List of usage examples for java.util Queue clear
void clear();
From source file:org.apache.tajo.rpc.RpcChannelFactory.java
public static void shutdownGracefully() { if (LOG.isDebugEnabled()) { LOG.debug("Shutdown Shared RPC Pool"); }//from w w w . j a va 2 s. c o m synchronized (lockObjectForLoopGroup) { for (Queue<EventLoopGroup> eventLoopGroupQueue : eventLoopGroupPool.values()) { for (EventLoopGroup eventLoopGroup : eventLoopGroupQueue) { eventLoopGroup.shutdownGracefully(); } eventLoopGroupQueue.clear(); } eventLoopGroupPool.clear(); } }
From source file:org.kuali.rice.krad.uif.lifecycle.ViewLifecycleUtils.java
/** * Return the lifecycle elements of the specified type from the given list * * <p>//from ww w. j a v a 2 s .c om * Elements that match, implement or are extended from the specified {@code elementType} are * returned in the result. If an element is a parent to other elements then these child elements * are searched for matching types as well. * </p> * * @param items list of elements from which to search * @param elementType the class or interface of the element type to return * @param <T> the type of the elements that are returned * @return List of matching elements */ public static <T extends LifecycleElement> List<T> getElementsOfTypeDeep( Collection<? extends LifecycleElement> items, Class<T> elementType) { if (items == null) { return Collections.emptyList(); } List<T> elements = Collections.emptyList(); @SuppressWarnings("unchecked") Queue<LifecycleElement> elementQueue = RecycleUtils.getInstance(LinkedList.class); elementQueue.addAll(items); try { while (!elementQueue.isEmpty()) { LifecycleElement currentElement = elementQueue.poll(); if (currentElement == null) { continue; } if (elementType.isInstance(currentElement)) { if (elements.isEmpty()) { elements = new ArrayList<T>(); } elements.add(elementType.cast(currentElement)); } elementQueue.addAll(getElementsForLifecycle(currentElement).values()); } } finally { elementQueue.clear(); RecycleUtils.recycle(elementQueue); } return elements; }
From source file:org.apache.hama.bsp.ResourceManager.java
private void clearQueues() { synchronized (tasksToRunByGroom) { for (java.util.Queue<TaskInProgress> queue : tasksToRunByGroom.values()) { queue.clear(); }//from ww w .j av a 2 s . co m executingTasks.clear(); } }
From source file:org.lunarray.model.descriptor.scanner.AnnotationScannerUtil.java
/** * Transitively tests for marker marks.//from w w w . j a va2 s. com * * @param marker * The marker. * @param processed * The processed annotations. * @param process * The annotations to process. * @return True if and only if the marker marks any of the processed * annotations. */ private boolean isMarkedTransiviteProcess(final Class<? extends Annotation> marker, final Set<Class<? extends Annotation>> processed, final Queue<Class<? extends Annotation>> process) { boolean marked = false; while (!process.isEmpty()) { final Class<? extends Annotation> poll = process.poll(); processed.add(poll); if (poll.equals(marker)) { marked = true; process.clear(); } else { for (final Annotation annotation : poll.getAnnotations()) { final Class<? extends Annotation> annotationType = annotation.annotationType(); if (!processed.contains(annotationType)) { process.add(annotationType); } } } } return marked; }
From source file:org.kuali.rice.krad.uif.lifecycle.ViewLifecycleUtils.java
/** * Get nested elements of the type specified one layer deep; this defers from * getElementsOfTypeShallow because it does NOT include itself as a match if it also matches the * type being requested./* w w w. ja va 2 s . c o m*/ * * @param element instance to get children for * @param elementType type for element to return * @param <T> type of element that will be returned * @return list of child elements with the given type */ public static <T extends LifecycleElement> List<T> getNestedElementsOfTypeShallow(LifecycleElement element, Class<T> elementType) { if (element == null) { return Collections.emptyList(); } List<T> elements = Collections.emptyList(); @SuppressWarnings("unchecked") Queue<LifecycleElement> elementQueue = RecycleUtils.getInstance(LinkedList.class); try { elementQueue.add(element); while (!elementQueue.isEmpty()) { LifecycleElement currentElement = elementQueue.poll(); if (currentElement == null) { continue; } if (elementType.isInstance(currentElement) && currentElement != element) { if (elements.isEmpty()) { elements = new ArrayList<T>(); } elements.add(elementType.cast(currentElement)); } for (LifecycleElement nestedElement : getElementsForLifecycle(currentElement).values()) { if (!(nestedElement instanceof Component)) { elementQueue.offer(nestedElement); } } } } finally { elementQueue.clear(); RecycleUtils.recycle(elementQueue); } return elements; }
From source file:hudson.model.QueueTest.java
/** * Can {@link Queue} successfully recover removal? *//* ww w. j a va 2s . c o m*/ public void testPersistence2() throws Exception { Queue q = hudson.getQueue(); // prevent execution to push stuff into the queue hudson.setNumExecutors(0); hudson.setSlaves(hudson.getSlaves()); FreeStyleProject testProject = createFreeStyleProject("test"); testProject.scheduleBuild(); q.save(); System.out.println(FileUtils.readFileToString(new File(hudson.getRootDir(), "queue.xml"))); assertEquals(1, q.getItems().length); q.clear(); assertEquals(0, q.getItems().length); // delete the project before loading the queue back testProject.delete(); q.load(); assertEquals(0, q.getItems().length); }
From source file:hudson.model.QueueTest.java
/** * Checks the persistence of queue.//from w w w . j av a 2s .c o m */ public void testPersistence() throws Exception { Queue q = hudson.getQueue(); // prevent execution to push stuff into the queue hudson.setNumExecutors(0); hudson.setSlaves(hudson.getSlaves()); FreeStyleProject testProject = createFreeStyleProject("test"); testProject.scheduleBuild(); q.save(); System.out.println(FileUtils.readFileToString(new File(hudson.getRootDir(), "queue.xml"))); assertEquals(1, q.getItems().length); q.clear(); assertEquals(0, q.getItems().length); // load the contents back q.load(); assertEquals(1, q.getItems().length); // did it bind back to the same object? assertSame(q.getItems()[0].task, testProject); }
From source file:org.kuali.rice.krad.uif.util.ComponentUtils.java
/** * places a key, value pair in each context map of a list of components * * @param elements the list of elements/*w w w.j av a2 s . co m*/ * @param contextName a value to be used as a key to retrieve the object * @param contextValue the value to be placed in the context */ public static void pushObjectToContext(Collection<? extends LifecycleElement> elements, String contextName, Object contextValue) { if (elements == null || elements.isEmpty()) { return; } Queue<LifecycleElement> elementQueue = new LinkedList<LifecycleElement>(); try { elementQueue.addAll(elements); while (!elementQueue.isEmpty()) { LifecycleElement currentElement = elementQueue.poll(); if (currentElement == null) { continue; } if (currentElement instanceof Component) { ((Component) currentElement).pushObjectToContext(contextName, contextValue); } elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(currentElement).values()); } } finally { elementQueue.clear(); RecycleUtils.recycle(elementQueue); } }
From source file:org.kuali.rice.krad.uif.util.ComponentUtils.java
/** * places a all entries from a map into each context map of a list of components * * @param components The list components. * @param sourceContext The source context map. *//*w w w. j av a2s. co m*/ public static void pushAllToContext(List<? extends Component> components, Map<String, Object> sourceContext) { if (components == null || components.isEmpty()) { return; } @SuppressWarnings("unchecked") Queue<LifecycleElement> elementQueue = RecycleUtils.getInstance(LinkedList.class); try { elementQueue.addAll(components); while (!elementQueue.isEmpty()) { LifecycleElement currentElement = elementQueue.poll(); if (currentElement == null) { continue; } if (currentElement instanceof Component) { ((Component) currentElement).pushAllToContext(sourceContext); } elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(currentElement).values()); } } finally { elementQueue.clear(); RecycleUtils.recycle(elementQueue); } }
From source file:org.kuali.rice.krad.uif.util.ComponentUtils.java
public static void updateChildIdsWithSuffixNested(Component component, String idSuffix) { @SuppressWarnings("unchecked") Queue<LifecycleElement> elementQueue = RecycleUtils.getInstance(LinkedList.class); try {// w ww . jav a 2 s. c o m elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(component).values()); while (!elementQueue.isEmpty()) { LifecycleElement currentElement = elementQueue.poll(); if (currentElement == null) { continue; } if (currentElement instanceof Component) { updateIdWithSuffix((Component) currentElement, idSuffix); elementQueue.addAll(((Component) currentElement).getPropertyReplacerComponents()); } elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(currentElement).values()); } } finally { elementQueue.clear(); RecycleUtils.recycle(elementQueue); } }