/** * Waits for the dialogue thread to end. * * @param timeout maximum time to wait for the thread to end. A value of * Duration.ZERO (or equivalent) means to wait forever. * @throws InterruptedException if the current thread was interrupted while * waiting for the dialogue thread to terminate. */ public void join(Duration timeout) throws InterruptedException { mDialogueThread.join(timeout.getMilliseconds()); }
public static Duration sum(Duration a, Duration b) { long millisecondsA = a.getMilliseconds(); long millisecondsB = b.getMilliseconds(); long allowedMax = Long.MAX_VALUE - millisecondsA; if (millisecondsB > allowedMax) throw new AssertionError("Time sum would overflow Long capacity."); return new Duration(millisecondsA + millisecondsB); }
public static void addDurationProperty(Element parent, String propertyName, Duration value) { if (value != null) { addProperty(parent, propertyName, value.getMilliseconds() + MILLISECOND_UNIT_SUFFIX); } }
public static void setDurationAttribute(Element element, String attributeName, Duration value) { if (value != null) { setAttribute(element, attributeName, value.getMilliseconds() + MILLISECOND_UNIT_SUFFIX); } }
public static void addDurationProperty(JsonObjectBuilder builder, String propertyName, Duration duration) { if (duration == null) { builder.addNull(propertyName); } else { builder.add(propertyName, duration.getMilliseconds()); } }
public static void addCacheControlDurationProperty(Element parent, String propertyName, Duration value) { if (value != null) { addProperty(parent, propertyName, String.valueOf(value.getMilliseconds() / 1000)); } }
public static void setCacheControlDurationAttribute(Element parent, String propertyName, Duration value) { if (value != null) { setAttribute(parent, propertyName, String.valueOf(value.getMilliseconds() / 1000)); } }
@Override public JsonValue asJson() { JsonObjectBuilder builder = JsonUtils.createObjectBuilder(); JsonUtils.add(builder, DTMF_TERM_PROPERTY, mDtmfTerm); builder.add(MAX_TIME_PROPERTY, mMaxTime); builder.add(DURATION_PROPERTY, mDuration.getMilliseconds()); JsonUtils.add(builder, "file", mFile); return builder.build(); }
@Override public JsonValue asJson() { JsonObjectBuilder builder = JsonUtils.createObjectBuilder(); JsonUtils.add(builder, STATUS_PROPERTY, mStatus.asJson()); builder.add(DURATION_PROPERTY, mDuration.getMilliseconds()); return builder.build(); }
Long lastAccess = mLastAccess.get(sessionId); if (lastAccess != null) { if (currentTime - lastAccess > mSessionTimeout.getMilliseconds()) { Session<I, O, F, L, C> sessionContext = mSessions.get(sessionId); sessionContext.stop(); Thread.sleep(mTimeoutCheckScanPeriod.getMilliseconds()); } catch (InterruptedException interruptedException) { if (mStopped) {
private static <R> R receive(NamedSynchronousQueue<R> receiveQueue, Duration timeout) throws Timeout, InterruptedException { if (receiveQueue == null) throw new IllegalStateException("Receive queue is closed."); R result = receiveQueue.poll(timeout.getMilliseconds(), TimeUnit.MILLISECONDS); if (result == null) throw new Timeout("Timed-out in receive() after " + timeout + " in [" + receiveQueue.getName() + "]"); return result; }
private static <S> void send(NamedSynchronousQueue<S> sendQueue, S itemToSend, Duration timeout) throws Timeout, InterruptedException { if (sendQueue == null) throw new IllegalStateException("Send queue is closed."); boolean success = sendQueue.offer(itemToSend, timeout.getMilliseconds(), TimeUnit.MILLISECONDS); if (!success) throw new Timeout("Timed-out in send() after " + timeout + " in [" + sendQueue.getName() + "]"); }
waitForDialoguesToTerminateThread.join(Duration.seconds(10).getMilliseconds()); if (waitForDialoguesToTerminateThread.isAlive()) { waitForDialoguesToTerminateThread.interrupt(); waitForDialoguesToTerminateThread.join(Duration.seconds(2).getMilliseconds());