List of usage examples for java.util Queue add
boolean add(E e);
From source file:org.openscore.lang.ExecutionRuntimeServices.java
/** * add event - for score to fire//w w w .j a va2 s.c o m * @param eventType - string which is the key you can listen to * @param eventData - the event data */ public void addEvent(String eventType, Serializable eventData) { @SuppressWarnings("unchecked") Queue<ScoreEvent> eventsQueue = getFromMap(SCORE_EVENTS_QUEUE); if (eventsQueue == null) { eventsQueue = new ArrayDeque<>(); contextMap.put(SCORE_EVENTS_QUEUE, (ArrayDeque) eventsQueue); } eventsQueue.add(new ScoreEvent(eventType, eventData)); }
From source file:com.nearinfinity.hbase.dsl.HBase.java
protected void savePut(byte[] tableName, Put put) { Queue<Put> puts = getPuts(tableName); if (puts.size() >= MAX_QUEUE_SIZE) { flushPuts(tableName, puts);/*from w w w . j av a 2 s . c o m*/ } puts.add(put); }
From source file:pt.webdetails.cda.cache.scheduler.CacheActivator.java
public void processQueries(Session s, Queue<CachedQuery> queue) { logger.debug("Refreshing cached query"); CachedQuery q = queue.poll();//from w ww. ja va2s .c o m try { IPentahoSession session = PentahoSessionHolder.getSession(); s.refresh(q); setSession(q); q.execute(); PentahoSessionHolder.setSession(session); } catch (Exception ex) { logger.error("Failed to execute " + q.toString(), ex); } q.updateNext(); queue.add(q); s.update(q); }
From source file:com.norconex.committer.core.AbstractFileQueueCommitter.java
@Override public void commit() { // Get all files to be committed, relying on natural ordering which // will be in file creation order. final Queue<File> filesPending = new ConcurrentLinkedQueue<File>(); FileUtil.visitAllFiles(new File(queue.getDirectory()), new IFileVisitor() { @Override/*from w ww . ja v a2s. com*/ public void visit(File file) { filesPending.add(file); } }, REF_FILTER); // Nothing left to commit. This happens if multiple threads are // committing at the same time and no more files are available for the // current thread to commit. This should happen rarely in practice. if (filesPending.isEmpty()) { return; } // Don't commit more than queue size List<ICommitOperation> filesToCommit = new ArrayList<>(); while (filesToCommit.size() < queueSize) { File file = filesPending.poll(); // If no more files available in both list, quit loop. This happens // if multiple threads tries to commit at once and there is less // than queueSize files to commit. This should happen rarely in // practice. if (file == null) { break; } // Current thread tries to own this file. If the file is already own // by another thread, continue and attempt to grab another file. if (filesCommitting.putIfAbsent(file, Thread.currentThread()) != null) { continue; } // A file might have already been committed and cleanup from // the map, but still returned by the directory listing. Ignore // those. It is important to make this check AFTER the current // thread got ownership of the file. if (!file.exists()) { continue; } // Current thread will be committing this file if (file.getAbsolutePath().contains(FileSystemCommitter.FILE_SUFFIX_ADD)) { filesToCommit.add(new FileAddOperation(file)); } else if (file.getAbsolutePath().contains(FileSystemCommitter.FILE_SUFFIX_REMOVE)) { filesToCommit.add(new FileDeleteOperation(file)); } else { LOG.error("Unsupported file to commit: " + file); } } if (LOG.isInfoEnabled()) { LOG.info(String.format("Committing %s files", filesToCommit.size())); } for (ICommitOperation op : filesToCommit) { try { if (op instanceof FileAddOperation) { prepareCommitAddition((IAddOperation) op); commitAddition((IAddOperation) op); } else { prepareCommitDeletion((IDeleteOperation) op); commitDeletion((IDeleteOperation) op); } } catch (IOException e) { throw new CommitterException("Cannot read reference from : " + op, e); } } commitComplete(); deleteEmptyOldDirs(new File(queue.getDirectory())); // Cleanup committed files from map that might have been deleted Enumeration<File> en = filesCommitting.keys(); while (en.hasMoreElements()) { File file = (File) en.nextElement(); if (!file.exists()) { filesCommitting.remove(file); } } }
From source file:com.nearinfinity.hbase.dsl.HBase.java
protected void saveDelete(byte[] tableName, Delete delete) { Queue<Delete> deletes = getDeletes(tableName); if (deletes.size() >= MAX_QUEUE_SIZE) { flushDeletes(tableName, deletes); }/*from w w w.j a v a 2s.c om*/ deletes.add(delete); }
From source file:eu.stratosphere.nephele.taskmanager.runtime.RuntimeInputChannelContext.java
@Override public void destroy() { final Queue<Buffer> buffersToRecycle = new ArrayDeque<Buffer>(); synchronized (this.queuedEnvelopes) { this.destroyCalled = true; while (!this.queuedEnvelopes.isEmpty()) { final TransferEnvelope envelope = this.queuedEnvelopes.poll(); if (envelope.getBuffer() != null) { buffersToRecycle.add(envelope.getBuffer()); }//from w w w . java 2 s .c o m } } while (!buffersToRecycle.isEmpty()) { buffersToRecycle.poll().recycleBuffer(); } }
From source file:io.cloudslang.score.lang.ExecutionRuntimeServices.java
/** * add event - for score to fire/* w w w . j a v a 2 s . c o m*/ * @param eventType - string which is the key you can listen to * @param eventData - the event data */ public void addEvent(String eventType, Serializable eventData) { @SuppressWarnings("unchecked") Queue<ScoreEvent> eventsQueue = getFromMap(SCORE_EVENTS_QUEUE); if (eventsQueue == null) { eventsQueue = new ArrayDeque<>(); contextMap.put(SCORE_EVENTS_QUEUE, (ArrayDeque) eventsQueue); } eventsQueue.add(new ScoreEvent(eventType, getLanguageName(), eventData, getMetaData())); }
From source file:org.wso2.carbon.dataservices.core.DBUtils.java
/** * This util method is used to retrieve the string tokens resides in a particular * udt parameter./* w w w.ja v a 2s . c o m*/ * * @param param Name of the parameter * @return */ public static Queue<String> getTokens(String param) { boolean isString = false; Queue<String> tokens = new LinkedBlockingQueue<String>(); char[] chars = param.toCharArray(); StringBuilder columnName = new StringBuilder(); for (int i = 0; i < chars.length; i++) { Character c = chars[i]; if (!".".equals(c.toString()) && !"[".equals(c.toString()) && !"]".equals(c.toString())) { isString = true; columnName.append(c.toString()); if (i == chars.length - 1) { tokens.add(columnName.toString()); } } else { if (isString) { tokens.add(columnName.toString()); columnName = new StringBuilder(); isString = false; } tokens.add(c.toString()); } } return tokens; }
From source file:org.jolokia.client.request.J4pReadIntegrationTest.java
@Test public void error404ConnectionTest() throws Exception { final J4pReadRequest req = new J4pReadRequest(itSetup.getAttributeMBean(), "LongSeconds"); try {//from w w w . j a va2s. c o m stop(); startWithoutAgent(); j4pClient.execute(req); fail(); } catch (J4pRemoteException exp) { assertEquals(404, exp.getStatus()); } stop(); start(); final CyclicBarrier barrier = new CyclicBarrier(10); final Queue errors = new ConcurrentLinkedQueue(); Runnable run = new Runnable() { public void run() { try { j4pClient.execute(req); } catch (Exception e) { errors.add(1); System.err.println(e); } try { barrier.await(); } catch (InterruptedException ex) { return; } catch (BrokenBarrierException ex) { return; } } }; for (int i = 0; i < 10; i++) { new Thread(run).start(); } if (barrier.await() == 0) { //System.err.println("Finished"); assertEquals(0, errors.size(), "Concurrent calls should work"); } }
From source file:bwem.map.MapImpl.java
public TilePosition breadthFirstSearch(TilePosition start, Pred findCond, Pred visitCond, boolean connect8) { if (findCond.isTrue(getData().getTile(start), start, this)) { return start; }//from w w w . jav a 2 s.c o m final Set<TilePosition> visited = new TreeSet<>((a, b) -> { int result = Integer.compare(a.getX(), b.getX()); if (result != 0) { return result; } return Integer.compare(a.getY(), b.getY()); }); Queue<TilePosition> toVisit = new ArrayDeque<>(); toVisit.add(start); visited.add(start); TilePosition[] dir8 = { new TilePosition(-1, -1), new TilePosition(0, -1), new TilePosition(1, -1), new TilePosition(-1, 0), new TilePosition(1, 0), new TilePosition(-1, 1), new TilePosition(0, 1), new TilePosition(1, 1) }; TilePosition[] dir4 = { new TilePosition(0, -1), new TilePosition(-1, 0), new TilePosition(+1, 0), new TilePosition(0, +1) }; TilePosition[] directions = connect8 ? dir8 : dir4; while (!toVisit.isEmpty()) { TilePosition current = toVisit.remove(); for (TilePosition delta : directions) { TilePosition next = current.add(delta); if (getData().getMapData().isValid(next)) { Tile nextTile = getData().getTile(next, CheckMode.NO_CHECK); if (findCond.isTrue(nextTile, next, this)) { return next; } if (visitCond.isTrue(nextTile, next, this) && !visited.contains(next)) { toVisit.add(next); visited.add(next); } } } } //TODO: Are we supposed to return start or not? // bwem_assert(false); throw new IllegalStateException(); // return start; }