List of usage examples for org.joda.time Duration Duration
public Duration(ReadableInstant start, ReadableInstant end)
From source file:com.heisenberg.impl.instance.ActivityInstanceImpl.java
License:Apache License
public void setEnd(LocalDateTime end) { this.end = end; if (start != null && end != null) { this.duration = new Duration(start.toDateTime(), end.toDateTime()).getMillis(); }//from w w w. j a v a 2 s . c o m if (updates != null) { updates.isEndChanged = true; propagateActivityInstanceChange(parent); } }
From source file:com.heisenberg.impl.instance.WorkflowInstanceImpl.java
License:Apache License
public void setEnd(LocalDateTime end) { this.end = end; if (start != null && end != null) { this.duration = new Duration(start.toDateTime(), end.toDateTime()).getMillis(); }/*from w ww .j a v a 2s .co m*/ if (updates != null) { getUpdates().isEndChanged = true; } }
From source file:com.indeed.imhotep.web.QueryServlet.java
License:Apache License
private void logSelectStatementData(SelectStatement selectStatement, SelectExecutionStats selectExecutionStats, QueryLogEntry logEntry) {//w ww .j a v a 2s.c o m final FromClause from = selectStatement.from; final GroupByClause groupBy = selectStatement.groupBy; final SelectClause select = selectStatement.select; if (from != null) { logEntry.setProperty("dataset", from.getDataset()); if (from.getStart() != null && from.getEnd() != null) { logEntry.setProperty("days", new Duration(from.getStart(), from.getEnd()).getStandardDays()); } } final int selectCount; if (select != null && select.getProjections() != null) { selectCount = select.getProjections().size(); } else { selectCount = 0; } logEntry.setProperty("selectcnt", selectCount); final int groupByCount; if (groupBy != null && groupBy.groupings != null) { groupByCount = groupBy.groupings.size(); } else { groupByCount = 0; } logEntry.setProperty("groupbycnt", groupByCount); if (selectExecutionStats != null) { logEntry.setProperty("cached", selectExecutionStats.cached ? "1" : "0"); logEntry.setProperty("rows", selectExecutionStats.rowsWritten); logEntry.setProperty("disk", selectExecutionStats.overflowedToDisk ? "1" : "0"); logEntry.setProperty("hash", selectExecutionStats.hashForCaching); logEntry.setProperty("head", selectExecutionStats.headOnly ? "1" : "0"); } }
From source file:com.josecalles.tistiq.task.StatCalculator.java
License:Apache License
public long timeSinceLastMessage(RealmList<TextMessage> messages) { long time = messages.get(messages.size() - 1).getDateReceived(); DateTime lastMessageTime = new DateTime(time); DateTime currentTime = new DateTime(); Duration duration = new Duration(lastMessageTime, currentTime); return duration.getMillis(); }
From source file:com.linkedin.pinot.controller.helix.core.retention.strategy.TimeRetentionStrategy.java
License:Apache License
@Override public boolean isPurgeable(SegmentZKMetadata segmentZKMetadata) { if (_retentionDuration == null || _retentionDuration.getMillis() <= 0) { return false; }//from w ww. j a v a 2 s . c o m try { TimeUnit segmentTimeUnit = segmentZKMetadata.getTimeUnit(); if (segmentTimeUnit == null) { return false; } long endsMills = segmentTimeUnit.toMillis(segmentZKMetadata.getEndTime()); Duration segmentTimeUntilNow = new Duration(endsMills, System.currentTimeMillis()); if (_retentionDuration.isShorterThan(segmentTimeUntilNow)) { return true; } } catch (Exception e) { LOGGER.warn("Caught exception while checking if a segment is purgeable", e); return false; } return false; }
From source file:com.marand.thinkmed.medications.AdministrationStatusEnum.java
License:Open Source License
private static long getOffsetInMinutes(final DateTime planned, final DateTime compare) { return new Duration(planned, compare).getStandardMinutes(); }
From source file:com.mastfrog.acteur.util.CacheControl.java
License:Open Source License
public boolean isExpired() { if (contains(CacheControlTypes.no_cache) || contains(CacheControlTypes.no_store)) { return true; }/*from w w w . j av a2 s . c o m*/ Long maxAgeSeconds = get(CacheControlTypes.max_age); if (maxAgeSeconds != null) { Duration dur = new Duration(new DateTime(), creationTime); Duration target = Duration.standardSeconds(maxAgeSeconds); if (dur.isLongerThan(target)) { return true; } } return false; }
From source file:com.mastfrog.netty.http.client.RequestInfo.java
License:Open Source License
Duration age() {
return new Duration(startTime, DateTime.now());
}
From source file:com.metamx.druid.indexing.coordinator.scaling.ResourceManagementScheduler.java
License:Open Source License
@LifecycleStart public void start() { synchronized (lock) { if (started) { return; }//from w w w . java 2 s .co m log.info("Started Resource Management Scheduler"); ScheduledExecutors.scheduleAtFixedRate(exec, config.getProvisionResourcesDuration(), new Runnable() { @Override public void run() { resourceManagementStrategy.doProvision(taskRunner.getPendingTasks(), taskRunner.getWorkers()); } }); // Schedule termination of worker nodes periodically Period period = new Period(config.getTerminateResourcesDuration()); PeriodGranularity granularity = new PeriodGranularity(period, config.getTerminateResourcesOriginDateTime(), null); final long startTime = granularity.next(granularity.truncate(new DateTime().getMillis())); ScheduledExecutors.scheduleAtFixedRate(exec, new Duration(System.currentTimeMillis(), startTime), config.getTerminateResourcesDuration(), new Runnable() { @Override public void run() { resourceManagementStrategy.doTerminate(taskRunner.getPendingTasks(), taskRunner.getWorkers()); } }); started = true; } }
From source file:com.metamx.druid.indexing.coordinator.scaling.SimpleResourceManagementStrategy.java
License:Open Source License
@Override public boolean doProvision(Collection<RemoteTaskRunnerWorkItem> pendingTasks, Collection<ZkWorker> zkWorkers) { final WorkerSetupData workerSetupData = workerSetupdDataRef.get(); final String minVersion = workerSetupData.getMinVersion() == null ? config.getWorkerVersion() : workerSetupData.getMinVersion(); int maxNumWorkers = workerSetupData.getMaxNumWorkers(); int currValidWorkers = 0; for (ZkWorker zkWorker : zkWorkers) { if (zkWorker.isValidVersion(minVersion)) { currValidWorkers++;//from w w w .j ava 2s . c o m } } if (currValidWorkers >= maxNumWorkers) { log.debug("Cannot scale anymore. Num workers = %d, Max num workers = %d", zkWorkers.size(), workerSetupdDataRef.get().getMaxNumWorkers()); return false; } List<String> workerNodeIds = autoScalingStrategy .ipToIdLookup(Lists.newArrayList(Iterables.transform(zkWorkers, new Function<ZkWorker, String>() { @Override public String apply(ZkWorker input) { return input.getWorker().getIp(); } }))); currentlyProvisioning.removeAll(workerNodeIds); boolean nothingProvisioning = currentlyProvisioning.isEmpty(); if (nothingProvisioning) { if (hasTaskPendingBeyondThreshold(pendingTasks)) { AutoScalingData provisioned = autoScalingStrategy.provision(); if (provisioned != null) { currentlyProvisioning.addAll(provisioned.getNodeIds()); lastProvisionTime = new DateTime(); scalingStats.addProvisionEvent(provisioned); return true; } } } else { Duration durSinceLastProvision = new Duration(lastProvisionTime, new DateTime()); log.info( "%s still provisioning. Wait for all provisioned nodes to complete before requesting new worker. Current wait time: %s", currentlyProvisioning, durSinceLastProvision); if (durSinceLastProvision.isLongerThan(config.getMaxScalingDuration())) { log.makeAlert("Worker node provisioning taking too long!") .addData("millisSinceLastProvision", durSinceLastProvision.getMillis()) .addData("provisioningCount", currentlyProvisioning.size()).emit(); List<String> nodeIps = autoScalingStrategy.idToIpLookup(Lists.newArrayList(currentlyProvisioning)); autoScalingStrategy.terminate(nodeIps); currentlyProvisioning.clear(); } } return false; }