Java Code Examples for java.util.concurrent.CopyOnWriteArrayList#get()
The following examples show how to use
java.util.concurrent.CopyOnWriteArrayList#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TransportBroadcastReplicationAction.java From Elasticsearch with Apache License 2.0 | 6 votes |
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)); }
Example 2
Source File: TransportBroadcastReplicationAction.java From crate with Apache License 2.0 | 6 votes |
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)); }
Example 3
Source File: MultiCacheOp.java From smallrye-mutiny with Apache License 2.0 | 5 votes |
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; } } }
Example 4
Source File: DriverManager.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * 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"); } }
Example 5
Source File: RandomStrategy.java From rpc-java with Apache License 2.0 | 5 votes |
@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); }
Example 6
Source File: SerializerPojo.java From FastBootWeixin with Apache License 2.0 | 5 votes |
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); } }
Example 7
Source File: doRandomGivenPercentMutants.java From muJava with Apache License 2.0 | 5 votes |
/** * 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; }
Example 8
Source File: ObserverManagerImpl.java From Cangol-appcore with Apache License 2.0 | 5 votes |
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); }
Example 9
Source File: DynamicallyIncludedDestinationsDuplexNetworkTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
public TransportConnection getDuplexBridgeConnectionFromRemote() { TransportConnector transportConnector = remoteBroker.getTransportConnectorByScheme("tcp"); CopyOnWriteArrayList<TransportConnection> transportConnections = transportConnector.getConnections(); TransportConnection duplexBridgeConnectionFromRemote = transportConnections.get(0); return duplexBridgeConnectionFromRemote; }