public abstract class AbstractIoService extends java.lang.Object implements IoService
IoServices.
An instance of IoService contains an Executor which will handle the incoming
events.| Modifier and Type | Class and Description |
|---|---|
protected static class |
AbstractIoService.ServiceOperationFuture |
| Modifier and Type | Field and Description |
|---|---|
private boolean |
createdExecutor
A flag used to indicate that the local executor has been created
inside this instance, and not passed by a caller.
|
protected java.lang.Object |
disposalLock
A lock object which must be acquired when related resources are
destroyed.
|
private boolean |
disposed |
private boolean |
disposing |
private java.util.concurrent.Executor |
executor
The associated executor, responsible for handling execution of I/O events.
|
private IoFilterChainBuilder |
filterChainBuilder
Current filter chain builder.
|
private IoHandler |
handler
The IoHandler in charge of managing all the I/O Events.
|
private static java.util.concurrent.atomic.AtomicInteger |
id
The unique number identifying the Service.
|
private IoServiceListenerSupport |
listeners
Maintains the
IoServiceListeners of this service. |
private static org.slf4j.Logger |
LOGGER |
private IoServiceListener |
serviceActivationListener |
protected IoSessionConfig |
sessionConfig
The default
IoSessionConfig which will be used to configure new sessions. |
private IoSessionDataStructureFactory |
sessionDataStructureFactory |
private IoServiceStatistics |
stats |
private java.lang.String |
threadName
The thread name built from the IoService inherited
instance class name and the IoService Id
|
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractIoService(IoSessionConfig sessionConfig,
java.util.concurrent.Executor executor)
Constructor for
AbstractIoService. |
| Modifier and Type | Method and Description |
|---|---|
void |
addListener(IoServiceListener listener)
Adds an
IoServiceListener that listens any events related with
this service. |
java.util.Set<WriteFuture> |
broadcast(java.lang.Object message)
Writes the specified
message to all the IoSessions
managed by this service. |
void |
dispose()
Releases any resources allocated by this service.
|
void |
dispose(boolean awaitTermination)
Releases any resources allocated by this service.
|
protected abstract void |
dispose0()
Implement this method to release any acquired resources.
|
protected void |
executeWorker(java.lang.Runnable worker) |
protected void |
executeWorker(java.lang.Runnable worker,
java.lang.String suffix) |
protected void |
finishSessionInitialization0(IoSession session,
IoFuture future)
Implement this method to perform additional tasks required for session
initialization.
|
long |
getActivationTime()
Returns the time when this service was activated.
|
DefaultIoFilterChainBuilder |
getFilterChain()
A shortcut for ( ( DefaultIoFilterChainBuilder )
IoService.getFilterChainBuilder() ). |
IoFilterChainBuilder |
getFilterChainBuilder()
Returns the
IoFilterChainBuilder which will build the
IoFilterChain of all IoSessions which is created
by this service. |
IoHandler |
getHandler()
Returns the handler which will handle all connections managed by this service.
|
IoServiceListenerSupport |
getListeners() |
int |
getManagedSessionCount()
Returns the number of all sessions which are currently managed by this
service.
|
java.util.Map<java.lang.Long,IoSession> |
getManagedSessions()
Returns the map of all sessions which are currently managed by this
service.
|
int |
getScheduledWriteBytes()
Returns the number of bytes scheduled to be written
|
int |
getScheduledWriteMessages()
Returns the number of messages scheduled to be written
|
IoSessionDataStructureFactory |
getSessionDataStructureFactory()
Returns the
IoSessionDataStructureFactory that provides
related data structures for a new session created by this service. |
IoServiceStatistics |
getStatistics()
Returns the IoServiceStatistics object for this service.
|
protected void |
initSession(IoSession session,
IoFuture future,
IoSessionInitializer sessionInitializer) |
boolean |
isActive()
Returns a value of whether or not this service is active
|
boolean |
isDisposed()
Returns true if and if only all resources of this processor
have been disposed.
|
boolean |
isDisposing()
Returns true if and if only
IoService.dispose() method has
been called. |
void |
removeListener(IoServiceListener listener)
Removed an existing
IoServiceListener that listens any events
related with this service. |
void |
setFilterChainBuilder(IoFilterChainBuilder builder)
Sets the
IoFilterChainBuilder which will build the
IoFilterChain of all IoSessions which is created
by this service. |
void |
setHandler(IoHandler handler)
Sets the handler which will handle all connections managed by this service.
|
void |
setSessionDataStructureFactory(IoSessionDataStructureFactory sessionDataStructureFactory)
Sets the
IoSessionDataStructureFactory that provides
related data structures for a new session created by this service. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetSessionConfig, getTransportMetadataprivate static final org.slf4j.Logger LOGGER
private static final java.util.concurrent.atomic.AtomicInteger id
private final java.lang.String threadName
private final java.util.concurrent.Executor executor
private final boolean createdExecutor
private IoHandler handler
protected final IoSessionConfig sessionConfig
IoSessionConfig which will be used to configure new sessions.private final IoServiceListener serviceActivationListener
private IoFilterChainBuilder filterChainBuilder
private IoSessionDataStructureFactory sessionDataStructureFactory
private final IoServiceListenerSupport listeners
IoServiceListeners of this service.protected final java.lang.Object disposalLock
private volatile boolean disposing
private volatile boolean disposed
private IoServiceStatistics stats
protected AbstractIoService(IoSessionConfig sessionConfig, java.util.concurrent.Executor executor)
AbstractIoService. You need to provide a default
session configuration and an Executor for handling I/O events. If
a null Executor is provided, a default one will be created using
Executors.newCachedThreadPool().sessionConfig - the default configuration for the managed IoSessionexecutor - the Executor used for handling execution of I/O
events. Can be null.public final IoFilterChainBuilder getFilterChainBuilder()
IoFilterChainBuilder which will build the
IoFilterChain of all IoSessions which is created
by this service.
The default value is an empty DefaultIoFilterChainBuilder.getFilterChainBuilder in interface IoServicepublic final void setFilterChainBuilder(IoFilterChainBuilder builder)
IoFilterChainBuilder which will build the
IoFilterChain of all IoSessions which is created
by this service.
If you specify null this property will be set to
an empty DefaultIoFilterChainBuilder.setFilterChainBuilder in interface IoServicepublic final DefaultIoFilterChainBuilder getFilterChain()
IoService.getFilterChainBuilder() ).
Please note that the returned object is not a real IoFilterChain
but a DefaultIoFilterChainBuilder. Modifying the returned builder
won't affect the existing IoSessions at all, because
IoFilterChainBuilders affect only newly created IoSessions.getFilterChain in interface IoServicepublic final void addListener(IoServiceListener listener)
IoServiceListener that listens any events related with
this service.addListener in interface IoServicepublic final void removeListener(IoServiceListener listener)
IoServiceListener that listens any events
related with this service.removeListener in interface IoServicepublic final boolean isActive()
public final boolean isDisposing()
IoService.dispose() method has
been called. Please note that this method will return true
even after all the related resources are released.isDisposing in interface IoServicepublic final boolean isDisposed()
isDisposed in interface IoServicepublic final void dispose()
public final void dispose(boolean awaitTermination)
awaitTermination = true
will probably lead to a deadlock.protected abstract void dispose0()
throws java.lang.Exception
dispose().java.lang.Exceptionpublic final java.util.Map<java.lang.Long,IoSession> getManagedSessions()
ID of the
session.getManagedSessions in interface IoServicepublic final int getManagedSessionCount()
getManagedSessionCount in interface IoServicepublic final IoHandler getHandler()
getHandler in interface IoServicepublic final void setHandler(IoHandler handler)
setHandler in interface IoServicepublic final IoSessionDataStructureFactory getSessionDataStructureFactory()
IoSessionDataStructureFactory that provides
related data structures for a new session created by this service.getSessionDataStructureFactory in interface IoServicepublic final void setSessionDataStructureFactory(IoSessionDataStructureFactory sessionDataStructureFactory)
IoSessionDataStructureFactory that provides
related data structures for a new session created by this service.setSessionDataStructureFactory in interface IoServicepublic IoServiceStatistics getStatistics()
getStatistics in interface IoServicepublic final long getActivationTime()
getActivationTime in interface IoServiceSystem.currentTimeMillis()public final java.util.Set<WriteFuture> broadcast(java.lang.Object message)
message to all the IoSessions
managed by this service. This method is a convenience shortcut for
IoUtil.broadcast(Object, Collection).public final IoServiceListenerSupport getListeners()
protected final void executeWorker(java.lang.Runnable worker)
protected final void executeWorker(java.lang.Runnable worker,
java.lang.String suffix)
protected final void initSession(IoSession session, IoFuture future, IoSessionInitializer sessionInitializer)
protected void finishSessionInitialization0(IoSession session, IoFuture future)
initSession(IoSession, IoFuture, IoSessionInitializer) will call
this method instead.public int getScheduledWriteBytes()
getScheduledWriteBytes in interface IoServicepublic int getScheduledWriteMessages()
getScheduledWriteMessages in interface IoService