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);
}
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;
}
}
}
}
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();
}
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;
}
};
}
}
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);
}
}
Aggregations