Example usage for java.util Queue poll

List of usage examples for java.util Queue poll

Introduction

In this page you can find the example usage for java.util Queue poll.

Prototype

E poll();

Source Link

Document

Retrieves and removes the head of this queue, or returns null if this queue is empty.

Usage

From source file:com.dbay.apns4j.impl.ApnsResender.java

public void resend(String name, Queue<PushNotification> queue) {
    IApnsService service = ApnsServiceImpl.getCachedService(name);
    if (service != null) {
        while (!queue.isEmpty()) {
            service.sendNotification(queue.poll());
        }/*from w w  w  .  j  a v  a 2  s  .co  m*/
    } else {
        logger.error("Cached service is null. name: " + name);
    }
}

From source file:org.kuali.rice.krad.uif.util.ComponentUtils.java

/**
 * Get all nested children of a given component.
 *
 * @param component The component to search.
 * @return All nested children of the component.
 * @see ViewLifecycleUtils#getElementsForLifecycle(LifecycleElement)
 *//*  ww  w.jav  a 2  s.c o  m*/
public static List<Component> getAllNestedComponents(Component component) {
    if (component == null) {
        return Collections.emptyList();
    }

    List<Component> components = Collections.emptyList();
    @SuppressWarnings("unchecked")
    Queue<LifecycleElement> elementQueue = RecycleUtils.getInstance(LinkedList.class);
    elementQueue.offer(component);

    try {
        while (!elementQueue.isEmpty()) {
            LifecycleElement currentElement = elementQueue.poll();

            if (currentElement == null) {
                continue;
            }

            if (currentElement instanceof Component && currentElement != component) {
                if (components.isEmpty()) {
                    components = new ArrayList<Component>();
                }

                components.add((Component) currentElement);
            }

            elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(currentElement).values());
        }
    } finally {
        elementQueue.clear();
        RecycleUtils.recycle(elementQueue);
    }

    return components;
}

From source file:org.auraframework.test.PooledRemoteWebDriverFactory.java

@Override
public synchronized void release() {
    for (Queue<PooledRemoteWebDriver> pool : pools.values()) {
        PooledRemoteWebDriver driver = pool.poll();
        while (driver != null) {
            driver.superQuit();/*w ww .j  av  a2s.co  m*/
            driver = pool.poll();
        }
    }
}

From source file:pt.webdetails.cda.cache.scheduler.CacheActivator.java

public void processQueries(Session s, Queue<CachedQuery> queue) {

    logger.debug("Refreshing cached query");
    CachedQuery q = queue.poll();
    try {//from w  w w. j  a  v a 2s .  c  o m
        IPentahoSession session = PentahoSessionHolder.getSession();
        s.refresh(q);
        setSession(q);
        q.execute();
        PentahoSessionHolder.setSession(session);
    } catch (Exception ex) {
        logger.error("Failed to execute " + q.toString(), ex);
    }

    q.updateNext();
    queue.add(q);
    s.update(q);
}

From source file:org.kuali.rice.krad.uif.util.ComponentUtils.java

/**
 * Traverse a component tree, setting a property on all components for which the property is writable.
 *
 * @param <T> component type/*from   w  w  w.ja  va  2  s  . co  m*/
 * @param <T> component type
 * @param components The components to traverse.
 * @param propertyPath The property path to set.
 * @param propertyValue The property value to set.
 * @see ObjectPropertyUtils#isWritableProperty(Object, String)
 * @see ObjectPropertyUtils#setPropertyValue(Object, String, Object)
 */
public static <T extends Component> void setComponentsPropertyDeep(List<T> components, String propertyPath,
        Object propertyValue) {
    if (components == null || components.isEmpty()) {
        return;
    }

    Set<Class<?>> skipTypes = null;
    @SuppressWarnings("unchecked")
    Queue<LifecycleElement> elementQueue = RecycleUtils.getInstance(LinkedList.class);
    elementQueue.addAll(components);

    try {
        while (!elementQueue.isEmpty()) {
            LifecycleElement currentElement = elementQueue.poll();
            if (currentElement == null) {
                continue;
            }

            elementQueue.addAll(ViewLifecycleUtils.getElementsForLifecycle(currentElement).values());

            Class<?> componentClass = currentElement.getClass();
            if (skipTypes != null && skipTypes.contains(componentClass)) {
                continue;
            }

            if (!ObjectPropertyUtils.isWritableProperty(currentElement, propertyPath)) {
                if (skipTypes == null) {
                    skipTypes = new HashSet<Class<?>>();
                }
                skipTypes.add(componentClass);
                continue;
            }

            ObjectPropertyUtils.setPropertyValue(currentElement, propertyPath, propertyValue, true);
        }
    } finally {
        elementQueue.clear();
        RecycleUtils.recycle(elementQueue);
    }
}

From source file:cl.borrego.process.batch.impl.TaskLifeCycleManagerImpl.java

/**
 * Process the task. Acceptable end states are Completed, Error or Initial state.
 *
 * @param taskQueue Distribute tasks/*from  www .j  av a2s  . com*/
 * @return ProcessReport All processed reports
 */
