List of usage examples for java.util Queue isEmpty
boolean isEmpty();
From source file:org.rhq.modules.plugins.wildfly10.itest.standalone.TemplatedResourcesTest.java
@Test(priority = 11) public void loadUpdateTemplatedResourceConfiguration() throws Exception { ConfigurationManager configurationManager = this.pluginContainer.getConfigurationManager(); for (ResourceData resourceData : testResourceData) { ResourceType resourceType = new ResourceType(resourceData.resourceTypeName, Constants.PLUGIN_NAME, ResourceCategory.SERVICE, null); Resource subsystem = waitForResourceByTypeAndKey(platform, server, resourceType, resourceData.resourceKey); Assert.assertNotNull(subsystem); Queue<Resource> unparsedResources = new LinkedList<Resource>(); unparsedResources.add(subsystem); List<Resource> foundResources = new ArrayList<Resource>(); while (!unparsedResources.isEmpty()) { Resource currentResource = unparsedResources.poll(); for (Resource childResource : currentResource.getChildResources()) { unparsedResources.add(childResource); if (childResource.getResourceType().getName().equals(resourceData.subResourceType)) { foundResources.add(childResource); }//from w w w. j a va 2s . c om } } for (Resource resourceUnderTest : foundResources) { log.info(foundResources); assert resourceUnderTest .getId() != 0 : "Resource not properly initialized. Id = 0. Try extending sleep after discovery."; Configuration resourceUnderTestConfig = configurationManager .loadResourceConfiguration(resourceUnderTest.getId()); Assert.assertNotNull(resourceUnderTestConfig); Assert.assertFalse(resourceUnderTestConfig.getProperties().isEmpty()); boolean specialPropertyFound = false; for (Property property : resourceUnderTestConfig.getProperties()) { if (property.getName().equals(resourceData.specialConfigurationProperty)) { Assert.assertNotNull(((PropertySimple) property).getStringValue()); specialPropertyFound = true; break; } } Assert.assertTrue(specialPropertyFound, resourceData.specialConfigurationProperty + "property not found in the list of properties"); ConfigurationUpdateRequest testUpdateRequest = new ConfigurationUpdateRequest(1, resourceUnderTestConfig, resourceUnderTest.getId()); ConfigurationUpdateResponse response = configurationManager .executeUpdateResourceConfigurationImmediately(testUpdateRequest); Assert.assertNotNull(response); } } }
From source file:org.rhq.modules.plugins.jbossas7.itest.standalone.TemplatedResourcesTest.java
@Test(priority = 11) public void loadUpdateTemplatedResourceConfiguration() throws Exception { ConfigurationManager configurationManager = this.pluginContainer.getConfigurationManager(); for (ResourceData resourceData : testResourceData) { ResourceType resourceType = new ResourceType(resourceData.resourceTypeName, PLUGIN_NAME, ResourceCategory.SERVICE, null); Resource subsystem = waitForResourceByTypeAndKey(platform, server, resourceType, resourceData.resourceKey); Assert.assertNotNull(subsystem); Queue<Resource> unparsedResources = new LinkedList<Resource>(); unparsedResources.add(subsystem); List<Resource> foundResources = new ArrayList<Resource>(); while (!unparsedResources.isEmpty()) { Resource currentResource = unparsedResources.poll(); for (Resource childResource : currentResource.getChildResources()) { unparsedResources.add(childResource); if (childResource.getResourceType().getName().equals(resourceData.subResourceType)) { foundResources.add(childResource); }//from ww w. j a v a2s.c o m } } for (Resource resourceUnderTest : foundResources) { log.info(foundResources); assert resourceUnderTest .getId() != 0 : "Resource not properly initialized. Id = 0. Try extending sleep after discovery."; Configuration resourceUnderTestConfig = configurationManager .loadResourceConfiguration(resourceUnderTest.getId()); Assert.assertNotNull(resourceUnderTestConfig); Assert.assertFalse(resourceUnderTestConfig.getProperties().isEmpty()); boolean specialPropertyFound = false; for (Property property : resourceUnderTestConfig.getProperties()) { if (property.getName().equals(resourceData.specialConfigurationProperty)) { Assert.assertNotNull(((PropertySimple) property).getStringValue()); specialPropertyFound = true; break; } } Assert.assertTrue(specialPropertyFound, resourceData.specialConfigurationProperty + "property not found in the list of properties"); ConfigurationUpdateRequest testUpdateRequest = new ConfigurationUpdateRequest(1, resourceUnderTestConfig, resourceUnderTest.getId()); ConfigurationUpdateResponse response = configurationManager .executeUpdateResourceConfigurationImmediately(testUpdateRequest); Assert.assertNotNull(response); } } }
From source file:org.polymap.core.model2.engine.EntityRepositoryImpl.java
public EntityRepositoryImpl(final EntityRepositoryConfiguration config) { this.config = config; // init store getStore().init(new StoreRuntimeContextImpl()); // init infos log.info("Initialializing Composite types:"); Queue<Class<? extends Composite>> queue = new LinkedList(); queue.addAll(Arrays.asList(config.getEntities())); while (!queue.isEmpty()) { log.info(" Composite type: " + queue.peek()); CompositeInfoImpl info = new CompositeInfoImpl(queue.poll()); infos.put(info.getType(), info); // mixins queue.addAll(info.getMixins());/*from w ww .j a va2 s. co m*/ // Composite properties for (PropertyInfo propInfo : info.getProperties()) { if (Composite.class.isAssignableFrom(propInfo.getType())) { queue.offer(propInfo.getType()); } } } }
From source file:gobblin.util.HadoopUtils.java
/** * This method is an additive implementation of the {@link FileSystem#rename(Path, Path)} method. It moves all the * files/directories under 'from' path to the 'to' path without overwriting existing directories in the 'to' path. * * <p>/*from w w w . j a v a2 s . c o m*/ * The rename operation happens at the first non-existent sub-directory. If a directory at destination path already * exists, it recursively tries to move sub-directories. If all the sub-directories also exist at the destination, * a file level move is done * </p> * * @param fileSystem on which the data needs to be moved * @param from path of the data to be moved * @param to path of the data to be moved */ public static void renameRecursively(FileSystem fileSystem, Path from, Path to) throws IOException { log.info(String.format("Recursively renaming %s in %s to %s.", from, fileSystem.getUri(), to)); FileSystem throttledFS = getOptionallyThrottledFileSystem(fileSystem, 10000); ExecutorService executorService = ScalingThreadPoolExecutor.newScalingThreadPool(1, 100, 100, ExecutorsUtils.newThreadFactory(Optional.of(log), Optional.of("rename-thread-%d"))); Queue<Future<?>> futures = Queues.newConcurrentLinkedQueue(); try { if (!fileSystem.exists(from)) { throw new IOException("Trying to rename a path that does not exist! " + from); } futures.add(executorService.submit(new RenameRecursively(throttledFS, fileSystem.getFileStatus(from), to, executorService, futures))); int futuresUsed = 0; while (!futures.isEmpty()) { try { futures.poll().get(); futuresUsed++; } catch (ExecutionException | InterruptedException ee) { throw new IOException(ee.getCause()); } } log.info(String.format("Recursive renaming of %s to %s. (details: used %d futures)", from, to, futuresUsed)); } finally { ExecutorsUtils.shutdownExecutorService(executorService, Optional.of(log), 1, TimeUnit.SECONDS); } }
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 w w .j a va 2 s.com 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:org.apache.http.HC4.impl.auth.HttpAuthenticator.java
public void generateAuthResponse(final HttpRequest request, final AuthState authState, final HttpContext context) throws HttpException, IOException { AuthScheme authScheme = authState.getAuthScheme(); Credentials creds = authState.getCredentials(); switch (authState.getState()) { // TODO add UNCHALLENGED and HANDSHAKE cases case FAILURE: return;// w w w .j a v a 2s . c o m case SUCCESS: ensureAuthScheme(authScheme); if (authScheme.isConnectionBased()) { return; } break; case CHALLENGED: final Queue<AuthOption> authOptions = authState.getAuthOptions(); if (authOptions != null) { while (!authOptions.isEmpty()) { final AuthOption authOption = authOptions.remove(); authScheme = authOption.getAuthScheme(); creds = authOption.getCredentials(); authState.update(authScheme, creds); if (this.log.isDebugEnabled()) { this.log.debug("Generating response to an authentication challenge using " + authScheme.getSchemeName() + " scheme"); } try { final Header header = doAuth(authScheme, creds, request, context); request.addHeader(header); break; } catch (final AuthenticationException ex) { if (this.log.isWarnEnabled()) { this.log.warn(authScheme + " authentication error: " + ex.getMessage()); } } } return; } else { ensureAuthScheme(authScheme); } } if (authScheme != null) { try { final Header header = doAuth(authScheme, creds, request, context); request.addHeader(header); } catch (final AuthenticationException ex) { if (this.log.isErrorEnabled()) { this.log.error(authScheme + " authentication error: " + ex.getMessage()); } } } }
From source file:org.finra.datagenerator.engine.scxml.SCXMLFrontierTest.java
/** * Test the ability of the exit flag to stop the DFS in SCXMLFrontier *//*from ww w . j ava 2s . c o m*/ @Test public void testExitFlag() { SCXMLEngine e = new SCXMLEngine(); InputStream is = SCXMLEngineTest.class.getResourceAsStream("/bigtest.xml"); e.setModelByInputFileStream(is); List<CustomTagExtension> tagExtensionList = customTagExtensionList(); try { List<PossibleState> bfs = e.bfs(1); PossibleState p = bfs.get(0); try { is = SCXMLEngineTest.class.getResourceAsStream("/bigtest.xml"); SCXML model = SCXMLParser.parse(new InputSource(is), null, customActionsFromTagExtensions(tagExtensionList)); SCXMLFrontier frontier = new SCXMLFrontier(p, model, tagExtensionList); Queue<Map<String, String>> queue = new LinkedList<>(); AtomicBoolean flag = new AtomicBoolean(true); frontier.searchForScenarios(new QueueResultsProcessing(queue), flag); Assert.assertEquals(queue.isEmpty(), true); } catch (IOException | SAXException ex) { Assert.fail(); } } catch (ModelException ex) { Assert.fail(); } }
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 w w w. j a v a 2s . 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); }
From source file:com.epam.reportportal.apache.http.impl.auth.HttpAuthenticator.java
public void generateAuthResponse(final HttpRequest request, final AuthState authState, final HttpContext context) throws HttpException, IOException { AuthScheme authScheme = authState.getAuthScheme(); Credentials creds = authState.getCredentials(); switch (authState.getState()) { case FAILURE: return;// ww w. j a v a2s. c om case SUCCESS: ensureAuthScheme(authScheme); if (authScheme.isConnectionBased()) { return; } break; case CHALLENGED: final Queue<AuthOption> authOptions = authState.getAuthOptions(); if (authOptions != null) { while (!authOptions.isEmpty()) { final AuthOption authOption = authOptions.remove(); authScheme = authOption.getAuthScheme(); creds = authOption.getCredentials(); authState.update(authScheme, creds); if (this.log.isDebugEnabled()) { this.log.debug("Generating response to an authentication challenge using " + authScheme.getSchemeName() + " scheme"); } try { final Header header = doAuth(authScheme, creds, request, context); request.addHeader(header); break; } catch (final AuthenticationException ex) { if (this.log.isWarnEnabled()) { this.log.warn(authScheme + " authentication error: " + ex.getMessage()); } } } return; } else { ensureAuthScheme(authScheme); } } if (authScheme != null) { try { final Header header = doAuth(authScheme, creds, request, context); request.addHeader(header); } catch (final AuthenticationException ex) { if (this.log.isErrorEnabled()) { this.log.error(authScheme + " authentication error: " + ex.getMessage()); } } } }
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 */// ww w. j a va 2 s.c o 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; }