Package java.util.concurrent

Examples of java.util.concurrent.ScheduledFuture


     * Schedules the task for execution with the contained timeout. If a task
     * is already pending or running, it will be cancelled (not interrupted).
     * The new task will be scheduled to run in now + timeout.
     */
    public ScheduledFuture schedule() {
        ScheduledFuture currentTask = cancelCurrentTask();
        ScheduledFuture newTask = m_executor.schedule(m_task, m_timeout, m_timeUnit);
        m_futureRef.compareAndSet(currentTask, newTask);
        return newTask;
    }
View Full Code Here


    /**
     * @return the current task, or <code>null</code> if no task is available.
     */
    private ScheduledFuture cancelCurrentTask() {
        ScheduledFuture currentTask = (ScheduledFuture) m_futureRef.get();
        if (currentTask != null) {
            // Doesn't matter for completed tasks...
            currentTask.cancel(false /* mayInterruptIfRunning */);
        }
        return currentTask;
    }
View Full Code Here

     */
    private void scheduleCancelInflight(final String queueUrl, final Message message) {
        if (scheduler != null) {
            int visibility = getVisibilityForQueue(queueUrl);
            if (visibility > 0) {
                ScheduledFuture task = scheduler.schedule(new Runnable() {
                    @Override
                    public void run() {
                        synchronized (messages) {
                            // put it back!
                            messages.add(message);
View Full Code Here

    @Override
    public void deleteMessage(DeleteMessageRequest deleteMessageRequest) throws AmazonClientException {
        String receiptHandle = deleteMessageRequest.getReceiptHandle();
        if (inFlight.containsKey(receiptHandle)) {
            ScheduledFuture inFlightTask = inFlight.get(receiptHandle);
            inFlightTask.cancel(true);
        }
    }
View Full Code Here

      Configuration cfg = getCfg().expiration().wakeUpInterval(789L).build();

      ScheduledExecutorService mockService = mock(ScheduledExecutorService.class);
      em.initialize(mockService, "", cfg, null, null, null);

      ScheduledFuture mockFuture = mock(ScheduledFuture.class);
      when(mockService.scheduleWithFixedDelay(isA(EvictionManagerImpl.ScheduledTask.class), eq(789l),
                                                eq(789l), eq(TimeUnit.MILLISECONDS)))
            .thenReturn(mockFuture);
      em.start();
View Full Code Here

            JDKCallableJob callableJob = new JDKCallableJob( job,
                                                             ctx,
                                                             trigger,
                                                             jobHandle,
                                                             this.scheduler );
            ScheduledFuture future = schedule( date,
                                               callableJob,
                                               this.scheduler );
            jobHandle.setFuture( future );

            return jobHandle;
View Full Code Here

            JDKCallableJob callableJob = new JDKCallableJob( job,
                                                             ctx,
                                                             trigger,
                                                             jobHandle,
                                                             this.scheduler );
            ScheduledFuture future = schedule( date,
                                               callableJob,
                                               this.scheduler );
            jobHandle.setFuture( future );

            return jobHandle;
View Full Code Here

            V>> entries) {
        final ScheduledEntry<K, V> result = entries.remove(key);
        if (entries.isEmpty()) {
            scheduledEntries.remove(second);

            ScheduledFuture removed = scheduledTaskMap.remove(second);
            if (removed != null) {
                removed.cancel(false);
            }
        }
        return result;
    }
View Full Code Here

        return result;
    }

    private void schedule(final Integer second, final int delaySeconds) {
        EntryProcessorExecutor command = new EntryProcessorExecutor(second);
        ScheduledFuture scheduledFuture = scheduledExecutorService.schedule(command, delaySeconds, TimeUnit.SECONDS);
        scheduledTaskMap.put(second, scheduledFuture);
    }
View Full Code Here

    }

    @SuppressWarnings("unchecked")
    @Test
    public void scheduleAtFixedRate() {
        @SuppressWarnings("rawtypes")
        ScheduledFuture expected = mock(ScheduledFuture.class);
        Runnable task = mock(Runnable.class);
        long delay = 10L;
        long period = 20L;
        TimeUnit unit = TimeUnit.SECONDS;
View Full Code Here

TOP

Related Classes of java.util.concurrent.ScheduledFuture

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.