Package java.util.concurrent

Examples of java.util.concurrent.TimeUnit


    }

    @Test(expected = RuntimeException.class)
    public void applyDelayHandlesException() throws InterruptedException {
        // given
        TimeUnit timeUnit = mock(TimeUnit.class);
        doThrow(new InterruptedException("TEST EXCEPTION")).when(timeUnit).sleep(10);

        // when
        new HttpResponse().withDelay(new Delay(timeUnit, 10)).applyDelay();
    }
View Full Code Here


            } else {
                throw new ServletException("Couldn't find a MetricRegistry instance.");
            }
        }

        final TimeUnit rateUnit = parseTimeUnit(context.getInitParameter(RATE_UNIT),
                                                TimeUnit.SECONDS);
        final TimeUnit durationUnit = parseTimeUnit(context.getInitParameter(DURATION_UNIT),
                                                    TimeUnit.SECONDS);
        final boolean showSamples = Boolean.parseBoolean(context.getInitParameter(SHOW_SAMPLES));
        MetricFilter filter = (MetricFilter) context.getAttribute(METRIC_FILTER);
        if (filter == null) {
          filter = MetricFilter.ALL;
View Full Code Here

    protected void waitUntilCompleted() {
        while (!completed.get()) {
            try {
                if (duration > 0) {
                    TimeUnit unit = getTimeUnit();
                    LOG.info("Waiting for: " + duration + " " + unit);
                    latch.await(duration, unit);
                    completed.set(true);
                } else {
                    latch.await();
View Full Code Here

    protected void waitUntilCompleted() {
        while (!completed.get()) {
            try {
                if (duration > 0) {
                    TimeUnit unit = getTimeUnit();
                    LOG.info("Waiting for: " + duration + " " + unit);
                    latch.await(duration, unit);
                    completed.set(true);
                } else {
                    latch.await();
View Full Code Here

   * Helper to create an invoker pool
   */
  protected static ExecutorService createInvokerPool(Args options) {
    int workerThreads = options.workerThreads;
    int stopTimeoutVal = options.stopTimeoutVal;
    TimeUnit stopTimeoutUnit = options.stopTimeoutUnit;

    LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>();
    ExecutorService invoker = new ThreadPoolExecutor(workerThreads,
      workerThreads, stopTimeoutVal, stopTimeoutUnit, queue);

View Full Code Here

                throw new IllegalArgumentException
                    ("Duration argument has extra characters after unit: " +
                     property);
            }
            try {
                final TimeUnit unit = TimeUnit.valueOf(unitName);
                millis = TimeUnit.MILLISECONDS.convert(time, unit);
            } catch (IllegalArgumentException e) {
                try {
                    final IEEETimeUnit unit = IEEETimeUnit.valueOf(unitName);
                    millis = unit.toMillis(time);
                } catch (IllegalArgumentException e2) {
                    throw new IllegalArgumentException
                        ("Duration argument has unknown unit name: " +
                         property);
                }
View Full Code Here

    public void scheduleCallable() {
        @SuppressWarnings("unchecked")
        ScheduledFuture<Object> expected = mock(ScheduledFuture.class);
        Task task = new Task();
        long delay = 10L;
        TimeUnit unit = TimeUnit.SECONDS;

        when(this.executor.schedule(task, delay, unit)).thenReturn(expected);

        ScheduledFuture<Object> result = this.subject.schedule(task, delay, unit);
View Full Code Here

        @SuppressWarnings("rawtypes")
        ScheduledFuture expected = mock(ScheduledFuture.class);
        Runnable task = mock(Runnable.class);
        long delay = 10L;
        long period = 20L;
        TimeUnit unit = TimeUnit.SECONDS;

        when(this.executor.scheduleAtFixedRate(task, delay, period, unit)).thenReturn(expected);

        ScheduledFuture<?> result = this.subject.scheduleAtFixedRate(task, delay, period, unit);
View Full Code Here

        @SuppressWarnings("rawtypes")
        ScheduledFuture expected = mock(ScheduledFuture.class);
        Runnable task = mock(Runnable.class);
        long delay = 10L;
        long period = 20L;
        TimeUnit unit = TimeUnit.SECONDS;

        when(this.executor.scheduleWithFixedDelay(task, delay, period, unit)).thenReturn(expected);

        ScheduledFuture<?> result = this.subject.scheduleWithFixedDelay(task, delay, period, unit);
View Full Code Here

        Lock lock = getLock(lockableComponent, invokedMethod);
        // the default access timeout (will be used in the absence of any explicit access timeout value for the invoked method)
        AccessTimeoutDetails defaultAccessTimeout = lockableComponent.getDefaultAccessTimeout();
        // set to the default values
        long time = defaultAccessTimeout.getValue();
        TimeUnit unit = defaultAccessTimeout.getTimeUnit();

        AccessTimeoutDetails accessTimeoutOnMethod = lockableComponent.getAccessTimeout(invokedMethod);
        if (accessTimeoutOnMethod != null) {
            if (accessTimeoutOnMethod.getValue() < 0) {
                // for any negative value of timeout, we just default to max timeout val and max timeout unit.
                // violation of spec! But we don't want to wait indefinitely.

                ROOT_LOGGER.debug("Ignoring a negative @AccessTimeout value: " + accessTimeoutOnMethod.getValue() + " and timeout unit: "
                        + accessTimeoutOnMethod.getTimeUnit().name() + ". Will default to timeout value: " + defaultAccessTimeout.getValue()
                        + " and timeout unit: " + defaultAccessTimeout.getTimeUnit().name());
            } else {
                // use the explicit access timeout values specified on the method
                time = accessTimeoutOnMethod.getValue();
                unit = accessTimeoutOnMethod.getTimeUnit();
            }
        }
        // try getting the lock
        boolean success = lock.tryLock(time, unit);
        if (!success) {
            throw MESSAGES.concurrentAccessTimeoutException(invocationContext,time + unit.name());
        }
        try {
            // lock obtained. now proceed!
            return invocationContext.proceed();
        } finally {
View Full Code Here

TOP

Related Classes of java.util.concurrent.TimeUnit

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.