Search in sources :

Example 46 with TimeUnit

use of java.util.concurrent.TimeUnit in project killbill by killbill.

the class DefaultBroadcastService method start.

@LifecycleHandlerType(LifecycleHandlerType.LifecycleLevel.START_SERVICE)
public void start() {
    final TimeUnit pendingRateUnit = broadcastConfig.getBroadcastServiceRunningRate().getUnit();
    final long pendingPeriod = broadcastConfig.getBroadcastServiceRunningRate().getPeriod();
    broadcastExecutor.scheduleAtFixedRate(new BroadcastServiceRunnable(this, broadcastDao, eventBus), pendingPeriod, pendingPeriod, pendingRateUnit);
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) LifecycleHandlerType(org.killbill.billing.platform.api.LifecycleHandlerType)

Example 47 with TimeUnit

use of java.util.concurrent.TimeUnit in project torodb by torodb.

the class ExecutorTorodbService method shutDown.

@Override
protected void shutDown() throws Exception {
    if (executorService != null) {
        long timeout = 10;
        TimeUnit timeUnit = TimeUnit.SECONDS;
        Duration waitingDuration = Duration.ZERO;
        executorService.shutdown();
        while (!executorService.awaitTermination(timeout, timeUnit)) {
            waitingDuration = waitingDuration.plusSeconds(timeout * timeUnit.toSeconds(1));
            if (ignoreTermination(waitingDuration)) {
                break;
            }
        }
    }
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) Duration(java.time.Duration)

Example 48 with TimeUnit

use of java.util.concurrent.TimeUnit in project HikariCP by brettwooldridge.

the class ClockSource method elapsedDisplayString0.

default default String elapsedDisplayString0(long startTime, long endTime) {
    long elapsedNanos = elapsedNanos0(startTime, endTime);
    StringBuilder sb = new StringBuilder(elapsedNanos < 0 ? "-" : "");
    elapsedNanos = Math.abs(elapsedNanos);
    for (TimeUnit unit : TIMEUNITS_DESCENDING) {
        long converted = unit.convert(elapsedNanos, NANOSECONDS);
        if (converted > 0) {
            sb.append(converted).append(TIMEUNIT_DISPLAY_VALUES[unit.ordinal()]);
            elapsedNanos -= NANOSECONDS.convert(converted, unit);
        }
    }
    return sb.toString();
}
Also used : TimeUnit(java.util.concurrent.TimeUnit)

Example 49 with TimeUnit

use of java.util.concurrent.TimeUnit in project japid42 by branaway.

the class Mail method sendMessage.

/**
	 * Send a JavaMail message
	 * 
	 * @param msg
	 *            An Email message
	 */
public static Future<Boolean> sendMessage(final Email msg) {
    if (asynchronousSend) {
        return executor.submit(new Callable<Boolean>() {

            public Boolean call() {
                try {
                    msg.setSentDate(new Date());
                    msg.send();
                    return true;
                } catch (Throwable e) {
                    MailException me = new MailException("Error while sending email", e);
                    Logger.error("The email has not been sent", me);
                    return false;
                }
            }
        });
    } else {
        final StringBuffer result = new StringBuffer();
        try {
            msg.setSentDate(new Date());
            msg.send();
        } catch (Throwable e) {
            MailException me = new MailException("Error while sending email", e);
            Logger.error("The email has not been sent", me);
            result.append("oops");
        }
        return new Future<Boolean>() {

            public boolean cancel(boolean mayInterruptIfRunning) {
                return false;
            }

            public boolean isCancelled() {
                return false;
            }

            public boolean isDone() {
                return true;
            }

            public Boolean get() throws InterruptedException, ExecutionException {
                return result.length() == 0;
            }

            public Boolean get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
                return result.length() == 0;
            }
        };
    }
}
Also used : Future(java.util.concurrent.Future) TimeUnit(java.util.concurrent.TimeUnit) MailException(cn.bran.play.exceptions.MailException) Date(java.util.Date)

Example 50 with TimeUnit

use of java.util.concurrent.TimeUnit in project japid42 by branaway.

the class Mail method send.

/**
	 * Send an email
	 */
public static Future<Boolean> send(Email email) {
    try {
        email = buildMessage(email);
        // has to use this since mail.smtp is a tree in play2
        String string = getConfig("mail.smtp.host");
        if (string != null)
            if (string.equals("mock") && Play.isDev()) {
                Mock.send(email);
                return new Future<Boolean>() {

                    public boolean cancel(boolean mayInterruptIfRunning) {
                        return false;
                    }

                    public boolean isCancelled() {
                        return false;
                    }

                    public boolean isDone() {
                        return true;
                    }

                    public Boolean get() throws InterruptedException, ExecutionException {
                        return true;
                    }

                    public Boolean get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
                        return true;
                    }
                };
            }
        email.setMailSession(getSession());
        return sendMessage(email);
    } catch (EmailException ex) {
        throw new MailException("Cannot send email", ex);
    }
}
Also used : EmailException(org.apache.commons.mail.EmailException) TimeUnit(java.util.concurrent.TimeUnit) MailException(cn.bran.play.exceptions.MailException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

TimeUnit (java.util.concurrent.TimeUnit)190 Test (org.junit.Test)28 ExecutionException (java.util.concurrent.ExecutionException)16 IOException (java.io.IOException)11 TimeoutException (java.util.concurrent.TimeoutException)11 Future (java.util.concurrent.Future)10 HashMap (java.util.HashMap)7 TimeSpec (com.linkedin.thirdeye.api.TimeSpec)6 ArrayList (java.util.ArrayList)6 TimeValue (org.elasticsearch.common.unit.TimeValue)6 DataType (com.linkedin.pinot.common.data.FieldSpec.DataType)5 File (java.io.File)5 HashSet (java.util.HashSet)5 Matcher (java.util.regex.Matcher)5 WaitUntilGatewaySenderFlushedCoordinatorJUnitTest (org.apache.geode.internal.cache.wan.WaitUntilGatewaySenderFlushedCoordinatorJUnitTest)5 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)5 TimeGranularity (com.linkedin.thirdeye.api.TimeGranularity)4 GwtIncompatible (com.google.common.annotations.GwtIncompatible)3 RestException (com.linkedin.r2.message.rest.RestException)3 Map (java.util.Map)3