List of usage examples for java.util Queue size
int size();
From source file:org.finra.datagenerator.engine.scxml.SCXMLFrontierTest.java
/** * Multiple variable assignments using set:{} *//*from w w w .ja v a2 s . c om*/ @Test public void testMultiVariableAssignment() { SCXMLEngine e = new SCXMLEngine(); InputStream is = SCXMLEngineTest.class.getResourceAsStream("/bigtest.xml"); e.setModelByInputFileStream(is); List<CustomTagExtension> tagExtensionList = customTagExtensionList(); try { List<PossibleState> bfs = e.bfs(343); PossibleState p = bfs.get(0); try { is = SCXMLEngineTest.class.getResourceAsStream("/bigtest.xml"); SCXML model = SCXMLParser.parse(new InputSource(is), null, customActionsFromTagExtensions(tagExtensionList)); SCXMLFrontier frontier = new SCXMLFrontier(p, model, tagExtensionList); Queue<Map<String, String>> queue = new LinkedList<>(); AtomicBoolean flag = new AtomicBoolean(false); frontier.searchForScenarios(new QueueResultsProcessing(queue), flag); Assert.assertEquals(queue.size(), 6); } catch (IOException | SAXException ex) { Assert.fail(); } } catch (ModelException ex) { Assert.fail(); } }
From source file:org.auraframework.test.PooledRemoteWebDriverFactory.java
@Override public synchronized WebDriver get(final DesiredCapabilities capabilities) { // default to use a pooled instance unless the test explicitly requests a brand new instance Object reuseBrowser = capabilities.getCapability(WebDriverProvider.REUSE_BROWSER_PROPERTY); if ((reuseBrowser != null) && (reuseBrowser.equals(false))) { return super.get(capabilities); }//from w ww. j a va 2 s . c o m Queue<PooledRemoteWebDriver> pool = pools.get(capabilities); if (pool == null) { pool = new LinkedList<PooledRemoteWebDriver>(); pools.put(capabilities, pool); } if (pool.size() > 0) { return pool.poll(); } else { final Queue<PooledRemoteWebDriver> thisPool = pool; return retry(new Callable<WebDriver>() { @Override public WebDriver call() throws Exception { return new PooledRemoteWebDriver(thisPool, serverUrl, capabilities); } }, MAX_GET_RETRIES, "Failed to get a new PooledRemoteWebDriver"); } }
From source file:au.org.ala.delta.intkey.ui.UIUtils.java
/** * Adds the supplied filename to the top of the most recently used files. * //ww w. ja v a 2s . c om * @param filename */ public static void addFileToMRU(String filename, String title, List<Pair<String, String>> existingFiles) { // Strip any RTF formatting, and characters used as separators in the MRU text from the title. title = RTFUtils.stripFormatting(title); title = title.replace(MRU_ITEM_SEPARATOR, " "); title = title.replace(MRU_FILES_SEPARATOR, " "); Queue<String> q = new LinkedList<String>(); String newFilePathAndTitle; if (StringUtils.isEmpty(title)) { newFilePathAndTitle = filename + MRU_ITEM_SEPARATOR + filename; } else { newFilePathAndTitle = filename + MRU_ITEM_SEPARATOR + title; } q.add(newFilePathAndTitle); if (existingFiles != null) { for (Pair<String, String> existingFile : existingFiles) { String existingFilePathAndTitle = existingFile.getFirst() + MRU_ITEM_SEPARATOR + existingFile.getSecond(); if (!q.contains(existingFilePathAndTitle)) { q.add(existingFilePathAndTitle); } } } StringBuilder b = new StringBuilder(); for (int i = 0; i < MAX_SIZE_MRU && q.size() > 0; ++i) { if (i > 0) { b.append(MRU_FILES_SEPARATOR); } b.append(q.poll()); } Preferences prefs = Preferences.userNodeForPackage(Intkey.class); prefs.put(MRU_FILES_PREF_KEY, b.toString()); try { prefs.sync(); } catch (BackingStoreException e) { throw new RuntimeException(e); } }
From source file:com.github.wolfdogs.kemono.util.event.RootEventManager.java
private void removeHandler(HandlerEntry entry) { if (entry == null) return;// w w w .j a v a 2s.co m Class<? extends Event> type = entry.getType(); Object relatedObject = entry.getRelatedObject(); Map<Object, Queue<HandlerEntry>> objectEntriesMap = handlerEntryContainersMap.get(type); if (objectEntriesMap == null) return; Queue<HandlerEntry> entries = objectEntriesMap.get(relatedObject); if (entries == null) return; entries.remove(entry); if (entries.size() == 0) objectEntriesMap.remove(relatedObject); if (objectEntriesMap.size() == 0) handlerEntryContainersMap.remove(type); }
From source file:org.siddhiesb.transport.passthru.DeliveryAgent.java
/** * Notification for a connection availability. When this occurs a message in the * queue for delivery will be tried.// ww w. j av a 2 s . c om * */ public void connected(HttpRoute route) { Queue<CommonContext> queue = null; lock.lock(); try { queue = waitingMessages.get(route); } finally { lock.unlock(); } while (queue.size() > 0) { NHttpClientConnection conn = targetConnections.getConnection(route); if (conn != null) { CommonContext messageContext = queue.poll(); if (messageContext != null) { tryNextMessage(messageContext, route, conn); } } else { break; } } }
From source file:org.apache.camel.component.mail.MailConsumer.java
public int processBatch(Queue<Object> exchanges) throws Exception { int total = exchanges.size(); // limit if needed if (maxMessagesPerPoll > 0 && total > maxMessagesPerPoll) { if (LOG.isDebugEnabled()) { LOG.debug("Limiting to maximum messages to poll " + maxMessagesPerPoll + " as there was " + total + " messages in this poll."); }/* w ww .j a va 2s . c om*/ total = maxMessagesPerPoll; } for (int index = 0; index < total && isBatchAllowed(); index++) { // only loop if we are started (allowed to run) Exchange exchange = ObjectHelper.cast(Exchange.class, exchanges.poll()); // add current index and total as properties exchange.setProperty(Exchange.BATCH_INDEX, index); exchange.setProperty(Exchange.BATCH_SIZE, total); exchange.setProperty(Exchange.BATCH_COMPLETE, index == total - 1); // update pending number of exchanges pendingExchanges = total - index - 1; // must use the original message in case we need to workaround a charset issue when extracting mail content final Message mail = exchange.getIn(MailMessage.class).getOriginalMessage(); // add on completion to handle after work when the exchange is done exchange.addOnCompletion(new Synchronization() { public void onComplete(Exchange exchange) { processCommit(mail, exchange); } public void onFailure(Exchange exchange) { processRollback(mail, exchange); } @Override public String toString() { return "MailConsumerOnCompletion"; } }); // process the exchange processExchange(exchange); } return total; }
From source file:org.apache.camel.component.jpa.JpaConsumer.java
public int processBatch(Queue<Object> exchanges) throws Exception { int total = exchanges.size(); // limit if needed if (maxMessagesPerPoll > 0 && total > maxMessagesPerPoll) { LOG.debug("Limiting to maximum messages to poll " + maxMessagesPerPoll + " as there was " + total + " messages in this poll."); total = maxMessagesPerPoll;/*ww w . j a v a 2 s . c o m*/ } for (int index = 0; index < total && isBatchAllowed(); index++) { // only loop if we are started (allowed to run) DataHolder holder = ObjectHelper.cast(DataHolder.class, exchanges.poll()); EntityManager entityManager = holder.manager; Exchange exchange = holder.exchange; Object result = holder.result; // add current index and total as properties exchange.setProperty(Exchange.BATCH_INDEX, index); exchange.setProperty(Exchange.BATCH_SIZE, total); exchange.setProperty(Exchange.BATCH_COMPLETE, index == total - 1); // update pending number of exchanges pendingExchanges = total - index - 1; if (lockEntity(result, entityManager)) { // process the current exchange if (LOG.isDebugEnabled()) { LOG.debug("Processing exchange: " + exchange); } try { getProcessor().process(exchange); } catch (Exception e) { throw new PersistenceException(e); } getDeleteHandler().deleteObject(entityManager, result); } } return total; }
From source file:org.apache.hadoop.hbase.master.balancer.TestStochasticLoadBalancer.java
@Test public void testKeepRegionLoad() throws Exception { ServerName sn = ServerName.valueOf("test:8080", 100); int numClusterStatusToAdd = 20000; for (int i = 0; i < numClusterStatusToAdd; i++) { ServerLoad sl = mock(ServerLoad.class); RegionLoad rl = mock(RegionLoad.class); when(rl.getStores()).thenReturn(i); Map<byte[], RegionLoad> regionLoadMap = new TreeMap<byte[], RegionLoad>(Bytes.BYTES_COMPARATOR); regionLoadMap.put(Bytes.toBytes(REGION_KEY), rl); when(sl.getRegionsLoad()).thenReturn(regionLoadMap); ClusterStatus clusterStatus = mock(ClusterStatus.class); when(clusterStatus.getServers()).thenReturn(Arrays.asList(sn)); when(clusterStatus.getLoad(sn)).thenReturn(sl); loadBalancer.setClusterStatus(clusterStatus); }/*w w w.j a v a2 s . c o m*/ assertTrue(loadBalancer.loads.get(REGION_KEY) != null); assertTrue(loadBalancer.loads.get(REGION_KEY).size() == 15); Queue<RegionLoad> loads = loadBalancer.loads.get(REGION_KEY); int i = 0; while (loads.size() > 0) { RegionLoad rl = loads.remove(); assertEquals(i + (numClusterStatusToAdd - 15), rl.getStores()); i++; } }
From source file:it.geosolutions.geobatch.migrationmonitor.monitor.MonitorAction.java
@Override public Queue<FileSystemEvent> execute(Queue<FileSystemEvent> events) throws ActionException { // return object final Queue<FileSystemEvent> outputEvents = new LinkedList<FileSystemEvent>(); try {/*from w w w. j av a 2 s . c om*/ // looking for file if (events.size() == 0) throw new IllegalArgumentException( "MonitorAction::execute(): Wrong number of elements for this action: " + events.size()); listenerForwarder.setTask("config"); listenerForwarder.started(); if (configuration == null) { final String message = "MonitorAction::execute(): DataFlowConfig is null."; if (LOGGER.isErrorEnabled()) LOGGER.error(message); throw new IllegalStateException(message); } // retrieve all the ELEMENTS table from the DB List<MigrationMonitor> migrationList = migrationMonitorDAO.findTablesToMigrate(); DS2DSTokenResolver tknRes = null; // init some usefull counters int failsCounter = 0; int iterCounter = 0; int totElem = migrationList.size(); // Process all MigrationMonitors retrieved for (MigrationMonitor mm : migrationList) { iterCounter++; try { tknRes = new DS2DSTokenResolver(mm, getConfigDir()); } catch (IOException e) { failsCounter++; LOGGER.error(e.getMessage(), e); LOGGER.error("error while processing MigrationMonitor " + mm.toString() + " let's skip it! (the error happens while resolving tokens...)"); LOGGER.error("fail number: " + failsCounter + " MigrationMonitor processed " + iterCounter + "/" + totElem); continue; } String filename = getTempDir() + File.separator + mm.getTableName() + mm.getLayerId() + ".xml"; Writer writer = null; try { writer = new FileWriter(filename); writer.append(tknRes.getOutputFileContent()); } catch (IOException e) { LOGGER.error("error while processing MigrationMonitor " + mm.toString() + " let's skip it! (the error happens while writing on the output file)"); LOGGER.error("fail number: " + failsCounter + " MigrationMonitor processed " + iterCounter + "/" + totElem); continue; } finally { try { writer.close(); FileSystemEvent fse = new FileSystemEvent(new File(filename), FileSystemEventType.FILE_ADDED); outputEvents.add(fse); } catch (IOException e) { LOGGER.error(e.getMessage(), e); } } mm.setMigrationStatus(MigrationStatus.INPROGRESS.toString().toUpperCase()); migrationMonitorDAO.merge(mm); } } catch (Exception t) { final String message = "MonitorAction::execute(): " + t.getLocalizedMessage(); if (LOGGER.isErrorEnabled()) LOGGER.error(message, t); final ActionException exc = new ActionException(this, message, t); listenerForwarder.failed(exc); throw exc; } return outputEvents; }
From source file:org.apache.synapse.transport.passthru.DeliveryAgent.java
/** * Notification for a connection availability. When this occurs a message in the * queue for delivery will be tried./*from w w w .j a va 2s.c om*/ * * @param host name of the remote host * @param port remote port number */ public void connected(HttpRoute route, NHttpClientConnection conn) { Queue<MessageContext> queue = null; lock.lock(); try { queue = waitingMessages.get(route); } finally { lock.unlock(); } while (queue.size() > 0) { if (conn == null) { conn = targetConnections.getExistingConnection(route); } if (conn != null) { MessageContext messageContext = queue.poll(); if (messageContext != null) { tryNextMessage(messageContext, route, conn); } conn = null; } else { break; } } }