/** * {@inheritDoc} */ @Override public boolean isStopped() { final State currentState = state.getState(); return currentState == State.STOPPED || currentState == State.STOPPING; }
public AbstractTransport(String name) { this.name = name; state = new StateHolder<State>(State.STOPPED); }
/** * Register listener, which will be notified, when state will be equal to passed * one. Once listener will be notified - it will be removed from this * <code>StateHolder</code>'s listener set. * @param state State, listener is interested in * @param completionHandler that will be notified. This <code>StateHolder</code> * implementation works with Runnable, Callable, CountDownLatch, Object * listeners * @return <code>ConditionListener</code>, if current state is not equal to required * and listener was registered, null if current state is equal to required. * In both cases listener will be notified */ public Future<E> notifyWhenStateIsEqual(final E state, final CompletionHandler<E> completionHandler) { return notifyWhenConditionMatchState(new Condition() { @Override public boolean check() { return state == StateHolder.this.state; } }, completionHandler); }
/** * Resume UDPNIOTransport, which has been paused before using {@link #pause()}. * * The transport will be resumed only if its current state is {@link org.glassfish.grizzly.Transport.State#PAUSED}, * otherwise the call will be ignored without exception thrown and the transport * state will remain the same as it was before the method call. */ @Override public void resume() { final Lock lock = state.getStateLocker().writeLock(); lock.lock(); try { if (state.getState() != State.PAUSED) { LOGGER.log(Level.WARNING, LogMessages.WARNING_GRIZZLY_TRANSPORT_NOT_PAUSE_STATE_EXCEPTION()); return; } state.setState(State.STARTING); notifyProbesBeforeResume(this); state.setState(State.STARTED); notifyProbesResume(this); } finally { lock.unlock(); } }
@Override public boolean addShutdownListener(final GracefulShutdownListener shutdownListener) { final Lock lock = state.getStateLocker().writeLock(); lock.lock(); try { final State stateNow = state.getState(); if (stateNow != State.STOPPING || stateNow != State.STOPPED) { if (shutdownListeners == null) { shutdownListeners = new HashSet<GracefulShutdownListener>(); } return shutdownListeners.add(shutdownListener); } return false; } finally { lock.unlock(); } }
if (transportStateHolder.getState() != State.PAUSED) { isSkipping = !doSelect(); } else { try { transportStateHolder .notifyWhenStateIsNotEqual(State.PAUSED, null) .get(5000, TimeUnit.MILLISECONDS); } catch (Exception ignored) {
/** * Sets current state * Current StateHolder locking mode will be used * @param state */ public void setState(E state) { readWriteLock.writeLock().lock(); try { this.state = state; // downgrading lock to read readWriteLock.readLock().lock(); readWriteLock.writeLock().unlock(); notifyConditionListeners(); } finally { readWriteLock.readLock().unlock(); } }
private void rebindAddress(final Connection connection) throws IOException { final Lock lock = state.getStateLocker().writeLock(); lock.lock(); try { if (Thread.currentThread().isInterrupted()) { Thread.interrupted(); } //noinspection SuspiciousMethodCalls if (serverConnections.remove(connection)) { final SocketAddress address = (SocketAddress) connection.getLocalAddress(); bind(address); } } finally { lock.unlock(); } } }
/** * Resume UDPNIOTransport, which has been paused before using {@link #pause()}. * * The transport will be resumed only if its current state is {@link org.glassfish.grizzly.Transport.State#PAUSED}, * otherwise the call will be ignored without exception thrown and the transport * state will remain the same as it was before the method call. */ @Override public void resume() { final Lock lock = state.getStateLocker().writeLock(); lock.lock(); try { if (state.getState() != State.PAUSED) { LOGGER.log(Level.WARNING, LogMessages.WARNING_GRIZZLY_TRANSPORT_NOT_PAUSE_STATE_EXCEPTION()); return; } state.setState(State.STARTING); notifyProbesBeforeResume(this); state.setState(State.STARTED); notifyProbesResume(this); } finally { lock.unlock(); } }
@Override public boolean addShutdownListener(final GracefulShutdownListener shutdownListener) { final Lock lock = state.getStateLocker().writeLock(); lock.lock(); try { final State stateNow = state.getState(); if (stateNow != State.STOPPING || stateNow != State.STOPPED) { if (shutdownListeners == null) { shutdownListeners = new HashSet<GracefulShutdownListener>(); } return shutdownListeners.add(shutdownListener); } return false; } finally { lock.unlock(); } }
if (transportStateHolder.getState() != State.PAUSED) { isSkipping = !doSelect(); } else { try { transportStateHolder .notifyWhenStateIsNotEqual(State.PAUSED, null) .get(5000, TimeUnit.MILLISECONDS); } catch (Exception ignored) {
/** * Sets current state * Current StateHolder locking mode will be used * @param state */ public void setState(E state) { readWriteLock.writeLock().lock(); try { this.state = state; // downgrading lock to read readWriteLock.readLock().lock(); readWriteLock.writeLock().unlock(); notifyConditionListeners(); } finally { readWriteLock.readLock().unlock(); } }
private void rebindAddress(final Connection connection) throws IOException { final Lock lock = state.getStateLocker().writeLock(); lock.lock(); try { if (Thread.currentThread().isInterrupted()) { Thread.interrupted(); } //noinspection SuspiciousMethodCalls if (serverConnections.remove(connection)) { final SocketAddress address = (SocketAddress) connection.getLocalAddress(); bind(address); } } finally { lock.unlock(); } } }
/** * Resume UDPNIOTransport, which has been paused before using {@link #pause()}. * * The transport will be resumed only if its current state is {@link org.glassfish.grizzly.Transport.State#PAUSED}, * otherwise the call will be ignored without exception thrown and the transport * state will remain the same as it was before the method call. */ @Override public void resume() { final Lock lock = state.getStateLocker().writeLock(); lock.lock(); try { if (state.getState() != State.PAUSED) { LOGGER.log(Level.WARNING, LogMessages.WARNING_GRIZZLY_TRANSPORT_NOT_PAUSE_STATE_EXCEPTION()); return; } state.setState(State.STARTING); notifyProbesBeforeResume(this); state.setState(State.STARTED); notifyProbesResume(this); } finally { lock.unlock(); } }
@Override public boolean addShutdownListener(final GracefulShutdownListener shutdownListener) { final Lock lock = state.getStateLocker().writeLock(); lock.lock(); try { final State stateNow = state.getState(); if (stateNow != State.STOPPING || stateNow != State.STOPPED) { if (shutdownListeners == null) { shutdownListeners = new HashSet<GracefulShutdownListener>(); } return shutdownListeners.add(shutdownListener); } return false; } finally { lock.unlock(); } }
if (transportStateHolder.getState() != State.PAUSED) { isSkipping = !doSelect(); } else { try { transportStateHolder .notifyWhenStateIsNotEqual(State.PAUSED, null) .get(5000, TimeUnit.MILLISECONDS); } catch (Exception ignored) {
/** * {@inheritDoc} */ @Override public boolean isStopped() { final State currentState = state.getState(); return currentState == State.STOPPED || currentState == State.STOPPING; }
/** * Register listener, which will be notified, when state will be equal to passed * one. Once listener will be notified - it will be removed from this * <code>StateHolder</code>'s listener set. * @param state State, listener is interested in * @param completionHandler that will be notified. This <code>StateHolder</code> * implementation works with Runnable, Callable, CountDownLatch, Object * listeners * @return <code>ConditionListener</code>, if current state is not equal to required * and listener was registered, null if current state is equal to required. * In both cases listener will be notified */ public Future<E> notifyWhenStateIsEqual(final E state, final CompletionHandler<E> completionHandler) { return notifyWhenConditionMatchState(new Condition() { @Override public boolean check() { return state == StateHolder.this.state; } }, completionHandler); }
public AbstractTransport(String name) { this.name = name; state = new StateHolder<State>(State.STOPPED); }
/** * Sets current state * Current StateHolder locking mode will be used * @param state */ public void setState(E state) { readWriteLock.writeLock().lock(); try { this.state = state; // downgrading lock to read readWriteLock.readLock().lock(); readWriteLock.writeLock().unlock(); notifyConditionListeners(); } finally { readWriteLock.readLock().unlock(); } }