boolean isIdle() { try(Locker.Lock lock = _locker.lock()) { return _state == State.IDLE; } }
public boolean isClosed() { try(Locker.Lock lock = _locker.lock()) { return _state == State.CLOSED; } }
/** * @return whether this callback has succeeded */ public boolean isSucceeded() { try(Locker.Lock lock = _locker.lock()) { return _state == State.SUCCEEDED; } }
/** * @return whether this callback has failed */ public boolean isFailed() { try(Locker.Lock lock = _locker.lock()) { return _state == State.FAILED; } }
public Boolean isIdle() { try (Lock locked = _locker.lock()) { return _idle; } }
/** * @deprecated use {@link #lock()} instead * @return the lock to unlock */ @Deprecated public Lock lockIfNotHeld() { return lock(); }
/** * Resets this callback. * <p> * A callback can only be reset to IDLE from the * SUCCEEDED or FAILED states or if it is already IDLE. * </p> * * @return true if the reset was successful */ public boolean reset() { try(Locker.Lock lock = _locker.lock()) { switch(_state) { case IDLE: return true; case SUCCEEDED: case FAILED: _iterate=false; _state=State.IDLE; return true; default: return false; } } }
@Override public String toString() { StringBuilder builder = new StringBuilder(); builder.append("EPC "); try (Lock locked = _locker.lock()) { builder.append(_idle ? "Idle/" : ""); builder.append(_producing ? "Prod/" : ""); builder.append(_pending ? "Pend/" : ""); builder.append(_execute ? "Exec/" : ""); } builder.append(_producer); return builder.toString(); }
public void close() { String failure=null; try(Locker.Lock lock = _locker.lock()) { switch (_state) { case IDLE: case SUCCEEDED: case FAILED: _state=State.CLOSED; break; case CLOSED: break; default: failure=String.format("Close %s in state %s",this,_state); _state=State.CLOSED; } } if(failure!=null) onCompleteFailure(new IOException(failure)); }
public void offer(Runnable task) { if (LOG.isDebugEnabled()) LOG.debug("{} offer {}", this, task); try (Locker.Lock lock = _locker.lock()) { _task = task; _wakeup.signal(); } }
@Override public void dispatch() { if (LOG.isDebugEnabled()) LOG.debug("{} spawning", this); boolean dispatch = false; try (Lock locked = _locker.lock()) { if (_idle) dispatch = true; else _execute = true; } if (dispatch) _executor.execute(_runProduce); }
try(Locker.Lock lock = _locker.lock())
try(Locker.Lock lock = _locker.lock())
try (Locker.Lock lock = _locker.lock())
@Override public void run() { if (LOG.isDebugEnabled()) LOG.debug("{} run", this); boolean produce = false; try (Lock locked = _locker.lock()) { _pending = false; if (!_idle && !_producing) { produce = _producing = true; } } if (produce) produceConsume(); }
@Override public void produce() { if (LOG.isDebugEnabled()) LOG.debug("{} execute", this); boolean produce = false; try (Lock locked = _locker.lock()) { // If we are idle and a thread is not producing if (_idle) { if (_producing) throw new IllegalStateException(); // Then this thread will do the producing produce = _producing = true; // and we are no longer idle _idle = false; } else { // Otherwise, lets tell the producing thread // that it should call produce again before going idle _execute = true; } } if (produce) produceConsume(); }
try(Locker.Lock lock = _locker.lock())
try (Locker.Lock lock = _locker.lock())