/** * Start the expiration period for this instance. * @param timeToLive the number of seconds before expiration */ public void startExpirationPeriod(int timeToLive) { this.expirationTime = System.currentTimeMillis() + timeToLive * 1000; }
/** * Return whether this instance has expired depending on the amount of * elapsed time since the call to {@link #startExpirationPeriod}. */ public boolean isExpired() { return (this.expirationTime != -1 && System.currentTimeMillis() > this.expirationTime); }
/** * Create a new ApplicationEvent. * @param source the object on which the event initially occurred (never {@code null}) */ public ApplicationEvent(Object source) { super(source); this.timestamp = System.currentTimeMillis(); }
/** * Returns the 'current time' of the Scheduler in the specified time unit. * @param unit the time unit * @return the 'current time' * @since 2.0 */ public long now(@NonNull TimeUnit unit) { return unit.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS); }
/** * Returns the 'current time' of the Worker in the specified time unit. * @param unit the time unit * @return the 'current time' * @since 2.0 */ public long now(@NonNull TimeUnit unit) { return unit.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS); }
/** * Sets the certificate to be valid immediately and until the specified duration has elapsed. * The precision of this field is seconds; further precision will be truncated. */ public Builder duration(long duration, TimeUnit unit) { long now = System.currentTimeMillis(); return validityInterval(now, now + unit.toMillis(duration)); }
/** * Attempt to parse a {@code Set-Cookie} HTTP header value {@code setCookie} as a cookie. Returns * null if {@code setCookie} is not a well-formed cookie. */ public static @Nullable Cookie parse(HttpUrl url, String setCookie) { return parse(System.currentTimeMillis(), url, setCookie); }
@Override public final synchronized void refresh() { logger.debug("Attempting to refresh target"); this.targetObject = freshTarget(); this.refreshCount++; this.lastRefreshTime = System.currentTimeMillis(); logger.debug("Target refreshed successfully"); }
private void updateSessionReadTime(@Nullable String sessionId) { if (sessionId != null) { SessionInfo info = this.sessions.get(sessionId); if (info != null) { info.setLastReadTime(System.currentTimeMillis()); } } }
@Override public void run() { times.add(System.currentTimeMillis()); } }, 100, 100, TimeUnit.MILLISECONDS);
@Override public void run() { times.add(System.currentTimeMillis()); } }, 100, 100, TimeUnit.MILLISECONDS);
@Override public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Date startTime, long period) { long initialDelay = startTime.getTime() - System.currentTimeMillis(); try { return this.scheduledExecutor.scheduleAtFixedRate(decorateTask(task, true), initialDelay, period, TimeUnit.MILLISECONDS); } catch (RejectedExecutionException ex) { throw new TaskRejectedException("Executor [" + this.scheduledExecutor + "] did not accept task: " + task, ex); } }
void sleep() throws Exception { cb.await(); try { long before = System.currentTimeMillis(); Thread.sleep(5000); throw new IllegalStateException("Was not interrupted in time?! " + (System.currentTimeMillis() - before)); } catch (InterruptedException ex) { // ignored here } }
void beforeCancelSleep(BaseTestConsumer<?, ?> ts) throws Exception { long before = System.currentTimeMillis(); Thread.sleep(50); if (System.currentTimeMillis() - before > 100) { ts.dispose(); throw new IllegalStateException("Overslept?" + (System.currentTimeMillis() - before)); } }
public WebResponse build() throws IOException { WebResponseData webResponseData = webResponseData(); long endTime = System.currentTimeMillis(); return new WebResponse(webResponseData, this.webRequest, endTime - this.startTime); }
@Override public ScheduledFuture<?> schedule(Runnable task, Date startTime) { ScheduledExecutorService executor = getScheduledExecutor(); long initialDelay = startTime.getTime() - System.currentTimeMillis(); try { return executor.schedule(errorHandlingTask(task, false), initialDelay, TimeUnit.MILLISECONDS); } catch (RejectedExecutionException ex) { throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex); } }
@Override public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, Date startTime, long delay) { ScheduledExecutorService executor = getScheduledExecutor(); long initialDelay = startTime.getTime() - System.currentTimeMillis(); try { return executor.scheduleWithFixedDelay(errorHandlingTask(task, true), initialDelay, delay, TimeUnit.MILLISECONDS); } catch (RejectedExecutionException ex) { throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex); } }
@Override public void subscribe(Subscriber<? super String> t1) { t1.onSubscribe(new BooleanSubscription()); System.out.println(count.get() + " @ " + String.valueOf(last - System.currentTimeMillis())); last = System.currentTimeMillis(); if (count.getAndDecrement() == 0) { t1.onNext("hello"); t1.onComplete(); } else { t1.onError(new RuntimeException()); } }
@Override public void subscribe(Observer<? super String> t1) { t1.onSubscribe(Disposables.empty()); System.out.println(count.get() + " @ " + String.valueOf(last - System.currentTimeMillis())); last = System.currentTimeMillis(); if (count.getAndDecrement() == 0) { t1.onNext("hello"); t1.onComplete(); } else { t1.onError(new RuntimeException()); } }
public void testSendAttributeChangeNotificationWhereSourceIsNotTheManagedResource() throws Exception { StubSpringModelMBean mbean = new StubSpringModelMBean(); Notification notification = new AttributeChangeNotification(this, 1872, System.currentTimeMillis(), "Shall we break for some tea?", "agree", "java.lang.Boolean", Boolean.FALSE, Boolean.TRUE); ObjectName objectName = createObjectName(); NotificationPublisher publisher = new ModelMBeanNotificationPublisher(mbean, objectName, mbean); publisher.sendNotification(notification); assertNotNull(mbean.getActualNotification()); assertTrue(mbean.getActualNotification() instanceof AttributeChangeNotification); assertSame("The exact same Notification is not being passed through from the publisher to the mbean.", notification, mbean.getActualNotification()); assertSame("The 'source' property of the Notification is *wrongly* being set to the ObjectName of the associated MBean.", this, mbean.getActualNotification().getSource()); }