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
Nested ClassesModifier and TypeClassDescriptionprotected static interfaceSomething that can check the availability of a session ID, to skip used session IDs when creating new sessions. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidprotected voidAdds a new socket to this context, sockets must be added to the context before they create any of their own events.voidaddSocketContextListener(SocketContextListener listener, boolean synchronous) protected Future<?> When an error as occurred, call this to distribute to all of the listeners.voidclose()Any overriding implementation must call super.close() first.getSocket(Identifier id) booleanisClosed()protected IdentifierCreates a random identifier that is not in the current set of sockets.protected voidboolean
-
Constructor Details
-
AbstractSocketContext
protected AbstractSocketContext()Creates a newAbstractSocketContext.
-
-
Method Details
-
getSockets
- Specified by:
getSocketsin interfaceSocketContext
-
getSocket
- Specified by:
getSocketin 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceSocketContext
-
isClosed
public boolean isClosed()- Specified by:
isClosedin interfaceSocketContext
-
addSocketContextListener
public void addSocketContextListener(SocketContextListener listener, boolean synchronous) throws IllegalStateException - Specified by:
addSocketContextListenerin interfaceSocketContext- Throws:
IllegalStateException
-
removeSocketContextListener
- Specified by:
removeSocketContextListenerin 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
-
