Module com.aoapps.messaging.base
Package com.aoapps.messaging.base
Class AbstractSocketContext<S extends AbstractSocket>
java.lang.Object
com.aoapps.messaging.base.AbstractSocketContext<S>
- All Implemented Interfaces:
SocketContext
,Closeable
,AutoCloseable
public abstract class AbstractSocketContext<S extends AbstractSocket>
extends Object
implements SocketContext
Base implementation of socket context.
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static interface
Something that can check the availability of a session ID, to skip used session IDs when creating new sessions. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
protected void
Adds a new socket to this context, sockets must be added to the context before they create any of their own events.void
addSocketContextListener
(SocketContextListener listener, boolean synchronous) protected Future
<?> When an error as occurred, call this to distribute to all of the listeners.void
close()
Any overriding implementation must call super.close() first.getSocket
(Identifier id) boolean
isClosed()
protected Identifier
Creates a random identifier that is not in the current set of sockets.protected void
boolean
-
Constructor Details
-
AbstractSocketContext
protected AbstractSocketContext()
-
-
Method Details
-
getSockets
- Specified by:
getSockets
in interfaceSocketContext
-
getSocket
- Specified by:
getSocket
in interfaceSocketContext
-
addIdentifierAvailabilityChecker
protected void addIdentifierAvailabilityChecker(AbstractSocketContext.IdentifierAvailabilityChecker idChecker) -
removeIdentifierAvailabilityChecker
protected void removeIdentifierAvailabilityChecker(AbstractSocketContext.IdentifierAvailabilityChecker idChecker) -
newIdentifier
Creates a random identifier that is not in the current set of sockets.The identifier is checked against any registered
AbstractSocketContext.IdentifierAvailabilityChecker
.- See Also:
-
close
public void close()Any overriding implementation must call super.close() first.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceSocketContext
-
isClosed
public boolean isClosed()- Specified by:
isClosed
in interfaceSocketContext
-
addSocketContextListener
public void addSocketContextListener(SocketContextListener listener, boolean synchronous) throws IllegalStateException - Specified by:
addSocketContextListener
in interfaceSocketContext
- Throws:
IllegalStateException
-
removeSocketContextListener
- Specified by:
removeSocketContextListener
in interfaceSocketContext
-
addSocket
Adds a new socket to this context, sockets must be added to the context before they create any of their own events. This gives context listeners a chance to register per-socket listeners in "onNewSocket".- First, adds to the list of sockets.
- Second, calls all listeners notifying them of new socket.
- Third, waits for all listeners to handle the event before returning.
-
callOnError
When an error as occurred, call this to distribute to all of the listeners. If need to wait until all of the listeners have handled the error, can call Future.get() or Future.isDone().- Throws:
IllegalStateException
- if this socket is closed
-