Package java.util.concurrent

Examples of java.util.concurrent.TimeUnit


        } catch (final IllegalArgumentException ex) {
            // success
        }

        try {
            final TimeUnit unit = null;
            new PassiveExpiringMap<String, String>(10L, unit);
            fail("constructor - exception should have been thrown.");
        } catch (final IllegalArgumentException ex) {
            // success
        }
View Full Code Here


    @Override
    protected AccessTimeoutDetails fromAnnotation(final AnnotationInstance annotationInstance, final PropertyReplacer propertyReplacer) {
        final long timeout = annotationInstance.value().asLong();
        AnnotationValue unitAnnVal = annotationInstance.value("unit");
        final TimeUnit unit = unitAnnVal != null ? TimeUnit.valueOf(unitAnnVal.asEnum()) : TimeUnit.MILLISECONDS;
        return new AccessTimeoutDetails(timeout, 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 EjbLogger.ROOT_LOGGER.concurrentAccessTimeoutException(invocationContext, time + unit.name());
        }
        try {
            // lock obtained. now proceed!
            return invocationContext.proceed();
        } finally {
View Full Code Here

    @Override
    protected StatefulTimeoutInfo fromAnnotation(final AnnotationInstance annotationInstance, final PropertyReplacer propertyReplacer) {
        final long value = annotationInstance.value().asLong();
        final AnnotationValue unitValue = annotationInstance.value("unit");
        final TimeUnit unit;
        if (unitValue != null) {
            unit = TimeUnit.valueOf(unitValue.asEnum());
        } else {
            unit = TimeUnit.MINUTES;
        }
View Full Code Here

        Entry<V> entry = this.entries.get(id);
        if ((entry != null) && entry.done()) {
            if (this.timeout != null) {
                long value = this.timeout.getValue();
                if (value > 0) {
                    TimeUnit unit = this.timeout.getTimeUnit();
                    RemoveTask task = new RemoveTask(id);
                    // Make sure the expiration future map insertion happens before map removal (during task execution).
                    synchronized (task) {
                        this.expirationFutures.put(id, this.executor.schedule(task, value, unit));
                    }
View Full Code Here

    private static Integer timeout(final ContainerTransactionMetaData containerTransaction) {
        final List<TransactionTimeoutMetaData> transactionTimeouts = containerTransaction.getAny(TransactionTimeoutMetaData.class);
        if (transactionTimeouts == null || transactionTimeouts.isEmpty())
            return null;
        final TransactionTimeoutMetaData transactionTimeout = transactionTimeouts.get(0);
        final TimeUnit unit = transactionTimeout.getUnit() == null ? TimeUnit.SECONDS : transactionTimeout.getUnit();
        return (int)unit.toSeconds(transactionTimeout.getTimeout());
    }
View Full Code Here

    @Override
    public boolean equals(Object object) {
        if ((object == null) || !(object instanceof Time)) return false;
        Time time = (Time) object;
        TimeUnit compareUnit = TimeUnit.MILLISECONDS;
        return compareUnit.convert(this.value, this.unit) == compareUnit.convert(time.value, time.unit);
    }
View Full Code Here

    @Override
    public boolean equals(Object object) {
        if ((object == null) || !(object instanceof Time)) return false;
        Time time = (Time) object;
        TimeUnit compareUnit = TimeUnit.MILLISECONDS;
        return compareUnit.convert(this.value, this.unit) == compareUnit.convert(time.value, time.unit);
    }
View Full Code Here

    @Test
    public void scheduleCallable() {
        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

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.