List of usage examples for java.util.concurrent BlockingQueue drainTo
int drainTo(Collection<? super E> c);
From source file:com.ricston.connectors.dataanalysis.DataAnalysisConnector.java
/** * Take the data from the MapDb backed persisted queue and return it as a List of Maps. * The idea behind this method is that the statistics collector will poll this method * for data every couple of seconds./*from w w w .j a v a 2s. co m*/ * */ @Override public List<Map<String, Object>> getData() { logger.debug("Retrieving analysis data"); Map<String, Object> all = db.getAll(); List<Map<String, Object>> items = new ArrayList<Map<String, Object>>(); for (Iterator<Map.Entry<String, Object>> i = all.entrySet().iterator(); i.hasNext();) { @SuppressWarnings("unchecked") BlockingQueue<Map<String, Object>> q = (BlockingQueue<Map<String, Object>>) i.next().getValue(); q.drainTo(items); } logger.debug("Retrieving complete with total elements: " + items.size()); return items; }
From source file:com.opengamma.bbg.replay.BloombergTickWriter.java
/** * /*from w w w .j a v a 2 s . com*/ */ private void writeOutSecurityMapQueue() { for (Entry<String, BlockingQueue<FudgeMsg>> entry : _securityMapQueue.entrySet()) { String security = entry.getKey(); BlockingQueue<FudgeMsg> queue = entry.getValue(); if (queue.isEmpty()) { continue; } List<FudgeMsg> tickMsgList = new ArrayList<FudgeMsg>(queue.size()); queue.drainTo(tickMsgList); String buid = getBloombergBUID(security); //get first message FudgeMsg tickMsg = tickMsgList.get(0); Long epochMillis = tickMsg.getLong(RECEIVED_TS_KEY); File dir = buildSecurityDirectory(buid, epochMillis); if (!dir.exists()) { createDirectory(dir); } writeSecurityTicks(dir, buid, security, tickMsgList); tickMsgList.clear(); tickMsgList = null; } }
From source file:com.nridge.connector.fs.con_fs.task.TaskConnectorFS.java
private void emptyQueue(String aQueueName) { Logger appLogger = mAppMgr.getLogger(this, "emptyQueue"); appLogger.trace(mAppMgr.LOGMSG_TRACE_ENTER); BlockingQueue blockingQueue = (BlockingQueue) mAppMgr.getProperty(aQueueName); if (blockingQueue != null) { ArrayList<String> drainToList = new ArrayList<>(); blockingQueue.drainTo(drainToList); }/*from w ww . ja va 2s .c o m*/ appLogger.trace(mAppMgr.LOGMSG_TRACE_DEPART); }
From source file:org.apache.accumulo.core.client.impl.ConditionalWriterImpl.java
private TabletServerMutations<QCMutation> dequeue(String location) { BlockingQueue<TabletServerMutations<QCMutation>> queue = getServerQueue(location).queue; ArrayList<TabletServerMutations<QCMutation>> mutations = new ArrayList<TabletLocator.TabletServerMutations<QCMutation>>(); queue.drainTo(mutations); if (mutations.size() == 0) return null; if (mutations.size() == 1) { return mutations.get(0); } else {/* ww w. j a v a 2s . c o m*/ // merge multiple request to a single tablet server TabletServerMutations<QCMutation> tsm = mutations.get(0); for (int i = 1; i < mutations.size(); i++) { for (Entry<KeyExtent, List<QCMutation>> entry : mutations.get(i).getMutations().entrySet()) { List<QCMutation> list = tsm.getMutations().get(entry.getKey()); if (list == null) { list = new ArrayList<QCMutation>(); tsm.getMutations().put(entry.getKey(), list); } list.addAll(entry.getValue()); } } return tsm; } }
From source file:org.apache.accumulo.core.clientImpl.ConditionalWriterImpl.java
private TabletServerMutations<QCMutation> dequeue(String location) { BlockingQueue<TabletServerMutations<QCMutation>> queue = getServerQueue(location).queue; ArrayList<TabletServerMutations<QCMutation>> mutations = new ArrayList<>(); queue.drainTo(mutations); if (mutations.size() == 0) return null; if (mutations.size() == 1) { return mutations.get(0); } else {/*from w w w. j a va 2 s. c o m*/ // merge multiple request to a single tablet server TabletServerMutations<QCMutation> tsm = mutations.get(0); for (int i = 1; i < mutations.size(); i++) { for (Entry<KeyExtent, List<QCMutation>> entry : mutations.get(i).getMutations().entrySet()) { tsm.getMutations().computeIfAbsent(entry.getKey(), k -> new ArrayList<>()) .addAll(entry.getValue()); } } return tsm; } }
From source file:org.apache.camel.impl.DefaultServicePool.java
protected void doStop() throws Exception { if (log.isDebugEnabled()) { log.debug("Stopping service pool: " + this); }//from w ww . ja v a 2 s . c o m for (BlockingQueue<Service> entry : pool.values()) { Collection<Service> values = new ArrayList<Service>(); entry.drainTo(values); ServiceHelper.stopServices(values); entry.clear(); } pool.clear(); }
From source file:org.apache.cassandra.concurrent.ContinuationsExecutor.java
/** * Drains the task queue into a new list, normally using drainTo. But if the * queue is a DelayQueue or any other kind of queue for which poll or * drainTo may fail to remove some elements, it deletes them one by one. *//*from w ww . ja va 2s. c o m*/ private List<Runnable> drainQueue() { BlockingQueue<Runnable> q = workQueue; List<Runnable> taskList = new ArrayList<Runnable>(); q.drainTo(taskList); if (!q.isEmpty()) { for (Runnable r : q.toArray(new Runnable[0])) { if (q.remove(r)) taskList.add(r); } } return taskList; }
From source file:org.artifactory.webapp.servlet.ArtifactoryContextConfigListener.java
@Override public void contextInitialized(ServletContextEvent event) { final ServletContext servletContext = event.getServletContext(); setSessionTrackingMode(servletContext); final Thread initThread = new Thread("art-init") { boolean success = true; @SuppressWarnings({ "unchecked" }) @Override//from w w w . j a va2s. c om public void run() { try { //Use custom logger String contextId = HttpUtils.getContextId(servletContext); //Build a partial config, since we expect the logger-context to exit in the selector cache by only contextId LoggerConfigInfo configInfo = new LoggerConfigInfo(contextId); LogbackContextSelector.bindConfig(configInfo); //No log field since needs to lazy initialize only after logback customization listener has run Logger log = getLogger(); configure(servletContext, log); LogbackContextSelector.unbindConfig(); } catch (Exception e) { getLogger().error( "Application could not be initialized: " + ExceptionUtils.getRootCause(e).getMessage(), e); success = false; } finally { if (success) { //Run the waiting filters BlockingQueue<DelayedInit> waitingFiltersQueue = (BlockingQueue<DelayedInit>) servletContext .getAttribute(DelayedInit.APPLICATION_CONTEXT_LOCK_KEY); List<DelayedInit> waitingInits = new ArrayList<>(); waitingFiltersQueue.drainTo(waitingInits); for (DelayedInit filter : waitingInits) { try { filter.delayedInit(); } catch (ServletException e) { getLogger().error("Could not init {}.", filter.getClass().getName(), e); success = false; break; } } } //Remove the lock and open the app to requests servletContext.removeAttribute(DelayedInit.APPLICATION_CONTEXT_LOCK_KEY); } } }; initThread.setDaemon(true); servletContext.setAttribute(DelayedInit.APPLICATION_CONTEXT_LOCK_KEY, new LinkedBlockingQueue<DelayedInit>()); initThread.start(); if (Boolean.getBoolean("artifactory.init.useServletContext")) { try { getLogger().info("Waiting for servlet context initialization ..."); initThread.join(); } catch (InterruptedException e) { getLogger().error("Artifactory initialization thread got interrupted", e); } } }