List of usage examples for java.util Queue poll
E poll();
From source file:tasly.greathealth.thirdparty.order.OrderCommandsStorage.java
public synchronized OrderCommand getOrderCommand(final ChannelSource channelSource, final EventType eventType) { OrderCommand result = null;//www . ja va 2 s . c o m final Map<EventType, Queue<OrderCommand>> sourceCmds = commands.get(channelSource); if (sourceCmds == null) { return null; } final Queue<OrderCommand> cmds = sourceCmds.get(eventType); if (cmds != null) { result = cmds.poll(); final StoragePara para = new StoragePara(); para.eventType = eventType; para.channelSource = channelSource; } return result; }
From source file:org.languagetool.rules.AbstractCompoundRule.java
private void addToQueue(AnalyzedTokenReadings token, Queue<AnalyzedTokenReadings> prevTokens) { boolean inserted = prevTokens.offer(token); if (!inserted) { prevTokens.poll(); prevTokens.offer(token);//from www. j a va 2 s .c o m } }
From source file:ubic.gemma.core.job.progress.ProgressStatusServiceImpl.java
@Override public synchronized List<ProgressData> getProgressStatus(String taskId) { if (taskId == null) throw new IllegalArgumentException("task id cannot be null"); SubmittedTask<?> task = taskRunningService.getSubmittedTask(taskId); List<ProgressData> statusObjects = new Vector<>(); if (task == null) { ProgressStatusServiceImpl.log.warn( "It looks like job " + taskId + " has gone missing; assuming it is dead or finished already"); // We should assume it is dead. ProgressData data = new ProgressData(); data.setTaskId(taskId);// w w w .java2 s . co m data.setDone(true); data.setDescription("The job has gone missing; it has already finished or failed."); statusObjects.add(data); return statusObjects; } assert task.getTaskId() != null; assert task.getTaskId().equals(taskId); Queue<String> updates = task.getProgressUpdates(); StringBuilder progressMessage = new StringBuilder(); while (!updates.isEmpty()) { String update = updates.poll(); progressMessage.append(update).append("\n"); } if (task.isDone()) { ProgressData data; switch (task.getStatus()) { case COMPLETED: ProgressStatusServiceImpl.log.debug("Job " + taskId + " is done"); data = new ProgressData(taskId, 1, progressMessage + "Done!", true); break; case FAILED: data = new ProgressData(taskId, 1, progressMessage + "Failed!", true); data.setFailed(true); break; default: data = new ProgressData(taskId, 1, progressMessage + "Possibly canceled.", true); break; } statusObjects.add(data); } else { statusObjects.add(new ProgressData(taskId, 1, progressMessage.toString(), false)); } return statusObjects; }
From source file:org.jbpm.services.task.jaxb.ComparePair.java
public void recursiveCompare() { Queue<ComparePair> compares = new LinkedList<ComparePair>(); compares.add(this); while (!compares.isEmpty()) { compares.addAll(compares.poll().compare()); }/*from w w w .j av a 2 s. com*/ }
From source file:org.apache.synapse.transport.passthru.DeliveryAgent.java
public void errorConnecting(HttpRoute route, int errorCode, String message) { Queue<MessageContext> queue = waitingMessages.get(route); if (queue != null) { MessageContext msgCtx = queue.poll(); if (msgCtx != null) { targetErrorHandler.handleError(msgCtx, errorCode, "Error connecting to the back end", null, ProtocolState.REQUEST_READY); synchronized (msgCtx) { msgCtx.setProperty(PassThroughConstants.WAIT_BUILDER_IN_STREAM_COMPLETE, Boolean.TRUE); msgCtx.notifyAll();//from w w w. java2s.c o m } } } else { throw new IllegalStateException("Queue cannot be null for: " + route); } }
From source file:com.wolvereness.overmapped.lib.MultiProcessor.java
@Override public void shutdown() { if (shutdown) return;//from ww w . jav a 2 s .c om super.shutdown(); final Queue<Task<?>> queue = this.queue; while (true) { final Task<?> task = queue.poll(); if (task != null) { task.cancel(false); } else { break; } } for (final Thread thread : threads) { thread.interrupt(); } }
From source file:org.lunarray.model.descriptor.scanner.AnnotationScannerUtil.java
/** * Transitively tests for marker marks./* w w w.j av a 2s . c o m*/ * * @param marker * The marker. * @param processed * The processed annotations. * @param process * The annotations to process. * @return True if and only if the marker marks any of the processed * annotations. */ private boolean isMarkedTransiviteProcess(final Class<? extends Annotation> marker, final Set<Class<? extends Annotation>> processed, final Queue<Class<? extends Annotation>> process) { boolean marked = false; while (!process.isEmpty()) { final Class<? extends Annotation> poll = process.poll(); processed.add(poll); if (poll.equals(marker)) { marked = true; process.clear(); } else { for (final Annotation annotation : poll.getAnnotations()) { final Class<? extends Annotation> annotationType = annotation.annotationType(); if (!processed.contains(annotationType)) { process.add(annotationType); } } } } return marked; }
From source file:com.liferay.server.manager.internal.executor.PluginExecutor.java
@Override public void executeDelete(HttpServletRequest request, JSONObject responseJSONObject, Queue<String> arguments) throws Exception { String context = arguments.poll(); DeployManagerUtil.undeploy(context); }
From source file:org.auraframework.test.util.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); }/* w w w .ja v a 2 s .co m*/ Queue<PooledRemoteWebDriver> pool = pools.get(capabilities); if (pool == null) { pool = new LinkedList<>(); 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, getGetDriverTimeout(capabilities), "Failed to get a new PooledRemoteWebDriver"); } }
From source file:edu.toronto.cs.phenotips.solr.HPOScriptService.java
/** * Get the HPO IDs of the specified phenotype and all its ancestors. * /*from www .ja va 2 s. co m*/ * @param id the HPO identifier to search for, in the {@code HP:1234567} format * @return the full set of ancestors-or-self IDs, or an empty set if the requested ID was not found in the index */ public Set<String> getAllAncestorsAndSelfIDs(final String id) { Set<String> results = new HashSet<String>(); Queue<SolrDocument> nodes = new LinkedList<SolrDocument>(); SolrDocument crt = this.get(id); if (crt == null) { return results; } nodes.add(crt); while (!nodes.isEmpty()) { crt = nodes.poll(); results.add(String.valueOf(crt.get(ID_FIELD_NAME))); @SuppressWarnings("unchecked") List<String> parents = (List<String>) crt.get("is_a"); if (parents == null) { continue; } for (String pid : parents) { nodes.add(this.get(StringUtils.substringBefore(pid, " "))); } } return results; }