List of usage examples for org.joda.time Duration getMillis
public long getMillis()
From source file:net.solarnetwork.central.dras.mock.biz.MockDRASQueryBiz.java
License:Open Source License
@Override public List<? extends NodeDatum> getAggregatedDatum(Class<? extends NodeDatum> datumClass, DatumQueryCommand criteria) {//www.j a va 2 s . co m MutableDateTime mdt = new MutableDateTime(criteria.getStartDate()); Period period; switch (criteria.getAggregate()) { case Hour: period = Period.hours(1); break; case Day: period = Period.days(1); break; case Week: period = Period.weeks(1); break; case Month: period = Period.months(1); break; default: period = Period.minutes(1); } List<NodeDatum> results = new ArrayList<NodeDatum>(); do { NodeDatum datum = null; if (ConsumptionDatum.class.isAssignableFrom(datumClass)) { ReportingConsumptionDatum d = new ReportingConsumptionDatum(); d.setNodeId(criteria.getNodeId()); d.setCreated(mdt.toDateTime()); Duration dur = period.toDurationFrom(mdt); float hours = (float) ((double) dur.getMillis() / (double) (1000 * 60 * 60)); d.setWattHours(Double.valueOf(hours * consumptionWattHours)); datum = d; } else if (PowerDatum.class.isAssignableFrom(datumClass)) { ReportingPowerDatum d = new ReportingPowerDatum(); d.setNodeId(criteria.getNodeId()); d.setCreated(mdt.toDateTime()); Duration dur = period.toDurationFrom(mdt); float hours = (float) ((double) dur.getMillis() / (double) (1000 * 60 * 60)); d.setWattHours(Double.valueOf(hours * generationWattHours)); datum = d; } if (datum != null) { results.add(datum); } mdt.add(period); } while (mdt.isBefore(criteria.getEndDate())); return results; }
From source file:no.digipost.cache.inmemory.CacheConfig.java
License:Apache License
public static CacheConfig expireAfterAccess(final Duration expiryTime) { return new CacheConfig() { @Override/*from w ww. j a v a 2 s . c o m*/ public CacheBuilder<Object, Object> configure(CacheBuilder<Object, Object> builder) { LOG.info("Expires values {} ms after last access", expiryTime.getMillis()); return builder.expireAfterAccess(expiryTime.getMillis(), TimeUnit.MILLISECONDS); } }; }
From source file:no.digipost.cache.inmemory.CacheConfig.java
License:Apache License
public static CacheConfig expireAfterWrite(final Duration expiryTime) { return new CacheConfig() { @Override/* w w w .j a v a 2 s. c o m*/ public CacheBuilder<Object, Object> configure(CacheBuilder<Object, Object> builder) { LOG.info("Expire values {} ms after they are written to the cache", expiryTime.getMillis()); return builder.expireAfterWrite(expiryTime.getMillis(), TimeUnit.MILLISECONDS); } }; }
From source file:oncue.backingstore.RedisBackingStore.java
License:Apache License
@Override public int cleanupJobs(boolean includeFailedJobs, Duration expirationAge) { int cleanedJobsCount = 0; for (Job completedJob : getCompletedJobs()) { DateTime expirationThreshold = DateTime.now().minus(expirationAge.getMillis()); boolean isExpired = completedJob.getCompletedAt().isBefore(expirationThreshold.toInstant()); if (isExpired) { removeCompletedJobById(completedJob.getId()); cleanedJobsCount++;/* ww w . j a v a 2s . com*/ } } if (!includeFailedJobs) { return cleanedJobsCount; } for (Job failedJob : getFailedJobs()) { if (failedJob.getCompletedAt() == null) { log.error( "Found a failed job with no completion time. Setting completion time to now and defering to next clean up. (" + failedJob.toString() + ")"); failedJob.setCompletedAt(DateTime.now()); persistJobFailure(failedJob); continue; } DateTime expirationThreshold = DateTime.now().minus(expirationAge.getMillis()); boolean isExpired = failedJob.getCompletedAt().isBefore(expirationThreshold.toInstant()); if (isExpired) { removeFailedJobById(failedJob.getId()); cleanedJobsCount++; } } return cleanedJobsCount; }
From source file:org.apache.apex.malhar.lib.state.managed.StateTracker.java
License:Apache License
@SuppressWarnings("SynchronizationOnLocalVariableOrMethodParameter") @Override//from w ww .j a v a2 s . c o m public void run() { synchronized (managedStateImpl.commitLock) { //freeing of state needs to be stopped during commit as commit results in transferring data to a state which // can be freed up as well. long bytesSum = 0; for (Bucket bucket : managedStateImpl.buckets.values()) { if (bucket != null) { bytesSum += bucket.getSizeInBytes(); } } if (bytesSum > managedStateImpl.getMaxMemorySize()) { Duration duration = managedStateImpl.getDurationPreventingFreeingSpace(); long durationMillis = 0; if (duration != null) { durationMillis = duration.getMillis(); } synchronized (bucketLastAccess) { long now = System.currentTimeMillis(); for (Iterator<Map.Entry<Long, MutableLong>> iterator = bucketLastAccess.entrySet() .iterator(); bytesSum > managedStateImpl.getMaxMemorySize() && iterator.hasNext();) { Map.Entry<Long, MutableLong> entry = iterator.next(); if (now - entry.getValue().longValue() < durationMillis) { break; } long bucketId = entry.getKey(); Bucket bucket = managedStateImpl.getBucket(bucketId); if (bucket != null) { synchronized (bucket) { long sizeFreed; try { sizeFreed = bucket.freeMemory( managedStateImpl.getCheckpointManager().getLastTransferredWindow()); } catch (IOException e) { managedStateImpl.throwable.set(e); throw new RuntimeException("freeing " + bucketId, e); } bytesSum -= sizeFreed; } if (bucket.getSizeInBytes() == 0) { iterator.remove(); } } } } } } }
From source file:org.apache.apex.malhar.lib.window.impl.AbstractWindowedOperator.java
License:Apache License
@Override public void setAllowedLateness(Duration allowedLateness) { this.allowedLatenessMillis = allowedLateness.getMillis(); }
From source file:org.apache.beam.runners.apex.ApexRunnerResult.java
License:Apache License
@Override @Nullable//from w w w .ja v a2 s.com public State waitUntilFinish(@Nullable Duration duration) { long timeout = (duration == null || duration.getMillis() < 1) ? Long.MAX_VALUE : System.currentTimeMillis() + duration.getMillis(); try { while (!apexApp.isFinished() && System.currentTimeMillis() < timeout) { if (ApexRunner.ASSERTION_ERROR.get() != null) { throw ApexRunner.ASSERTION_ERROR.get(); } Thread.sleep(500); } if (apexApp.isFinished()) { cleanupOnCancelOrFinish(); return State.DONE; } return null; } catch (InterruptedException e) { throw new RuntimeException(e); } }
From source file:org.apache.beam.runners.dataflow.worker.ReaderCache.java
License:Apache License
/** Cache reader for {@code cacheDuration}. */ ReaderCache(Duration cacheDuration) { this.cache = CacheBuilder.newBuilder().expireAfterWrite(cacheDuration.getMillis(), TimeUnit.MILLISECONDS) .removalListener((RemovalNotification<KV<String, ByteString>, CacheEntry> notification) -> { if (notification.getCause() != RemovalCause.EXPLICIT) { LOG.info("Closing idle reader for {}", keyToString(notification.getKey())); closeReader(notification.getKey(), notification.getValue()); }/*from w w w. j a va 2s .co m*/ }).build(); }
From source file:org.apache.beam.runners.jet.JetPipelineResult.java
License:Apache License
@Override public State waitUntilFinish(Duration duration) { if (terminalState != null) { return terminalState; }//from ww w . j a va 2 s. co m try { completionFuture.get(duration.getMillis(), TimeUnit.MILLISECONDS); return State.DONE; } catch (InterruptedException | TimeoutException e) { return getState(); // job should be RUNNING or STOPPED } catch (ExecutionException e) { throw new CompletionException(e.getCause()); } }
From source file:org.apache.beam.runners.reference.JobServicePipelineResult.java
License:Apache License
@Nullable @Override/* w w w.j a v a 2 s .c o m*/ public State waitUntilFinish(Duration duration) { if (duration.compareTo(Duration.millis(1)) < 1) { // Equivalent to infinite timeout. return waitUntilFinish(); } else { CompletableFuture<State> result = CompletableFuture.supplyAsync(this::waitUntilFinish); try { return result.get(duration.getMillis(), TimeUnit.MILLISECONDS); } catch (TimeoutException e) { // Null result indicates a timeout. return null; } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new RuntimeException(e); } catch (ExecutionException e) { throw new RuntimeException(e); } } }