use of org.joda.time.Duration in project druid by druid-io.
the class RealtimePlumber method startPersistThread.
protected void startPersistThread() {
final Granularity segmentGranularity = schema.getGranularitySpec().getSegmentGranularity();
final Period windowPeriod = config.getWindowPeriod();
final DateTime truncatedNow = segmentGranularity.bucketStart(new DateTime());
final long windowMillis = windowPeriod.toStandardDuration().getMillis();
log.info("Expect to run at [%s]", new DateTime().plus(new Duration(System.currentTimeMillis(), segmentGranularity.increment(truncatedNow).getMillis() + windowMillis)));
ScheduledExecutors.scheduleAtFixedRate(scheduledExecutor, new Duration(System.currentTimeMillis(), segmentGranularity.increment(truncatedNow).getMillis() + windowMillis), new Duration(truncatedNow, segmentGranularity.increment(truncatedNow)), new ThreadRenamingCallable<ScheduledExecutors.Signal>(String.format("%s-overseer-%d", schema.getDataSource(), config.getShardSpec().getPartitionNum())) {
@Override
public ScheduledExecutors.Signal doCall() {
if (stopped) {
log.info("Stopping merge-n-push overseer thread");
return ScheduledExecutors.Signal.STOP;
}
mergeAndPush();
if (stopped) {
log.info("Stopping merge-n-push overseer thread");
return ScheduledExecutors.Signal.STOP;
} else {
return ScheduledExecutors.Signal.REPEAT;
}
}
});
}
use of org.joda.time.Duration in project druid by druid-io.
the class FileRequestLogger method start.
@LifecycleStart
public void start() {
try {
baseDir.mkdirs();
MutableDateTime mutableDateTime = new DateTime().toMutableDateTime();
mutableDateTime.setMillisOfDay(0);
synchronized (lock) {
currentDay = mutableDateTime.toDateTime();
fileWriter = getFileWriter();
}
long nextDay = currentDay.plusDays(1).getMillis();
Duration delay = new Duration(nextDay - new DateTime().getMillis());
ScheduledExecutors.scheduleWithFixedDelay(exec, delay, Duration.standardDays(1), new Callable<ScheduledExecutors.Signal>() {
@Override
public ScheduledExecutors.Signal call() {
try {
synchronized (lock) {
currentDay = currentDay.plusDays(1);
CloseQuietly.close(fileWriter);
fileWriter = getFileWriter();
}
} catch (Exception e) {
Throwables.propagate(e);
}
return ScheduledExecutors.Signal.REPEAT;
}
});
} catch (IOException e) {
Throwables.propagate(e);
}
}
use of org.joda.time.Duration in project druid by druid-io.
the class CoordinatorRuleManager method start.
@LifecycleStart
public void start() {
synchronized (lock) {
if (started) {
return;
}
this.exec = Execs.scheduledSingleThreaded("CoordinatorRuleManager-Exec--%d");
ScheduledExecutors.scheduleWithFixedDelay(exec, new Duration(0), config.get().getPollPeriod().toStandardDuration(), new Runnable() {
@Override
public void run() {
poll();
}
});
started = true;
}
}
use of org.joda.time.Duration in project druid by druid-io.
the class RetryPolicy method getAndIncrementRetryDelay.
public Duration getAndIncrementRetryDelay() {
if (hasExceededRetryThreshold()) {
return null;
}
Duration retVal = currRetryDelay;
currRetryDelay = new Duration(Math.min(currRetryDelay.getMillis() * 2, maxRetryDelay.getMillis()));
++retryCount;
return retVal;
}
use of org.joda.time.Duration in project opennms by OpenNMS.
the class DefaultProvisionService method createScheduleForNode.
private NodeScanSchedule createScheduleForNode(final OnmsNode node, final boolean force) {
Assert.notNull(node, "Node may not be null");
final String actualForeignSource = node.getForeignSource();
if (actualForeignSource == null && !isDiscoveryEnabled()) {
LOG.info("Not scheduling node {} to be scanned since it has a null foreignSource and handling of discovered nodes is disabled in provisiond", node);
return null;
}
final String effectiveForeignSource = actualForeignSource == null ? "default" : actualForeignSource;
try {
final ForeignSource fs = m_foreignSourceRepository.getForeignSource(effectiveForeignSource);
final Duration scanInterval = fs.getScanInterval();
if (scanInterval.getMillis() <= 0) {
LOG.debug("Node ({}/{}/{}) scan interval is zero, skipping schedule.", node.getId(), node.getForeignSource(), node.getForeignId());
return null;
}
Duration initialDelay = Duration.ZERO;
if (node.getLastCapsdPoll() != null && !force) {
final DateTime nextPoll = new DateTime(node.getLastCapsdPoll().getTime()).plus(scanInterval);
final DateTime now = new DateTime();
if (nextPoll.isAfter(now)) {
initialDelay = new Duration(now, nextPoll);
}
}
return new NodeScanSchedule(node.getId(), actualForeignSource, node.getForeignId(), node.getLocation(), initialDelay, scanInterval);
} catch (final ForeignSourceRepositoryException e) {
LOG.warn("unable to get foreign source '{}' from repository", effectiveForeignSource, e);
return null;
}
}
Aggregations