下面列出了java.util.concurrent.CopyOnWriteArrayList#get ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void finishAndNotifyListener(ActionListener listener, CopyOnWriteArrayList<ShardResponse> shardsResponses) {
logger.trace("{}: got all shard responses", actionName);
int successfulShards = 0;
int failedShards = 0;
int totalNumCopies = 0;
List<ShardOperationFailedException> shardFailures = null;
for (int i = 0; i < shardsResponses.size(); i++) {
ActionWriteResponse shardResponse = shardsResponses.get(i);
if (shardResponse == null) {
// non active shard, ignore
} else {
failedShards += shardResponse.getShardInfo().getFailed();
successfulShards += shardResponse.getShardInfo().getSuccessful();
totalNumCopies += shardResponse.getShardInfo().getTotal();
if (shardFailures == null) {
shardFailures = new ArrayList<>();
}
for (ActionWriteResponse.ShardInfo.Failure failure : shardResponse.getShardInfo().getFailures()) {
shardFailures.add(new DefaultShardOperationFailedException(new BroadcastShardOperationFailedException(new ShardId(failure.index(), failure.shardId()), failure.getCause())));
}
}
}
listener.onResponse(newResponse(successfulShards, failedShards, totalNumCopies, shardFailures));
}
private void finishAndNotifyListener(ActionListener listener, CopyOnWriteArrayList<ShardResponse> shardsResponses) {
logger.trace("{}: got all shard responses", actionName);
int successfulShards = 0;
int failedShards = 0;
int totalNumCopies = 0;
List<DefaultShardOperationFailedException> shardFailures = null;
for (int i = 0; i < shardsResponses.size(); i++) {
ReplicationResponse shardResponse = shardsResponses.get(i);
if (shardResponse == null) {
// non active shard, ignore
} else {
failedShards += shardResponse.getShardInfo().getFailed();
successfulShards += shardResponse.getShardInfo().getSuccessful();
totalNumCopies += shardResponse.getShardInfo().getTotal();
if (shardFailures == null) {
shardFailures = new ArrayList<>();
}
for (ReplicationResponse.ShardInfo.Failure failure : shardResponse.getShardInfo().getFailures()) {
shardFailures.add(new DefaultShardOperationFailedException(new BroadcastShardOperationFailedException(failure.fullShardId(), failure.getCause())));
}
}
}
listener.onResponse(newResponse(successfulShards, failedShards, totalNumCopies, shardFailures));
}
public void replay() {
if (wip.getAndIncrement() != 0) {
return;
}
int missed = 1;
CopyOnWriteArrayList<Node<T>> history = cache.history;
for (;;) {
if (cache.done && !hasNext()) {
if (cache.failure != null) {
downstream.onError(cache.failure);
} else {
downstream.onCompletion();
}
return;
}
long consumerRequested = requested.get();
if (consumerRequested == Long.MIN_VALUE) { // cancelled.
return;
}
if (consumerRequested > 0L && hasNext()) {
lastIndex = lastIndex + 1;
Node<T> node = history.get(lastIndex);
downstream.onItem(node.item);
Subscriptions.subtract(requested, 1);
continue;
}
missed = wip.addAndGet(-missed);
if (missed == 0) {
break;
}
}
}
/**
* Removes the specified driver from the {@code DriverManager}'s list of
* registered drivers.
* <p>
* If a {@code null} value is specified for the driver to be removed, then no
* action is taken.
* <p>
* If a security manager exists and its {@code checkPermission} denies
* permission, then a {@code SecurityException} will be thrown.
* <p>
* If the specified driver is not found in the list of registered drivers,
* then no action is taken. If the driver was found, it will be removed
* from the list of registered drivers.
* <p>
* If a {@code DriverAction} instance was specified when the JDBC driver was
* registered, its deregister method will be called
* prior to the driver being removed from the list of registered drivers.
*
* @param driver the JDBC Driver to remove
* @exception SQLException if a database access error occurs
* @throws SecurityException if a security manager exists and its
* {@code checkPermission} method denies permission to deregister a driver.
*
* @see SecurityManager#checkPermission
*/
@CallerSensitive
public static synchronized void deregisterDriver(Driver driver)
throws SQLException {
if (driver == null) {
return;
}
SecurityManager sec = System.getSecurityManager();
if (sec != null) {
sec.checkPermission(DEREGISTER_DRIVER_PERMISSION);
}
println("DriverManager.deregisterDriver: " + driver);
DriverInfo aDriver = new DriverInfo(driver, null);
CopyOnWriteArrayList<DriverInfo> drivers = getRegisteredDrivers();
if (drivers.contains(aDriver)) {
if (isDriverAllowed(driver, Reflection.getCallerClass())) {
DriverInfo di = drivers.get(drivers.indexOf(aDriver));
// If a DriverAction was specified, Call it to notify the
// driver that it has been deregistered
if(di.action() != null) {
di.action().deregister();
}
drivers.remove(aDriver);
} else {
// If the caller does not have permission to load the driver then
// throw a SecurityException.
throw new SecurityException();
}
} else {
println(" couldn't find driver to unload");
}
}
@Override
public RPCChannelGroup.ChannelInfo selectChannel(CopyOnWriteArrayList<RPCChannelGroup> allConnections) {
long totalHostCount = allConnections.size();
if (totalHostCount == 0) {
return null;
}
int index = (int) (getRandomLong() % totalHostCount);
RPCChannelGroup channelGroup = allConnections.get(index);
int subIndex = (int) (getRandomLong() % channelGroup.getConnectionNum());
Channel channel = channelGroup.getChannel(subIndex);
return new RPCChannelGroup.ChannelInfo(channelGroup, channel);
}
public SerializerPojo(CopyOnWriteArrayList<ClassInfo> registered){
if(registered == null)
registered = new CopyOnWriteArrayList<ClassInfo>();
this.registered = registered;
oldSize = registered.size();
for(int i=0;i<registered.size();i++)
{
ClassInfo ci = registered.get(i);
Class clazz = classForName(ci.name);
class2classId.put(clazz, i);
classId2class.put(i, clazz);
}
}
/**
* Gets the randomed test set.
*
* @param adequateTestSet
* the adequate test set
* @param numOfRandom
* the num of random
* @return the randomed test set
*/
private static ArrayList<ArrayList<String>> getRandomedTestSet(CopyOnWriteArrayList<ArrayList<String>> adequateTestSet,
int numOfRandom) {
ArrayList<ArrayList<String>> result = new ArrayList<>();
for (int i = 0; i < numOfRandom; i++) // random N times
{
SecureRandom random = new SecureRandom();
ArrayList<String> randomTest = adequateTestSet.get(random.nextInt(adequateTestSet.size()));
result.add(randomTest);
}
return result;
}
private void subscribe(Object subscriber, SubscriberMethod subscriberMethod) {
final String event = subscriberMethod.event;
CopyOnWriteArrayList<Subscription> subscriptions = subscriptionsByEvent.get(event);
final Subscription newSubscription = new Subscription(subscriber, subscriberMethod, subscriberMethod.priority);
if (subscriptions == null) {
subscriptions = new CopyOnWriteArrayList<>();
subscriptionsByEvent.put(event, subscriptions);
} else {
for (final Subscription subscription : subscriptions) {
if (subscription.equals(newSubscription)) {
throw new IllegalArgumentException("Subscriber " + subscriber.getClass() + " already registered to event " + event);
}
}
}
final int size = subscriptions.size();
for (int i = 0; i <= size; i++) {
if (i == size || newSubscription.priority > subscriptions.get(i).priority) {
subscriptions.add(i, newSubscription);
break;
}
}
List<String> subscribedevents = eventBySubscriber.get(subscriber);
if (subscribedevents == null) {
subscribedevents = new ArrayList<>();
eventBySubscriber.put(subscriber, subscribedevents);
}
subscribedevents.add(event);
}
public TransportConnection getDuplexBridgeConnectionFromRemote() {
TransportConnector transportConnector = remoteBroker.getTransportConnectorByScheme("tcp");
CopyOnWriteArrayList<TransportConnection> transportConnections = transportConnector.getConnections();
TransportConnection duplexBridgeConnectionFromRemote = transportConnections.get(0);
return duplexBridgeConnectionFromRemote;
}