List of usage examples for java.util.concurrent ConcurrentLinkedQueue addAll
public boolean addAll(Collection<? extends E> c)
From source file:mcnutty.music.get.ProcessQueue.java
void save_queue() { try (PrintWriter file = new PrintWriter("queue.json")) { ConcurrentLinkedQueue<QueueItem> queue_dump = new ConcurrentLinkedQueue<>(); QueueItem last_item = new QueueItem(); for (QueueItem item : bucket_played) last_item = item;/*from w w w. j ava 2 s. c o m*/ queue_dump.add(last_item); queue_dump.addAll(bucket_queue); file.println(json_array_list(queue_dump).toString()); } catch (FileNotFoundException e) { e.printStackTrace(); } }
From source file:server.Folder.java
/** * Copy all versions of the objects found in a folder. This will create the complete object tree of * the objects, so if an object has ancestors or descendants in other folders, those will be copied, too. * @param folderContent the content of the folder which should be copied completely. * @param otc a ObjectTreeCopier which is configured with a validator and correct activeUser. * @param croakOnError if true, stop in case of an error and return a CopyResult which contains the events so far. * @return a copyResult containing a collection of all failed and successful attempts at copying the * folder's contents.//w ww . ja va 2s . c o m */ CopyResult copyAllVersions(Collection<ObjectSystemData> folderContent, ObjectTreeCopier otc, Boolean croakOnError) { ObjectSystemDataDAO oDao = daoFactory.getObjectSystemDataDAO(HibernateSession.getLocalEntityManager()); CopyResult copyResult = new CopyResult(); ConcurrentLinkedQueue<ObjectSystemData> conQueue = new ConcurrentLinkedQueue<ObjectSystemData>(); conQueue.addAll(folderContent); log.debug("starting to copy " + conQueue.size() + " objects"); for (ObjectSystemData source : conQueue) { // otc.resetCopyResult(); try { // create a full copy of the whole object tree: otc.createFullCopy(source); copyResult.addCopyResult(otc.getCopyResult()); } catch (Exception ex) { log.debug("objectTreeCopy failed for id " + source.getId(), ex); // copy failed - now we have to cleanup and remove the already created copies: ObjectSystemData brokenCopy = otc.getCopyCache().get(source); if (brokenCopy != null) { // we should nuke all other objects with the same root, // as they won't be amendable to a copy operation either. for (ObjectSystemData osd : conQueue) { if (osd.getRoot().equals(brokenCopy.getRoot())) { conQueue.remove(osd); } } // recursively delete the broken object tree. oDao.delete(brokenCopy.getRoot(), true, true); } log.debug("cleanup complete."); copyResult.addFailure(source, new CinnamonException(ex)); if (croakOnError) { return copyResult; } } } return copyResult; }
From source file:org.apache.jackrabbit.oak.plugins.blob.MarkSweepGarbageCollector.java
/** * Deletes a batch of blobs from blob store. * /* w w w.java 2 s . com*/ * @param ids * @param exceptionQueue * @param maxModified */ private long sweepInternal(List<String> ids, ConcurrentLinkedQueue<String> exceptionQueue, long maxModified) { long deleted = 0; try { LOG.trace("Blob ids to be deleted {}", ids); deleted = blobStore.countDeleteChunks(ids, maxModified); if (deleted != ids.size()) { // Only log and do not add to exception queue since some blobs may not match the // lastMaxModifiedTime criteria. LOG.debug("Some [{}] blobs were not deleted from the batch : [{}]", ids.size() - deleted, ids); } } catch (Exception e) { LOG.warn("Error occurred while deleting blob with ids [{}]", ids, e); exceptionQueue.addAll(ids); } return deleted; }
From source file:com.chinamobile.bcbsp.comm.MessageQueuesForDisk.java
/** * Load bucket from disk.//from w w w . j av a 2s. c o m * @param queuesBuckets * @param bucketIndex * @param queuePath * @throws IOException */ private void loadBucket(ArrayList<BucketMeta> queuesBuckets, int bucketIndex, String queuePath) throws IOException { LOG.info("[MessageQueuesForDisk] is loading the [" + queuePath + " Bucket-" + bucketIndex + "] <<< size = " + queuesBuckets.get(bucketIndex).count + "."); long start = System.currentTimeMillis(); /** Clock */ File messagesDataFileBucket; FileReader frMessagesData; BufferedReader brMessagesData; messagesDataFileBucket = new File(this.messagesDataFile + "/" + queuePath + "/" + "bucket-" + bucketIndex); if (!messagesDataFileBucket.exists()) { throw new IOException("Bucket file" + messagesDataFileBucket + " does not exit!"); } // Open file readers. frMessagesData = new FileReader(messagesDataFileBucket); brMessagesData = new BufferedReader(frMessagesData); // Read the file header. @SuppressWarnings("unused") String bucketHeader = brMessagesData.readLine(); ConcurrentHashMap<String, ConcurrentLinkedQueue<IMessage>> queueMap = queuesBuckets .get(bucketIndex).queueMap; if (queueMap == null) { queueMap = new ConcurrentHashMap<String, ConcurrentLinkedQueue<IMessage>>(); } String buffer; while ((buffer = brMessagesData.readLine()) != null) { String[] queueBuffer = buffer.split(Constants.KV_SPLIT_FLAG); if (queueBuffer[0] == "") { LOG.warn("[MessageQueuesForDisk] readLine = " + buffer); } String key = queueBuffer[0]; ConcurrentLinkedQueue<IMessage> queue = queueMap.get(key); if (queue == null) { queue = stringToQueue(queueBuffer[1]); this.sizeOfHashMapsInMem = this.sizeOfHashMapsInMem + (sizeOfRef + sizeOfInteger + sizeOfEmptyMessageQueue); } else { queue.addAll(stringToQueue(queueBuffer[1])); } queueMap.put(key, queue); } queuesBuckets.get(bucketIndex).queueMap = queueMap; brMessagesData.close(); frMessagesData.close(); // Update the meta data of the bucket. BucketMeta meta = queuesBuckets.get(bucketIndex); // Update the size of messages data in memory. this.sizeOfMessagesDataInMem = this.sizeOfMessagesDataInMem + (meta.length - meta.lengthInMemory); this.countOfMessagesDataInMem = this.countOfMessagesDataInMem + (meta.count - meta.countInMemory); meta.onDiskFlag = false; meta.lengthInMemory = meta.length; meta.countInMemory = meta.count; queuesBuckets.set(bucketIndex, meta); if (!messagesDataFileBucket.delete()) { throw new IOException("Bucket file delete failed!"); } this.readDiskTime = this.readDiskTime + (System.currentTimeMillis() - start); /** Clock */ }
From source file:m.c.m.proxyma.context.ProxyFolderBean.java
/** * Add the a plugin to the specified list using the execution priority * to define the position of the plugin into the list. * @param pluginName the plugin name to add to the list * @param list the list to update./*from ww w .ja v a 2 s . c om*/ */ private void addPluginUsingExecutionPriority(String pluginName, String baseXPath, ConcurrentLinkedQueue<String> list) { String pluginPriorityXPath = baseXPath + "[@class='" + pluginName + "']/@executionPriority"; int pluginPriority = 0; try { pluginPriority = Integer.parseInt(context.getSingleValueParameter(pluginPriorityXPath)); } catch (Exception x) { log.warning("executionPiority not an integer in \"" + pluginPriorityXPath + "\""); } //put the new object in the correct position based upon its execution priority LinkedList<String> tmpList = new LinkedList(list); String currentPlugin = null; int currentPluginPriority = 0; boolean inserted = false; for (int i = 0; (i < tmpList.size() && !inserted); i++) { currentPlugin = tmpList.get(i); pluginPriorityXPath = baseXPath + "[@class='" + currentPlugin + "']/@executionPriority"; try { currentPluginPriority = Integer.parseInt(context.getSingleValueParameter(pluginPriorityXPath)); } catch (Exception x) { currentPluginPriority = 0; } if (pluginPriority < currentPluginPriority) { tmpList.add(i, pluginName); inserted = true; } } //If a place for the plugin was not found the plugin is addedd on the tail if (!inserted) tmpList.add(pluginName); //Update the thread-safe queue list.removeAll(tmpList); list.addAll(tmpList); }
From source file:org.wso2.developerstudio.eclipse.greg.manager.remote.views.RegistryBrowserView.java
private String searchRegistryNodeForResource(RegistryNode node, String caption) throws InvalidRegistryURLException, UnknownRegistryException { ConcurrentLinkedQueue<RegistryResourceNode> queue = new ConcurrentLinkedQueue<RegistryResourceNode>(); queue.addAll(node.getRegistryContainer().getRegistryContent()); while (queue.peek() != null) { RegistryResourceNode registryResourceNode = queue.poll(); if (caption.equalsIgnoreCase(registryResourceNode.getCaption())) { return registryResourceNode.getRegistryResourcePath(); } else {/*from w ww. j a va2s .com*/ queue.addAll(registryResourceNode.getResourceNodeList()); } } // for (RegistryResourceNode registryResourceNode : queue) { // if(caption.equalsIgnoreCase(registryResourceNode.getCaption())){ // return registryResourceNode.getRegistryResourcePath(); // }else{ // queue.addAll(registryResourceNode.getResourceNodeList()); // } // } return null; }
From source file:org.wso2.developerstudio.eclipse.greg.manager.remote.views.RegistryBrowserView.java
private RegistryResourceNode searchRegistryNodeForResourceNode(RegistryNode node, String caption) throws InvalidRegistryURLException, UnknownRegistryException { ConcurrentLinkedQueue<RegistryResourceNode> queue = new ConcurrentLinkedQueue<RegistryResourceNode>(); queue.addAll(node.getRegistryContainer().getRegistryContent()); while (queue.peek() != null) { RegistryResourceNode registryResourceNode = queue.poll(); if (caption.equalsIgnoreCase(registryResourceNode.getCaption())) { return registryResourceNode; } else {//ww w . j a v a 2 s . c o m queue.addAll(registryResourceNode.getResourceNodeList()); } } // for (RegistryResourceNode registryResourceNode : queue) { // if(caption.equalsIgnoreCase(registryResourceNode.getCaption())){ // return registryResourceNode.getRegistryResourcePath(); // }else{ // queue.addAll(registryResourceNode.getResourceNodeList()); // } // } return null; }