Example usage for java.util.concurrent DelayQueue DelayQueue

List of usage examples for java.util.concurrent DelayQueue DelayQueue

Introduction

In this page you can find the example usage for java.util.concurrent DelayQueue DelayQueue.

Prototype

public DelayQueue() 

Source Link

Document

Creates a new DelayQueue that is initially empty.

Usage

From source file:DelayedJob.java

public static void main(String[] args) throws InterruptedException {
    BlockingQueue<DelayedJob> queue = new DelayQueue<>();
    Instant now = Instant.now();

    queue.put(new DelayedJob("A", now.plusSeconds(9)));
    queue.put(new DelayedJob("B", now.plusSeconds(3)));
    queue.put(new DelayedJob("C", now.plusSeconds(6)));
    queue.put(new DelayedJob("D", now.plusSeconds(1)));

    while (queue.size() > 0) {
        System.out.println("started...");
        DelayedJob job = queue.take();/*  w  w w. j av a2 s  . c  om*/
        System.out.println("Job: " + job);
    }
    System.out.println("Finished.");
}

From source file:de.hpi.fgis.hdrs.node.SegmentServiceThread.java

public SegmentServiceThread(SegmentServer server) {
    this.server = server;
    queue = new DelayQueue<DelayQueueEntry>();
}

From source file:com.opentech.camel.task.watchdog.DefaultWatchdog.java

@Override
public void initialize() {
    super.initialize();
    watchdogQueue = new DelayQueue<WatchedTask>();
    watchdogThread = new Thread(new Runnable() {

        @Override/*w  ww . ja  va  2s  .co  m*/
        public void run() {
            WatchedTask wt = null;
            while (Thread.currentThread().isInterrupted()) {
                try {
                    wt = null;
                    // TODO
                    wt = watchdogQueue.take();
                    // XXX
                    if (Status.RUNING == wt.getWt().getTask().getStatus()) {
                        wt.getFuture().cancel(true);
                        wt.getWt().getTask().timeout();
                        wt.getWt().getTask().after();
                    }
                } catch (InterruptedException e) {
                    logger.error("Watchdog Interrupted", e);
                    Thread.currentThread().interrupt();
                } catch (Throwable t) {
                    logger.error("Watchdog Error", t);
                } finally {
                    // ?
                    if (null != wt) {
                        // XXX ?
                        wt.getWt().getResourceHolder().release();
                    }
                }
            }
        }

    });
    watchdogThread.start();
}

From source file:org.wso2.andes.task.TaskExecutorService.java

/**
 * Create a Task manager with a given number of threads to process the tasks
 *
 * @param workerCount maximum number of threads spawned to process the tasks
 * @param idleTaskDelayMillis delay set for processing a task with IDLE {@link org.wso2.andes.task.Task.TaskHint}
 * @param threadFactory  thread factory to be used for processing the tasks
 *//*from   w  ww.j av  a  2 s  .co  m*/
public TaskExecutorService(int workerCount, long idleTaskDelayMillis, ThreadFactory threadFactory) {

    taskExecutorPool = Executors.newFixedThreadPool(workerCount, threadFactory);
    this.workerCount = workerCount;
    taskProcessorQueue = new ArrayDeque<>(workerCount);
    taskUpdateExecutorService = Executors.newSingleThreadExecutor(threadFactory);
    taskExceptionHandler = new DefaultExceptionHandler();
    taskHolderDelayQueue = new DelayQueue<>();
    taskHolderRegistry = new ConcurrentHashMap<>();
    this.idleTaskDelayMillis = idleTaskDelayMillis;
}

From source file:org.apache.hadoop.distributedloadsimulator.sls.nodemanager.NMSimulator.java

