/** * Acquires a permit from this semaphore, blocking until one is available, or the thread is * {@link Thread#interrupt interrupted}. * * @throws InterruptedException if the current thread is interrupted * @see Thread#interrupt */ public void acquire() throws InterruptedException { acquire(1); }
/** * Releases a permit, returning it to the semaphore. */ public void release() { release(1); }
/** * Acquires a permit from this semaphore, if one becomes available within the given waiting time * and the current thread has not been {@link Thread#interrupt interrupted}. * * @param timeout the maximum time to wait for a permit * @return <tt>true</tt> if a permit was acquired and <tt>false</tt> if the waiting time elapsed * before a permit was acquired. * @throws InterruptedException if the current thread is interrupted * @see Thread#interrupt */ public boolean tryAcquire(long timeout) throws InterruptedException { return tryAcquire(1, timeout); }
public static void clear() { for (Iterator i = eventSemaphores.entrySet().iterator(); i.hasNext();) { Map.Entry entry = (Entry) i.next(); Semaphore semaphore = (Semaphore) entry.getValue(); int permits = semaphore.drainPermits(); if (permits != 0) { log.warn("event '" + entry.getKey() + "' has " + permits + " outstanding notifications"); } } } }
static Semaphore getEventSemaphore(String event) { synchronized (eventSemaphores) { Semaphore semaphore = (Semaphore) eventSemaphores.get(event); if (semaphore == null) { // request fail semaphore to support atomic multi-acquire semaphore = new Semaphore(0); eventSemaphores.put(event, semaphore); } return semaphore; } }
public static void clear() { for (Iterator i = eventSemaphores.entrySet().iterator(); i.hasNext();) { Map.Entry entry = (Entry) i.next(); Semaphore semaphore = (Semaphore) entry.getValue(); int permits = semaphore.drainPermits(); if (permits != 0) { log.warn("event '" + entry.getKey() + "' has " + permits + " outstanding notifications"); } } } }
static Semaphore getEventSemaphore(String event) { synchronized (eventSemaphores) { Semaphore semaphore = (Semaphore) eventSemaphores.get(event); if (semaphore == null) { // request fail semaphore to support atomic multi-acquire semaphore = new Semaphore(0); eventSemaphores.put(event, semaphore); } return semaphore; } }
/** * Releases a permit, returning it to the semaphore. */ public void release() { release(1); }
/** * Acquires a permit from this semaphore, if one becomes available within the given waiting time * and the current thread has not been {@link Thread#interrupt interrupted}. * * @param timeout the maximum time to wait for a permit * @return <tt>true</tt> if a permit was acquired and <tt>false</tt> if the waiting time elapsed * before a permit was acquired. * @throws InterruptedException if the current thread is interrupted * @see Thread#interrupt */ public boolean tryAcquire(long timeout) throws InterruptedException { return tryAcquire(1, timeout); }
/** * Acquires a permit from this semaphore, blocking until one is available, or the thread is * {@link Thread#interrupt interrupted}. * * @throws InterruptedException if the current thread is interrupted * @see Thread#interrupt */ public void acquire() throws InterruptedException { acquire(1); }
public void afterCompletion(int status) { if (status == Status.STATUS_COMMITTED) { if (log.isDebugEnabled()) log.debug("sending '" + event + "' notification"); Semaphore eventSemaphore = getEventSemaphore(event); eventSemaphore.release(); } } };
public static void waitForEvent(int occurrences, String event, long timeout) { boolean debug = log.isDebugEnabled(); if (debug) log.debug("waiting for " + event); Semaphore eventSemaphore = getEventSemaphore(event); try { if (!eventSemaphore.tryAcquire(occurrences, timeout)) { throw new JbpmException("event '" + event + "' did not occur within " + timeout + " ms"); } if (debug) log.debug("received '" + event + "' notification"); } catch (InterruptedException e) { throw new JbpmException("wait for event '" + event + "' was interrupted", e); } }
public void afterCompletion(int status) { if (status == Status.STATUS_COMMITTED) { if (log.isDebugEnabled()) log.debug("sending '" + event + "' notification"); Semaphore eventSemaphore = getEventSemaphore(event); eventSemaphore.release(); } } };
public static void waitForEvent(int occurrences, String event, long timeout) { boolean debug = log.isDebugEnabled(); if (debug) log.debug("waiting for " + event); Semaphore eventSemaphore = getEventSemaphore(event); try { if (!eventSemaphore.tryAcquire(occurrences, timeout)) { throw new JbpmException("event '" + event + "' did not occur within " + timeout + " ms"); } if (debug) log.debug("received '" + event + "' notification"); } catch (InterruptedException e) { throw new JbpmException("wait for event '" + event + "' was interrupted", e); } }