public synchronized List<Report> processTask(Queue<Task> taskQueue) {
    if (taskQueue == null) {
        throw new RuntimeException();
    }
    for (;;) {
        Task task = taskQueue.poll();
        try {
            if (task == null) {
                //TODO should it wait some time?
            } else {
                if (task instanceof PoisonousTask) {
                    dumpFormattedMessage(Message.LevelEnum.INFO, "ending.process");
                    break;
                }
                successTaskLifeCyclePath(task);
            }
        } catch (ErrorPresentTaskProcessorBusinessException e) {
            dumpFormattedMessage(Message.LevelEnum.ERROR, "task.error.present", e);
            task.markWithError();
            dumpFormattedMessage(Message.LevelEnum.INFO, "marked.task.with.error", e);
        } catch (Exception e) {
            LOG.error(e);
            dumpFormattedMessage(Message.LevelEnum.ERROR, "process.error.present", e);
            task.release();
            dumpFormattedMessage(Message.LevelEnum.INFO, "released.task", e);
        } finally {
            //TODO assert status is a valid state
        }
    }
    dumpFormattedMessage(Message.LevelEnum.INFO, "processed.entries", m_processReportList.size());
    dumpFormattedMessage(Message.LevelEnum.DEBUG, "processed.entries.detail", m_processReportList);
    return m_processReportList;
}

From source file:com.stehno.sanctuary.core.scan.DefaultDirectoryScanner.java

/**
 * Scans the given directory for changes. The directory passed in will be used as the root
 * of the changeset and the stored files.
 * /*from  w  w  w.  ja  va 2 s  . co  m*/
 * @param directory
 * @return a populated change set.
 */
@Override
public ChangeSet scanDirectory(final File directory) {
    Assert.isTrue(directory != null && directory.isDirectory(), "A non-null directory must be specified.");

    if (log.isDebugEnabled())
        log.debug("Scanning: " + directory);

    final ChangeSet changeSet = new ChangeSet(directory);

    final Queue<File> directories = new LinkedList<File>();
    directories.add(directory);

    while (!directories.isEmpty()) {
        final File scanningDir = directories.poll();

        for (final File item : scanningDir.listFiles()) {
            if (item.isDirectory()) {
                directories.add(item);
            } else {
                changeSet.addFileStatus(localStore.fileStatus(item), item);
            }
        }
    }

    // figure out the deleted files
    for (final String path : localStore.listFilePaths()) {
        final File file = new File(path);
        if (!file.exists()) {
            changeSet.addFileStatus(FileStatus.DELETED, file);
        }
    }

    return changeSet;
}

From source file:io.netty.handler.codec.compression.JdkZlibTest.java

@Test
public void testConcatenatedStreamsReadFully() throws IOException {
    EmbeddedChannel chDecoderGZip = new EmbeddedChannel(new JdkZlibDecoder(true));

    try {/*  ww w. j av a 2 s.  c  o  m*/
        byte[] bytes = IOUtils.toByteArray(getClass().getResourceAsStream("/multiple.gz"));

        assertTrue(chDecoderGZip.writeInbound(Unpooled.copiedBuffer(bytes)));
        Queue<Object> messages = chDecoderGZip.inboundMessages();
        assertEquals(2, messages.size());

        for (String s : Arrays.asList("a", "b")) {
            ByteBuf msg = (ByteBuf) messages.poll();
            assertEquals(s, msg.toString(CharsetUtil.UTF_8));
            ReferenceCountUtil.release(msg);
        }
    } finally {
        assertFalse(chDecoderGZip.finish());
        chDecoderGZip.close();
    }
}

From source file:org.jboss.on.plugins.tomcat.test.TomcatPluginTest.java

private Set<Resource> findResource(Resource parent, String typeName) {
    Set<Resource> foundResources = new HashSet<Resource>();

    Queue<Resource> discoveryQueue = new LinkedList<Resource>();
    discoveryQueue.add(parent);//from w w w  . j  a  va 2  s .  c om

    while (!discoveryQueue.isEmpty()) {
        Resource currentResource = discoveryQueue.poll();

        log.info("Discovered resource of type: " + currentResource.getResourceType().getName());
        if (currentResource.getResourceType().getName().equals(typeName)) {
            foundResources.add(currentResource);
        }

        for (Resource child : currentResource.getChildResources()) {
            discoveryQueue.add(child);
        }
    }

    return foundResources;
}

From source file:org.apache.hadoop.mapred.nativetask.buffer.DirectBufferPool.java

public synchronized ByteBuffer borrowBuffer(int capacity) throws IOException {
    Queue<WeakReference<ByteBuffer>> list = bufferMap.get(capacity);
    if (null == list) {
        return ByteBuffer.allocateDirect(capacity);
    }/*from w  w  w  .  ja  va2 s .  co m*/
    WeakReference<ByteBuffer> ref;
    while ((ref = list.poll()) != null) {
        ByteBuffer buf = ref.get();
        if (buf != null) {
            return buf;
        }
    }
    return ByteBuffer.allocateDirect(capacity);
}