/** * register a Deadline threadlocal object to current thread. * @param timeout */ public static void registerIfNot(long timeout) { if (getCurrentDeadline() == null) { setCurrentDeadline(new Deadline(timeout)); } }
/** * start the timer before a method is invoked. * @param method method to be invoked */ public static boolean startTimer(String method) throws MetaException { Deadline deadline = getCurrentDeadline(); if (deadline == null) { throw MetaStoreUtils.newMetaException(new DeadlineException("The threadlocal Deadline is null," + " please register it first.")); } if (deadline.startTime != NO_DEADLINE) return false; deadline.method = method; do { deadline.startTime = System.nanoTime(); } while (deadline.startTime == NO_DEADLINE); return true; }
/** * end the time after a method is done. */ public static void stopTimer() throws MetaException { Deadline deadline = getCurrentDeadline(); if (deadline != null) { deadline.startTime = NO_DEADLINE; deadline.method = null; } else { throw MetaStoreUtils.newMetaException(new DeadlineException("The threadlocal Deadline is null," + " please register it first.")); } }
/** * Check whether the long running method timeout. * @throws MetaException when the method timeout */ public static void checkTimeout() throws MetaException { Deadline deadline = getCurrentDeadline(); if (deadline != null) { deadline.check(); } else { throw MetaStoreUtils.newMetaException(new DeadlineException("The threadlocal Deadline is null," + " please register it first.")); } }
/** * reset the timeout value of this timer. * @param timeoutMs */ public static void resetTimeout(long timeoutMs) throws MetaException { if (timeoutMs <= 0) { throw MetaStoreUtils.newMetaException(new DeadlineException("The reset timeout value should be " + "larger than 0: " + timeoutMs)); } Deadline deadline = getCurrentDeadline(); if (deadline != null) { deadline.timeoutNanos = timeoutMs * 1000000L; } else { throw MetaStoreUtils.newMetaException(new DeadlineException("The threadlocal Deadline is null," + " please register it first.")); } }
if (Deadline.getCurrentDeadline() != null) { failInThread("the threadlocal object should be removed after timeout.", null);
/** * register a Deadline threadlocal object to current thread. * @param timeout */ public static void registerIfNot(long timeout) { if (getCurrentDeadline() == null) { setCurrentDeadline(new Deadline(timeout)); } }
/** * start the timer before a method is invoked. * @param method */ public static void startTimer(String method) throws MetaException { Deadline deadline = getCurrentDeadline(); if (deadline != null) { deadline.startTime = System.currentTimeMillis(); deadline.method = method; } else { throw newMetaException(new DeadlineException("The threadlocal Deadline is null," + " please register it firstly.")); } }
/** * start the timer before a method is invoked. * @param method */ public static void startTimer(String method) throws MetaException { Deadline deadline = getCurrentDeadline(); if (deadline != null) { deadline.startTime = System.currentTimeMillis(); deadline.method = method; } else { throw newMetaException(new DeadlineException("The threadlocal Deadline is null," + " please register it firstly.")); } }
/** * register a Deadline threadlocal object to current thread. * @param timeout */ public static void registerIfNot(long timeout) { if (getCurrentDeadline() == null) { setCurrentDeadline(new Deadline(timeout)); } }
/** * end the time after a method is done. */ public static void stopTimer() throws MetaException { Deadline deadline = getCurrentDeadline(); if (deadline != null) { deadline.startTime = -1; deadline.method = null; } else { throw newMetaException(new DeadlineException("The threadlocal Deadline is null," + " please register it firstly.")); } }
/** * register a Deadline threadlocal object to current thread. * @param timeout */ public static void registerIfNot(long timeout) { if (getCurrentDeadline() == null) { setCurrentDeadline(new Deadline(timeout)); } }
/** * end the time after a method is done. */ public static void stopTimer() throws MetaException { Deadline deadline = getCurrentDeadline(); if (deadline != null) { deadline.startTime = NO_DEADLINE; deadline.method = null; } else { throw MetaStoreUtils.newMetaException(new DeadlineException("The threadlocal Deadline is null," + " please register it first.")); } }
/** * end the time after a method is done. */ public static void stopTimer() throws MetaException { Deadline deadline = getCurrentDeadline(); if (deadline != null) { deadline.startTime = -1; deadline.method = null; } else { throw newMetaException(new DeadlineException("The threadlocal Deadline is null," + " please register it firstly.")); } }
/** * Check whether the timer is started. * @return * @throws MetaException */ public static boolean isStarted() throws MetaException { Deadline deadline = getCurrentDeadline(); if (deadline != null) { return deadline.startTime >= 0; } else { throw newMetaException(new DeadlineException("The threadlocal Deadline is null," + " please register it firstly.")); } }
/** * Check whether the timer is started. * @return * @throws MetaException */ public static boolean isStarted() throws MetaException { Deadline deadline = getCurrentDeadline(); if (deadline != null) { return deadline.startTime >= 0; } else { throw newMetaException(new DeadlineException("The threadlocal Deadline is null," + " please register it firstly.")); } }
/** * Check whether the long running method timeout. * @throws DeadlineException when the method timeout */ public static void checkTimeout() throws MetaException { Deadline deadline = getCurrentDeadline(); if (deadline != null) { deadline.check(); } else { throw newMetaException(new DeadlineException("The threadlocal Deadline is null," + " please register it first.")); } }
/** * Check whether the long running method timeout. * @throws DeadlineException when the method timeout */ public static void checkTimeout() throws MetaException { Deadline deadline = getCurrentDeadline(); if (deadline != null) { deadline.check(); } else { throw newMetaException(new DeadlineException("The threadlocal Deadline is null," + " please register it first.")); } }
/** * Check whether the long running method timeout. * @throws MetaException when the method timeout */ public static void checkTimeout() throws MetaException { Deadline deadline = getCurrentDeadline(); if (deadline != null) { deadline.check(); } else { throw MetaStoreUtils.newMetaException(new DeadlineException("The threadlocal Deadline is null," + " please register it first.")); } }
/** * reset the timeout value of this timer. * @param timeoutMs */ public static void resetTimeout(long timeoutMs) throws MetaException { if (timeoutMs <= 0) { throw MetaStoreUtils.newMetaException(new DeadlineException("The reset timeout value should be " + "larger than 0: " + timeoutMs)); } Deadline deadline = getCurrentDeadline(); if (deadline != null) { deadline.timeoutNanos = timeoutMs * 1000000L; } else { throw MetaStoreUtils.newMetaException(new DeadlineException("The threadlocal Deadline is null," + " please register it first.")); } }