List of usage examples for java.util Queue poll
E poll();
From source file:com.tasktop.c2c.server.configuration.service.TemplateProcessingConfigurator.java
@Override public void configure(ProjectServiceConfiguration configuration) { File hudsonHomeDir = new File(targetBaseLocation, (perOrg ? configuration.getOrganizationIdentifier() : configuration.getProjectIdentifier())); if (hudsonHomeDir.exists()) { LOG.warn("Hudson home already apears to exist: " + hudsonHomeDir.getAbsolutePath()); } else {/*from w ww.j av a2 s. co m*/ // If we're here, the destination directory doesn't exist. Create it now. LOG.info("Creating new Hudson home: " + hudsonHomeDir.getAbsolutePath()); hudsonHomeDir.mkdirs(); } Queue<File> fileQueue = new LinkedList<File>(); Map<String, String> props = new HashMap<String, String>(configuration.getProperties()); fileQueue.add(new File(templateBaseLocation)); while (!fileQueue.isEmpty()) { File currentFile = fileQueue.poll(); if (currentFile.isDirectory()) { fileQueue.addAll(Arrays.asList(currentFile.listFiles())); createOrEnsureTargetDirectory(currentFile, configuration); } else { try { applyTemplateFileToTarget(props, currentFile, configuration); } catch (IOException e) { throw new RuntimeException(e); } } } }
From source file:com.google.code.rapid.queue.FileQueueTest.java
private void poll(Queue queue, int count) { System.out.println("Test read " + count + " times from queue"); long start = System.currentTimeMillis(); for (int i = 0; i < count; i++) { byte[] b = (byte[]) queue.poll(); if (b == null) { i--;// ww w .j av a 2s .co m System.out.println("null" + i); break; } } printTps(System.currentTimeMillis() - start, count); }
From source file:org.apache.hadoop.hbase.replication.regionserver.TestRegionReplicaReplicationEndpointNoMaster.java
private void replicateUsingCallable(ClusterConnection connection, Queue<Entry> entries) throws IOException, RuntimeException { Entry entry;//from w w w . j a v a 2 s. c o m while ((entry = entries.poll()) != null) { byte[] row = entry.getEdit().getCells().get(0).getRow(); RegionLocations locations = connection.locateRegion(tableName, row, true, true); RegionReplicaReplayCallable callable = new RegionReplicaReplayCallable(connection, RpcControllerFactory.instantiate(connection.getConfiguration()), table.getName(), locations.getRegionLocation(1), locations.getRegionLocation(1).getRegionInfo(), row, Lists.newArrayList(entry), new AtomicLong()); RpcRetryingCallerFactory factory = RpcRetryingCallerFactory.instantiate(connection.getConfiguration()); factory.<ReplicateWALEntryResponse>newCaller().callWithRetries(callable, 10000); } }
From source file:org.apache.hadoop.mapred.LinuxUtilizationGauger.java
/** * A function computes the Memory and CPU usage of all subprocess * @param pid PID of the process we are interested in * @param pidToContent Map between pid and the PS content * @param pidToChildPid Map between pid and pid of its child process * @return A 2-element array which contants CPU and memory usage *//*from w w w.j a v a 2s . co m*/ private double[] getSubProcessUsage(String pid, Map<String, String[]> pidToContent, Map<String, LinkedList<String>> pidToChildPid) { double cpuMemUsage[] = new double[2]; Queue<String> pidQueue = new LinkedList<String>(); pidQueue.add(pid); while (!pidQueue.isEmpty()) { pid = pidQueue.poll(); for (String child : pidToChildPid.get(pid)) { pidQueue.add(child); } String[] psContent = pidToContent.get(pid); double cpuUsage = Double.parseDouble(psContent[PCPU]); cpuUsage = percentageToGHz(cpuUsage); double memUsage = Double.parseDouble(psContent[RSS]); // "ps -eo rss" gives memory in kB. We convert it in GB memUsage /= 1000000d; cpuMemUsage[0] += cpuUsage; cpuMemUsage[1] += memUsage; } return cpuMemUsage; }
From source file:com.ibm.amc.feedback.FeedbackHandler.java
public FeedbackHandler() { if (logger.isEntryEnabled()) logger.entry("FeedbackHandler"); mapper = new ObjectMapper(); mapper.getFactory().disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET); mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); ShutdownListener.addShutdownListener(this); ActionFactory.getActionLog().addActionListener(this); // Check for action statuses that are too old and remove them executor.scheduleAtFixedRate(new Runnable() { @Override//from w w w. jav a2 s . com public void run() { final Date date = new Date(System.currentTimeMillis() - ACTION_STATUS_TIMEOUT); synchronized (statuses) { for (Queue<ActionStatusResponse> queue : statuses.values()) { while (queue.peek().updated.before(date)) { final ActionStatusResponse response = queue.poll(); if (logger.isDebugEnabled()) logger.debug("FeedbackHandler$Runnable.run", "Expiring action feedback response for action " + response.actionId); } } } } }, ACTION_STATUS_TIMEOUT, ACTION_STATUS_TIMEOUT, TimeUnit.MILLISECONDS); if (logger.isEntryEnabled()) logger.exit("FeedbackHandler"); }
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); }// w w w .j av a 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:org.rhq.plugins.modcluster.test.ModClusterPluginIntegrationTest.java
private Set<Resource> findResource(Resource parent) { Set<Resource> foundResources = new HashSet<Resource>(); Queue<Resource> discoveryQueue = new LinkedList<Resource>(); discoveryQueue.add(parent);/* w ww.java 2s. co m*/ while (!discoveryQueue.isEmpty()) { Resource currentResource = discoveryQueue.poll(); log.info("Discovered resource of type: " + currentResource.getResourceType().getName()); if (currentResource.getResourceType().getPlugin().equals(PLUGIN_NAME)) { foundResources.add(currentResource); } if (currentResource.getChildResources() != null) { for (Resource child : currentResource.getChildResources()) { discoveryQueue.add(child); } } } return foundResources; }
From source file:org.protempa.backend.ksb.SimpleKnowledgeSourceBackend.java
private Collection<String> collectSubtreePropositionIdsInt(String[] propIds, boolean narrower, boolean inDataSource) { Set<String> result = new HashSet<>(Arrays.asSet(propIds)); Queue<String> queue = new LinkedList<>(); queue.addAll(result);/*from w ww . j a v a 2 s . c o m*/ while (!queue.isEmpty()) { String propId = queue.poll(); PropositionDefinition pd = this.propDefsMap.get(propId); if (!inDataSource || pd.getInDataSource()) { result.add(propId); } if (narrower) { Arrays.addAll(queue, pd.getChildren()); } else { Arrays.addAll(queue, pd.getInverseIsA()); } } return result; }
From source file:com.naver.wordladder.WordLadder.java
public Node<String> getLeaf() { Queue<Node<String>> queue = new LinkedList<Node<String>>(); List<String> path = new ArrayList<String>(); queue.offer(new Node<String>(startString)); Node<String> currentNode; while ((currentNode = queue.poll()) != null) { String str = currentNode.getData(); path.add(str);// w ww . j av a 2 s . co m Set<String> oneDistanceWords = getOneDistanceWords(str); for (String oneDistanceWord : oneDistanceWords) { if (path.contains(oneDistanceWord)) { continue; } Node<String> child = new Node<String>(oneDistanceWord); child.setParent(currentNode); if (calculateEditDistance(oneDistanceWord, endString) == 1) { //start end? ? ?. Node<String> leaf = new Node<String>(endString); leaf.setParent(child); return leaf; } queue.offer(child); } } return new Node<String>(startString); }
From source file:com.microsoft.rest.serializer.FlatteningSerializer.java
@Override public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException { if (value == null) { jgen.writeNull();//from ww w . j a v a 2 s . c o m return; } // BFS for all collapsed properties ObjectNode root = mapper.valueToTree(value); ObjectNode res = root.deepCopy(); Queue<ObjectNode> source = new LinkedBlockingQueue<ObjectNode>(); Queue<ObjectNode> target = new LinkedBlockingQueue<ObjectNode>(); source.add(root); target.add(res); while (!source.isEmpty()) { ObjectNode current = source.poll(); ObjectNode resCurrent = target.poll(); Iterator<Map.Entry<String, JsonNode>> fields = current.fields(); while (fields.hasNext()) { Map.Entry<String, JsonNode> field = fields.next(); ObjectNode node = resCurrent; String key = field.getKey(); JsonNode outNode = resCurrent.get(key); if (field.getKey().matches(".+[^\\\\]\\..+")) { String[] values = field.getKey().split("((?<!\\\\))\\."); for (int i = 0; i < values.length; ++i) { values[i] = values[i].replace("\\.", "."); if (i == values.length - 1) { break; } String val = values[i]; if (node.has(val)) { node = (ObjectNode) node.get(val); } else { ObjectNode child = new ObjectNode(JsonNodeFactory.instance); node.put(val, child); node = child; } } node.set(values[values.length - 1], resCurrent.get(field.getKey())); resCurrent.remove(field.getKey()); outNode = node.get(values[values.length - 1]); } if (field.getValue() instanceof ObjectNode) { source.add((ObjectNode) field.getValue()); target.add((ObjectNode) outNode); } else if (field.getValue() instanceof ArrayNode && (field.getValue()).size() > 0 && (field.getValue()).get(0) instanceof ObjectNode) { Iterator<JsonNode> sourceIt = field.getValue().elements(); Iterator<JsonNode> targetIt = outNode.elements(); while (sourceIt.hasNext()) { source.add((ObjectNode) sourceIt.next()); target.add((ObjectNode) targetIt.next()); } } } } jgen.writeTree(res); }