List of usage examples for org.joda.time DateTime plusMillis
public DateTime plusMillis(int millis)
From source file:com.almende.eve.agent.SchedulingAgent.java
License:Apache License
public void onReady() { DateTime now = DateTime.now(); super.onReady(); LOG.warning("OnReady called!"); schedule("repeatTest", null, now.plusMillis(400)); schedule("repeatTest", null, now.plusMillis(400)); schedule("repeatTest", null, now.plusMillis(400)); schedule("repeatTest", null, now.plusMillis(400)); }
From source file:com.eucalyptus.objectstorage.pipeline.auth.S3Authentication.java
License:Open Source License
static void assertDateNotSkewed(final Date date) throws RequestTimeTooSkewedException { DateTime currentTime = DateTime.now(); DateTime dt = new DateTime(date); if (dt.isBefore(currentTime.minusMillis((int) ObjectStorageProperties.EXPIRATION_LIMIT))) throw new RequestTimeTooSkewedException(); if (dt.isAfter(currentTime.plusMillis((int) ObjectStorageProperties.EXPIRATION_LIMIT))) throw new RequestTimeTooSkewedException(); }
From source file:com.google.android.apps.paco.NonESMSignalGenerator.java
License:Open Source License
private SignalTimeHolder getNextTimeForOffsetType(SignalTime signalTime, List<SignalTimeHolder> previousTimes, Long experimentId) {//from w w w.java 2 s. co m if (previousTimes.size() == 0) { return createNullSignalTimeHolder(signalTime); // we don't allow offset types as the first signalTime } SignalTimeHolder previousTimePair = previousTimes.get(previousTimes.size() - 1); DateTime basis = computeBasisTimeForOffsetType(signalTime, previousTimePair, experimentId); if (basis != null) { DateTime chosenTime = basis.plusMillis(signalTime.getOffsetTimeMillis()); return new SignalTimeHolder(null, null, chosenTime, signalTime); } else { return createNullSignalTimeHolder(signalTime); } }
From source file:com.google.enterprise.adaptor.SamlIdentityProvider.java
License:Open Source License
private Response createResponse(SAMLMessageContext<AuthnRequest, Response, NameID> context, AuthnIdentity identity) {//from w w w. j av a2 s. c o m String recipient = context.getPeerEntityEndpoint().getLocation(); String audience = context.getInboundMessageIssuer(); String inResponseTo = context.getInboundSAMLMessage().getID(); String issuer = context.getLocalEntityId(); DateTime now = new DateTime(); // Expiration time in the future. DateTime expirationTime = now.plusMillis(expirationMillis); if (identity == null) { return makeResponse(issuer, now, makeStatus(makeStatusCode(StatusCode.RESPONDER_URI), makeStatusMessage("Could not authenticate user")), inResponseTo); } Attribute groupsAttribute = makeAttribute("member-of"); Iterable<GroupPrincipal> groups = identity.getGroups(); if (groups == null) { groups = Collections.emptySet(); } for (GroupPrincipal group : groups) { String name = group.getName(); groupsAttribute.getAttributeValues().add(makeAttributeValue(name)); } return makeResponse(issuer, now, makeSuccessfulStatus(), inResponseTo, makeAssertion(issuer, now, makeSubject(identity.getUser().getName(), makeSubjectConfirmation(OpenSamlUtil.BEARER_METHOD, makeSubjectConfirmationData(recipient, expirationTime, inResponseTo))), makeConditions(now, expirationTime, makeAudienceRestriction(audience)), makeAuthnStatement(now, AuthnContext.IP_PASSWORD_AUTHN_CTX), makeAttributeStatement(groupsAttribute))); }
From source file:com.ning.arecibo.collector.persistent.TimelineHostEventAccumulator.java
License:Apache License
public TimelineHostEventAccumulator(final TimelineDAO dao, final TimelineCoder timelineCoder, final SampleCoder sampleCoder, final BackgroundDBChunkWriter backgroundWriter, final int hostId, final int eventCategoryId, final DateTime firstSampleTime, Integer timelineLengthMillis) { this.timelineLengthMillis = timelineLengthMillis; this.backgroundWriter = backgroundWriter; this.timelineCoder = timelineCoder; this.sampleCoder = sampleCoder; this.hostId = hostId; this.eventCategoryId = eventCategoryId; // Set the end-of-chunk time by tossing a random number, to evenly distribute the db writeback load. this.chunkEndTime = timelineLengthMillis != null ? firstSampleTime.plusMillis(rand.nextInt(timelineLengthMillis)) : null;/*from w ww . j a v a 2s . c o m*/ }
From source file:com.ning.arecibo.collector.persistent.TimelineHostEventAccumulator.java
License:Apache License
@SuppressWarnings("unchecked") // TODO - we can probably do better than synchronize the whole method public synchronized void addHostSamples(final HostSamplesForTimestamp samples) { final DateTime timestamp = samples.getTimestamp(); if (chunkEndTime != null && chunkEndTime.isBefore(timestamp)) { extractAndQueueTimelineChunks(); startTime = timestamp;// w w w. j a v a2 s .c o m chunkEndTime = timestamp.plusMillis(timelineLengthMillis); } if (startTime == null) { startTime = timestamp; } if (endTime == null) { endTime = timestamp; } else if (!timestamp.isAfter(endTime)) { log.warn("Adding samples for host {}, timestamp {} is not after the end time {}; ignored", new Object[] { hostId, dateFormatter.print(timestamp), dateFormatter.print(endTime) }); return; } sampleSequenceNumber++; latestSampleAddTime = new DateTime(); for (final Map.Entry<Integer, ScalarSample> entry : samples.getSamples().entrySet()) { final Integer sampleKindId = entry.getKey(); final SampleSequenceNumber counter = sampleKindIdCounters.get(sampleKindId); if (counter != null) { counter.setSequenceNumber(sampleSequenceNumber); } else { sampleKindIdCounters.put(sampleKindId, new SampleSequenceNumber(sampleSequenceNumber)); } final ScalarSample sample = entry.getValue(); TimelineChunkAccumulator timeline = timelines.get(sampleKindId); if (timeline == null) { timeline = new TimelineChunkAccumulator(hostId, sampleKindId, sampleCoder); if (sampleCount > 0) { addPlaceholders(timeline, sampleCount); } timelines.put(sampleKindId, timeline); } final ScalarSample compressedSample = sampleCoder.compressSample(sample); timeline.addSample(compressedSample); } for (Map.Entry<Integer, SampleSequenceNumber> entry : sampleKindIdCounters.entrySet()) { final SampleSequenceNumber counter = entry.getValue(); if (counter.getSequenceNumber() < sampleSequenceNumber) { counter.setSequenceNumber(sampleSequenceNumber); final int sampleKindId = entry.getKey(); final TimelineChunkAccumulator timeline = timelines.get(sampleKindId); timeline.addSample(nullSample); } } // Now we can update the state endTime = timestamp; sampleCount++; times.add(timestamp); if (checkEveryAccess) { checkSampleCounts(sampleCount); } }
From source file:com.ning.billing.meter.timeline.TimelineSourceEventAccumulator.java
License:Apache License
public TimelineSourceEventAccumulator(final TimelineDao dao, final TimelineCoder timelineCoder, final SampleCoder sampleCoder, final BackgroundDBChunkWriter backgroundWriter, final int sourceId, final int eventCategoryId, final DateTime firstSampleTime, final Integer timelineLengthMillis) { this.timelineLengthMillis = timelineLengthMillis; this.backgroundWriter = backgroundWriter; this.timelineCoder = timelineCoder; this.sampleCoder = sampleCoder; this.sourceId = sourceId; this.eventCategoryId = eventCategoryId; // Set the end-of-chunk time by tossing a random number, to evenly distribute the db writeback load. this.chunkEndTime = timelineLengthMillis != null ? firstSampleTime.plusMillis(rand.nextInt(timelineLengthMillis)) : null;/* w w w . j ava2s . c o m*/ }
From source file:com.ning.billing.meter.timeline.TimelineSourceEventAccumulator.java
License:Apache License
@SuppressWarnings("unchecked") // TODO - we can probably do better than synchronize the whole method public synchronized void addSourceSamples(final SourceSamplesForTimestamp samples) { final DateTime timestamp = samples.getTimestamp(); if (chunkEndTime != null && chunkEndTime.isBefore(timestamp)) { extractAndQueueTimelineChunks(); startTime = timestamp;/*from w ww . j a v a2s .c om*/ chunkEndTime = timestamp.plusMillis(timelineLengthMillis); } if (startTime == null) { startTime = timestamp; } if (endTime == null) { endTime = timestamp; } else if (timestamp.isBefore(endTime)) { // Note: we allow multiple events at the same time // TODO Do we really want that? log.warn("Adding samples for source {}, timestamp {} is before the end time {}; ignored", new Object[] { sourceId, dateFormatter.print(timestamp), dateFormatter.print(endTime) }); return; } sampleSequenceNumber++; latestSampleAddTime = new DateTime(); for (final Map.Entry<Integer, ScalarSample> entry : samples.getSamples().entrySet()) { final Integer metricId = entry.getKey(); final SampleSequenceNumber counter = metricIdCounters.get(metricId); if (counter != null) { counter.setSequenceNumber(sampleSequenceNumber); } else { metricIdCounters.put(metricId, new SampleSequenceNumber(sampleSequenceNumber)); } final ScalarSample sample = entry.getValue(); TimelineChunkAccumulator timeline = timelines.get(metricId); if (timeline == null) { timeline = new TimelineChunkAccumulator(sourceId, metricId, sampleCoder); if (sampleCount > 0) { addPlaceholders(timeline, sampleCount); } timelines.put(metricId, timeline); } final ScalarSample compressedSample = sampleCoder.compressSample(sample); timeline.addSample(compressedSample); } for (final Map.Entry<Integer, SampleSequenceNumber> entry : metricIdCounters.entrySet()) { final SampleSequenceNumber counter = entry.getValue(); if (counter.getSequenceNumber() < sampleSequenceNumber) { counter.setSequenceNumber(sampleSequenceNumber); final int metricId = entry.getKey(); final TimelineChunkAccumulator timeline = timelines.get(metricId); timeline.addSample(nullSample); } } // Now we can update the state endTime = timestamp; sampleCount++; times.add(timestamp); if (checkEveryAccess) { checkSampleCounts(sampleCount); } }
From source file:com.norconex.collector.http.recrawl.impl.GenericRecrawlableResolver.java
License:Apache License
private boolean isRecrawlableFromMinFrequencies(MinFrequency f, PreviousCrawlData prevData) { String value = f.getValue();//from ww w . ja va2 s . c om if (StringUtils.isBlank(value)) { return true; } if (NumberUtils.isDigits(value)) { DateTime minCrawlDate = new DateTime(prevData.getCrawlDate()); int millis = NumberUtils.toInt(value); minCrawlDate = minCrawlDate.plusMillis(millis); if (minCrawlDate.isBeforeNow()) { if (LOG.isDebugEnabled()) { LOG.debug("Recrawl suggested according to custom " + "directive (min frequency < elapsed " + "time since " + prevData.getCrawlDate() + ") for: " + prevData.getReference()); } return true; } if (LOG.isDebugEnabled()) { LOG.debug("No recrawl suggested according to custom " + "directive (min frequency >= elapsed time since " + prevData.getCrawlDate() + ") for: " + prevData.getReference()); } return false; } SitemapChangeFrequency cf = SitemapChangeFrequency.getChangeFrequency(f.getValue()); return isRecrawlableFromFrequency(cf, prevData, "custom"); }
From source file:com.pureblue.quant.util.frequency.Instantly.java
@Override public DateTime periodEnd(DateTime time) { return time.plusMillis(1); // TODO: can we have a finer resolution than ms? }