List of usage examples for java.util.concurrent ConcurrentLinkedQueue add
public boolean add(E e)
From source file:org.alfresco.solr.tracker.AclTrackerTest.java
@Test public void checkTrackingWhenAclsToPurge() throws IllegalAccessException, IOException { @SuppressWarnings("unchecked") ConcurrentLinkedQueue<Long> aclsToPurge = (ConcurrentLinkedQueue<Long>) FieldUtils.readField(tracker, "aclsToPurge", true); aclsToPurge.add(201L); aclsToPurge.add(202L);/*from ww w. j a v a 2 s .c om*/ aclsToPurge.add(203L); // Invoke the behaviour we're testing testTrackChangesRan(); // aclsToPurge verify(informationServer).deleteByAclId(201L); verify(informationServer).deleteByAclId(202L); verify(informationServer).deleteByAclId(203L); // TODO: verify checkShutdown verify(informationServer).commit(); }
From source file:org.alfresco.solr.tracker.AclTrackerTest.java
@Test public void checkTrackingWhenAclChangeSetsToPurge() throws IllegalAccessException, IOException { @SuppressWarnings("unchecked") ConcurrentLinkedQueue<Long> aclChangeSetsToPurge = (ConcurrentLinkedQueue<Long>) FieldUtils .readField(tracker, "aclChangeSetsToPurge", true); aclChangeSetsToPurge.add(101L); aclChangeSetsToPurge.add(102L);/*from w w w. j av a 2 s.c o m*/ aclChangeSetsToPurge.add(103L); // Invoke the behaviour we're testing testTrackChangesRan(); // aclChangeSetsToPurge verify(informationServer).deleteByAclChangeSetId(101L); verify(informationServer).deleteByAclChangeSetId(102L); verify(informationServer).deleteByAclChangeSetId(103L); // TODO: verify checkShutdown verify(informationServer).commit(); }
From source file:nz.co.fortytwo.signalk.server.SubscriptionManager.java
public ConcurrentLinkedQueue<Subscription> getSubscriptions(String wsSession) { ConcurrentLinkedQueue<Subscription> subs = new ConcurrentLinkedQueue<Subscription>(); for (Subscription s : subscriptions) { if (s.getWsSession().equals(wsSession)) { subs.add(s); }// w w w.j av a 2 s.co m } return subs; }
From source file:org.apache.storm.daemon.DrpcServer.java
@Override public String execute(String functionName, String funcArgs) throws DRPCExecutionException, AuthorizationException, org.apache.thrift.TException { meterExecuteCalls.mark();//from w w w. ja v a2 s . c om LOG.debug("Received DRPC request for {} ({}) at {} ", functionName, funcArgs, System.currentTimeMillis()); Map<String, String> map = new HashMap<>(); map.put(DRPCAuthorizerBase.FUNCTION_NAME, functionName); checkAuthorization(authorizer, map, "execute"); int newid = 0; int orig = 0; do { orig = ctr.get(); newid = (orig + 1) % 1000000000; } while (!ctr.compareAndSet(orig, newid)); String strid = String.valueOf(newid); DRPCRequest req = new DRPCRequest(funcArgs, strid); InternalRequest internalRequest = new InternalRequest(functionName, req); this.outstandingRequests.put(strid, internalRequest); ConcurrentLinkedQueue<DRPCRequest> queue = acquireQueue(functionName); queue.add(req); LOG.debug("Waiting for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis()); try { internalRequest.sem.acquire(); } catch (InterruptedException e) { LOG.error("acquire fail ", e); } LOG.debug("Acquired for DRPC request for {} {} at {}", functionName, funcArgs, System.currentTimeMillis()); Object result = internalRequest.result; LOG.debug("Returning for DRPC request for " + functionName + " " + funcArgs + " at " + (System.currentTimeMillis())); this.cleanup(strid); if (result instanceof DRPCExecutionException) { throw (DRPCExecutionException) result; } if (result == null) { throw new DRPCExecutionException("Request timed out"); } return (String) result; }
From source file:org.onehippo.cms7.brokenlinks.LinkChecker.java
private void runCheckerThreads(final Iterable<Link> links) { ConcurrentLinkedQueue<Link> queue = new ConcurrentLinkedQueue<Link>(); for (Link link : links) { queue.add(link); }// w w w . j ava 2s .co m final int threadCount = Math.min(queue.size(), nrOfThreads); final AtomicInteger internalLinksChecked = new AtomicInteger(); Thread[] threads = new Thread[threadCount]; for (int i = 0; i < threadCount; i++) { threads[i] = new LinkCheckerRunner(queue, internalLinksChecked); threads[i].setUncaughtExceptionHandler(new LogUncaughtExceptionHandler(log)); } for (int i = 0; i < threadCount; i++) { threads[i].start(); } try { for (int i = 0; i < threadCount; i++) { threads[i].join(); } } catch (InterruptedException ex) { // aborted } try { session.refresh(false); } catch (RepositoryException e) { log.warn("Failed to clear the session.", e); } }
From source file:com.mobilehelix.appserver.push.PushManager.java
public void storeSession(String uniqueID, String combinedUser, PushReceiver newReceiver) { idMap.put(uniqueID, newReceiver);// www . java2s . c o m ConcurrentLinkedQueue<PushReceiver> receivers = this.userPushMap.get(combinedUser); if (receivers == null) { receivers = new ConcurrentLinkedQueue<>(); this.userPushMap.put(combinedUser, receivers); } receivers.add(newReceiver); }
From source file:org.sonar.server.db.migrations.violation.Referentials.java
private Queue<long[]> initGroupOfViolationIds(Database database) throws SQLException { Connection connection = database.getDataSource().getConnection(); Statement stmt = null;/*from w ww. j ava2 s.c o m*/ ResultSet rs = null; try { connection.setAutoCommit(false); stmt = connection.createStatement(); stmt.setFetchSize(10000); rs = stmt.executeQuery("select id from rule_failures"); ConcurrentLinkedQueue<long[]> queue = new ConcurrentLinkedQueue<long[]>(); totalViolations = 0; long[] block = new long[VIOLATION_GROUP_SIZE]; int cursor = 0; while (rs.next()) { block[cursor++] = rs.getLong(1); totalViolations++; if (cursor == VIOLATION_GROUP_SIZE) { queue.add(block); block = new long[VIOLATION_GROUP_SIZE]; cursor = 0; } } if (cursor > 0) { queue.add(block); } return queue; } finally { DbUtils.closeQuietly(connection, stmt, rs); } }
From source file:metlos.executors.batch.BatchExecutorTest.java
private void runSimpleDelayTest(int nofThreads) throws Exception { final ConcurrentLinkedQueue<Long> executionTimes = new ConcurrentLinkedQueue<Long>(); Runnable task = new Runnable() { @Override//from w w w . java 2 s . co m public void run() { executionTimes.add(System.currentTimeMillis()); } }; BatchExecutor ex = getExecutor(nofThreads); //start running my task... the task should "take" 0ms and there should be a delay //of 10ms between executions... the executionTimes collection should therefore //contain time stamps 10ms apart from each other. ex.submitWithPreferedDurationAndFixedDelay(Collections.singleton(task), 0, 0, 10, TimeUnit.MILLISECONDS); Thread.sleep(1000); ex.shutdown(); assert executionTimes.size() > 1 : "There should have been more than 1 task executed."; long minDelay = 8; //10ms +- 20% long maxDelay = 12; int nofElements = executionTimes.size(); long previousTime = executionTimes.poll(); long cummulativeDiff = 0; while (!executionTimes.isEmpty()) { long thisTime = executionTimes.poll(); long diff = thisTime - previousTime; cummulativeDiff += diff; previousTime = thisTime; } long averageDelay = cummulativeDiff / (nofElements - 1); assert minDelay < averageDelay && averageDelay < maxDelay : "The average delay should be in <" + minDelay + ", " + maxDelay + "> but was " + averageDelay + "."; }
From source file:org.atmosphere.cpr.PoolableBroadcasterFactoryTest.java
@Test public void concurrentLookupTest() throws InterruptedException { String id = "id"; final CountDownLatch latch = new CountDownLatch(100); final AtomicInteger created = new AtomicInteger(); factory.addBroadcasterListener(new BroadcasterListenerAdapter() { @Override/*ww w . j ava 2s .c o m*/ public void onPostCreate(Broadcaster b) { created.incrementAndGet(); } @Override public void onComplete(Broadcaster b) { } @Override public void onPreDestroy(Broadcaster b) { } }); final ConcurrentLinkedQueue<Broadcaster> c = new ConcurrentLinkedQueue<Broadcaster>(); ExecutorService r = Executors.newCachedThreadPool(); for (int i = 0; i < 100; i++) { r.submit(new Runnable() { @Override public void run() { c.add(factory.lookup("name" + UUID.randomUUID().toString(), true)); latch.countDown(); } }); } try { assertTrue(latch.await(20, TimeUnit.SECONDS)); assertEquals(created.get(), 100); assertEquals(c.size(), 100); for (Broadcaster b : c) { b.destroy(); } assertNotNull(factory.lookup("name" + UUID.randomUUID().toString(), true).broadcast("test")); assertEquals(factory.poolableProvider().poolSize(), 100); } finally { factory.destroy(); r.shutdownNow(); } }
From source file:org.atmosphere.cpr.PoolableBroadcasterFactoryTest.java
@Test public void concurrentAccessLookupTest() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1000); final AtomicInteger created = new AtomicInteger(); factory.poolableProvider(new UnboundedApachePoolableProvider()); factory.addBroadcasterListener(new BroadcasterListenerAdapter() { @Override/*ww w . j a v a2s . c o m*/ public void onPostCreate(Broadcaster b) { created.incrementAndGet(); } @Override public void onComplete(Broadcaster b) { } @Override public void onPreDestroy(Broadcaster b) { } }); final ConcurrentLinkedQueue<Broadcaster> c = new ConcurrentLinkedQueue<Broadcaster>(); ExecutorService r = Executors.newCachedThreadPool(); final String me = new String("me"); for (int i = 0; i < 1000; i++) { r.submit(new Runnable() { @Override public void run() { c.add(factory.get(me)); latch.countDown(); } }); } try { assertTrue(latch.await(20, TimeUnit.SECONDS)); assertEquals(latch.getCount(), 0); assertEquals(c.size(), 1000); assertEquals(created.get(), 1000); for (Broadcaster b : c) { b.destroy(); } assertNotNull(factory.lookup("name" + UUID.randomUUID().toString(), true).broadcast("test")); assertEquals(factory.poolableProvider().poolSize(), 1000); } finally { factory.destroy(); r.shutdownNow(); } }