public void init(String nodeIdStr, int memory, int cores, int dispatchTime, int heartBeatInterval,
        ResourceManager rm, Configuration conf) throws IOException, YarnException, ClassNotFoundException {
    super.init(dispatchTime, dispatchTime + 1000000L * heartBeatInterval, heartBeatInterval);
    conf.setClass(YarnConfiguration.LEADER_CLIENT_FAILOVER_PROXY_PROVIDER,
            ConfiguredLeastLoadedRMFailoverHAProxyProvider.class, RMFailoverProxyProvider.class);
    Class<? extends RMFailoverProxyProvider> defaultProviderClass = (Class<? extends RMFailoverProxyProvider>) Class
            .forName(YarnConfiguration.DEFAULT_LEADER_CLIENT_FAILOVER_PROXY_PROVIDER);
    this.resourceTracker = ServerRMProxy.createRMProxy(conf, ResourceTracker.class,
            conf.getBoolean(YarnConfiguration.DISTRIBUTED_RM, YarnConfiguration.DEFAULT_DISTRIBUTED_RM));
    // create resource
    String rackHostName[] = SLSUtils.getRackHostName(nodeIdStr);
    this.node = NodeInfo.newNodeInfo(rackHostName[0], rackHostName[1], BuilderUtils.newResource(memory, cores));
    //this.nodeId = NodeId.newInstance(InetAddress.getLocalHost().getHostName(),port);
    //this.rm = rm;
    // init data structures
    completedContainerList = Collections.synchronizedList(new ArrayList<ContainerId>());
    releasedContainerList = Collections.synchronizedList(new ArrayList<ContainerId>());
    containerQueue = new DelayQueue<ContainerSimulator>();
    amContainerList = Collections.synchronizedList(new ArrayList<ContainerId>());
    runningContainers = new ConcurrentHashMap<ContainerId, ContainerSimulator>();
    // register NM with RM
    RegisterNodeManagerRequest req = Records.newRecord(RegisterNodeManagerRequest.class);
    req.setNodeId(node.getNodeID());//from   w  w  w. ja va 2s . c  om
    req.setResource(node.getTotalCapability());
    req.setHttpPort(80);
    LOG.info("send registration request " + node.getNodeID());
    RegisterNodeManagerResponse response = resourceTracker.registerNodeManager(req);
    LOG.info("registration done " + node.getNodeID());
    masterKey = response.getNMTokenMasterKey();
    containerMasterKey = response.getContainerTokenMasterKey();
}

From source file:org.apache.hawq.pxf.service.UGICache.java

/**
 * Get the queue of cache entries associated with a segment, creating it if it doesn't yet
 * exist. This lets us lazily populate the expirationQueueMap.
 *
 * @param segmentId/*from ww  w.ja  va2  s.co m*/
 * @return the {@link DelayQueue} associated to the segment.
 */
private DelayQueue<Entry> getExpirationQueue(Integer segmentId) {
    DelayQueue<Entry> queue = expirationQueueMap.get(segmentId);
    if (queue == null) {
        synchronized (expirationQueueMap) {
            queue = expirationQueueMap.get(segmentId);
            if (queue == null) {
                queue = new DelayQueue<>();
                expirationQueueMap.put(segmentId, queue);
            }
        }
    }
    return queue;
}

From source file:org.archive.crawler.frontier.BdbFrontier.java

@Override
protected void initOtherQueues() throws DatabaseException {
    boolean recycle = (recoveryCheckpoint != null);

    // tiny risk of OutOfMemoryError: if giant number of snoozed
    // queues all wake-to-ready at once
    readyClassQueues = new LinkedBlockingQueue<String>();

    inactiveQueuesByPrecedence = new ConcurrentSkipListMap<Integer, Queue<String>>();

    retiredQueues = bdb.getStoredQueue("retiredQueues", String.class, recycle);

    // primary snoozed queues
    snoozedClassQueues = new DelayQueue<DelayedWorkQueue>();
    // just in case: overflow for extreme situations
    snoozedOverflow = bdb.getStoredMap("snoozedOverflow", Long.class, DelayedWorkQueue.class, true, false);

    this.futureUris = bdb.getStoredMap("futureUris", Long.class, CrawlURI.class, true,
            recoveryCheckpoint != null);

    // initialize master map in which other queues live
    this.pendingUris = createMultipleWorkQueues();
}

From source file:org.jiemamy.utils.collection.CollectionsUtil.java

/**
 * {@link DelayQueue}?????// ww w  .j  ava 2s.com
 * 
 * @param <E> {@link CopyOnWriteArraySet}??
 * @return {@link DelayQueue}???
 * @see DelayQueue#DelayQueue()
 */
public static <E extends Delayed> DelayQueue<E> newDelayQueue() {
    return new DelayQueue<E>();
}