List of usage examples for java.util Queue add
boolean add(E e);
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 {/* www . j av a 2 s. com*/ // 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:org.opendatakit.aggregate.format.structure.KmlGeoTraceNGeoShapeGenerator.java
@Override String generatePlacemarkSubmission(Submission sub, List<FormElementModel> propertyNames, CallingContext cc) throws ODKDatastoreException { StringBuilder placemarks = new StringBuilder(); // check if gps coordinate is in top element, else it's in a repeat if (geoParentRootSubmissionElement()) { placemarks.append(generatePlacemark(sub)); } else {/*w w w . ja v a2 s . c o m*/ Queue<SubmissionSet> submissionSetLevelsToExamine = new LinkedList<SubmissionSet>(); submissionSetLevelsToExamine.add(sub); while (!submissionSetLevelsToExamine.isEmpty()) { SubmissionSet submissionSet = submissionSetLevelsToExamine.remove(); recursiveElementSearchToFindRepeats(submissionSet, submissionSetLevelsToExamine, placemarks); } } return placemarks.toString(); }
From source file:com.microsoft.applicationinsights.internal.logger.FileLoggerOutputTest.java
@Test public void testChangeOfFiles() throws IOException { LogFileProxy mockProxy1 = Mockito.mock(LogFileProxy.class); Mockito.doReturn(true).when(mockProxy1).isFull(); LogFileProxy mockProxy2 = Mockito.mock(LogFileProxy.class); Mockito.doReturn(true).when(mockProxy2).isFull(); LogFileProxy mockProxy3 = Mockito.mock(LogFileProxy.class); final Queue<LogFileProxy> proxies = new LinkedList<LogFileProxy>(); proxies.add(mockProxy1); proxies.add(mockProxy2);/*from w w w .j a va2 s. c o m*/ proxies.add(mockProxy3); LogFileProxyFactory mockFactory = Mockito.mock(LogFileProxyFactory.class); Mockito.doAnswer(new Answer() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { return proxies.remove(); } }).when(mockFactory).create((File) anyObject(), anyString(), anyInt()); File folder = createFolderForTest(); FileLoggerOutput tested = createFileLoggerOutput(); tested.setLogProxyFactory(mockFactory); try { tested.log("line1"); tested.log("line2"); tested.log("line3"); } finally { if (folder != null && folder.exists()) { FileUtils.deleteDirectory(folder); } } Mockito.verify(mockFactory, Mockito.times(3)).create((File) anyObject(), anyString(), anyInt()); Mockito.verify(mockProxy1, Mockito.times(1)).writeLine(anyString()); Mockito.verify(mockProxy1, Mockito.times(1)).writeLine("line1"); Mockito.verify(mockProxy1, Mockito.times(1)).close(); Mockito.verify(mockProxy1, Mockito.times(1)).delete(); Mockito.verify(mockProxy2, Mockito.times(1)).writeLine(anyString()); Mockito.verify(mockProxy2, Mockito.times(1)).writeLine("line2"); Mockito.verify(mockProxy2, Mockito.times(1)).close(); Mockito.verify(mockProxy2, Mockito.never()).delete(); Mockito.verify(mockProxy3, Mockito.times(1)).writeLine(anyString()); Mockito.verify(mockProxy3, Mockito.times(1)).writeLine("line3"); Mockito.verify(mockProxy3, Mockito.never()).close(); Mockito.verify(mockProxy3, Mockito.never()).delete(); }
From source file:info.magnolia.test.mock.jcr.MockSession.java
@Override public Node getNodeByIdentifier(String id) throws RepositoryException { Queue<Node> queue = new LinkedList<Node>(); queue.add(rootNode); while (!queue.isEmpty()) { Node node = queue.remove(); // null safe equals check if (StringUtils.equals(id, node.getIdentifier())) return node; // add children to stack NodeIterator iterator = node.getNodes(); while (iterator.hasNext()) queue.add(iterator.nextNode()); }/*from w w w . j av a2 s .c om*/ throw new ItemNotFoundException("No node found with identifier/uuid [" + id + "]"); }
From source file:io.fabric8.kubernetes.server.mock.MockServerExpectationImpl.java
private void enqueue(ServerRequest req, ServerResponse resp) { Queue<ServerResponse> queuedResponses = responses.get(req); if (queuedResponses == null) { queuedResponses = new ArrayDeque<>(); responses.put(req, queuedResponses); }// ww w. ja va 2s .c om queuedResponses.add(resp); }
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); 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); }//from w w w. j a v a 2 s . co m if (currentResource.getChildResources() != null) { for (Resource child : currentResource.getChildResources()) { discoveryQueue.add(child); } } } return foundResources; }
From source file:org.commonjava.maven.ext.manip.rest.DefaultVersionTranslator.java
/** * Translate the versions./*from w ww. ja v a2 s.c o m*/ * There may be a lot of them, possibly causing timeouts or other issues. * This is mitigated by splitting them into smaller chunks when an error occurs and retrying. */ public Map<ProjectVersionRef, String> translateVersions(List<ProjectVersionRef> projects) { final Map<ProjectVersionRef, String> result = new HashMap<>(); final Queue<Task> queue = new ArrayDeque<>(); queue.add(new Task(pvrm, projects, endpointUrl)); while (!queue.isEmpty()) { Task task = queue.remove(); task.executeTranslate(); if (task.isSuccess()) { result.putAll(task.getResult()); } else { if (task.canSplit()) { if (task.getStatus() < 0) { logger.debug("Caught exception calling server with message {}", task.getErrorMessage()); } else { logger.debug("Did not get status {} but received {}", SC_OK, task.getStatus()); } List<Task> tasks = task.split(); logger.warn( "Failed to translate versions for task @{}, splitting and retrying. Chunk size was: {} and new chunk size {} in {} segments.", task.hashCode(), task.getChunkSize(), tasks.get(0).getChunkSize(), tasks.size()); queue.addAll(tasks); } else { logger.debug("Cannot split and retry anymore."); if (task.getStatus() > 0) { throw new RestException("Received response status " + task.getStatus() + " with message: " + task.getErrorMessage()); } else { throw new RestException("Received response status " + task.getStatus() + " with message " + task.getErrorMessage()); } } } } return result; }
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 .jav a 2 s . com 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:org.polymap.core.runtime.event.AnnotatedEventListener.java
/** * // w w w . j a v a2 s .c o m */ public AnnotatedEventListener(Object handler, Integer mapKey, EventFilter... filters) { assert handler != null; assert filters != null; this.handlerRef = new WeakReference(handler); this.handlerClass = handler.getClass(); this.mapKey = mapKey; // find annotated methods Queue<Class> types = new ArrayDeque(16); types.add(handler.getClass()); while (!types.isEmpty()) { Class type = types.remove(); if (type.getSuperclass() != null) { types.add(type.getSuperclass()); } types.addAll(Arrays.asList(type.getInterfaces())); for (Method m : type.getDeclaredMethods()) { EventHandler annotation = m.getAnnotation(EventHandler.class); if (annotation != null) { m.setAccessible(true); // annotated method AnnotatedMethod am = annotation.delay() > 0 ? new DeferredAnnotatedMethod(m, annotation) : new AnnotatedMethod(m, annotation); EventListener listener = am; // display thread; if (annotation.display()) { // if this is NOT the delegate of the DeferringListener then // check DeferringListener#SessionUICallbackCounter listener = new DisplayingListener(listener); } // deferred // XXX There is a race cond. between the UIThread and the event thread; if the UIThread // completes the current request before all display events are handled then the UI // is not updated until next user request; DeferringListener handles this by activating // UICallBack, improving behaviour - but not really solving in all cases; after 500ms we // are quite sure that no more events are pending and UI callback can turned off // currenty COMMENTED OUT! see EventManger#SessionEventDispatcher if (annotation.delay() > 0 /*|| annotation.display()*/) { int delay = annotation.delay() > 0 ? annotation.delay() : 500; listener = new TimerDeferringListener(listener, delay, 10000); } // filters listener = new FilteringListener(listener, ObjectArrays.concat(am.filters, filters, EventFilter.class)); // session context; first in chain so that all listener/filters // get the proper context SessionContext session = SessionContext.current(); if (session != null) { listener = new SessioningListener(listener, mapKey, session, handlerClass); } methods.add(listener); } } } if (methods.isEmpty()) { throw new IllegalArgumentException("No EventHandler annotation found in: " + handler.getClass()); } }
From source file:com.joyent.http.signature.apache.httpclient.HttpSignatureAuthenticationStrategy.java
@Override public Queue<AuthOption> select(final Map<String, Header> challengeHeaders, final HttpHost authhost, final HttpResponse response, final HttpContext context) throws MalformedChallengeException { final HttpClientContext httpClientContext = HttpClientContext.adapt(context); final AuthState state = httpClientContext.getTargetAuthState(); final Queue<AuthOption> queue = new LinkedList<>(); if (state == null || !state.getState().equals(AuthProtocolState.CHALLENGED)) { queue.add(authOption); } else {/* w w w . j ava 2 s.co m*/ System.out.println("does this happen?"); } return queue; }