public class DisconnectAwareConnectionDecorator<T> extends DelegatingConnection<T> implements DisconnectAwareConnection<T>
DisconnectAwareConnection implementation that decorates an existing connection, adding disconnect awareness.
This implementation uses EagerReceiveBuffer internally to receive messages as fast as they are sent.
The messages are then collected by receive() as per normal.
NOTE: due to the use of a bounded buffer, disconnection may not be detected immediately if the internal buffer is full.
| Constructor and Description |
|---|
DisconnectAwareConnectionDecorator(Connection<T> connection,
StoppableExecutor executor) |
DisconnectAwareConnectionDecorator(Connection<T> connection,
StoppableExecutor executor,
int bufferSize) |
| Modifier and Type | Method and Description |
|---|---|
Runnable |
onDisconnect(Runnable disconnectAction)
Used to specify the action to take when a disconnection is detected.
|
T |
receive()
Blocks until the next message is available.
|
void |
requestStop()
Requests that this stoppable commence a graceful stop.
|
void |
stop()
Requests a graceful stop of this object.
|
dispatch, toStringpublic DisconnectAwareConnectionDecorator(Connection<T> connection, StoppableExecutor executor)
public DisconnectAwareConnectionDecorator(Connection<T> connection, StoppableExecutor executor, int bufferSize)
public Runnable onDisconnect(Runnable disconnectAction)
DisconnectAwareConnection
It is guaranteed that calling receive() on this connection will forever return null after
the disconnect action has been started.
If this connection has an associates disconnect action at the time a disconnection is detected, it is guaranteed
to be invoked before any call to receive() will return null.
If the stop() method is called on this connection before a disconnection is detected, the disconnect action
will never be called.
onDisconnect in interface DisconnectAwareConnection<T>disconnectAction - The action to perform on disconnection, or null to remove any existing action.null if no action had been previously registered.public T receive()
Receivepublic void requestStop()
AsyncStoppableRequests that this stoppable commence a graceful stop. Does not block. You should call Stoppable.stop() to wait for the stop process to complete.
Generally, an AsyncStoppable should continue to complete existing work after this method has returned.
It should, however, stop accepting new work.
Requesting stopping does not guarantee the stoppable actually stops. Requesting stopping means preparing for stopping; stopping accepting new work. You have to call stop at some point anyway if your intention is to completely stop the stoppable.
requestStop in interface AsyncStoppablerequestStop in class DelegatingConnection<T>public void stop()
StoppableRequests a graceful stop of this object. Blocks until all concurrent activity has been completed.
If this object has already been stopped, this method does nothing.
stop in interface Stoppablestop in class DelegatingConnection<T>Copyright © 2013. All rights reserved