Class AbstractIoService
java.lang.Object
org.apache.mina.core.service.AbstractIoService
- All Implemented Interfaces:
IoService
- Direct Known Subclasses:
AbstractIoAcceptor, AbstractIoConnector
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanA flag used to indicate that the local executor has been created inside this instance, and not passed by a caller.protected final ObjectA lock object which must be acquired when related resources are destroyed.private booleanprivate booleanprivate final ExecutorThe associated executor, responsible for handling execution of I/O events.private IoFilterChainBuilderCurrent filter chain builder.private IoHandlerThe IoHandler in charge of managing all the I/O Events.private static final AtomicIntegerThe unique number identifying the Service.private final IoServiceListenerSupportMaintains theIoServiceListeners of this service.protected static final org.slf4j.Loggerprivate final IoServiceListenerprotected final IoSessionConfigThe defaultIoSessionConfigwhich will be used to configure new sessions.private IoSessionDataStructureFactoryprivate final IoServiceStatisticsprivate final StringThe thread name built from the IoService inherited instance class name and the IoService Id -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractIoService(IoSessionConfig sessionConfig, Executor executor) Constructor forAbstractIoService. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddListener(IoServiceListener listener) Adds anIoServiceListenerthat listens any events related with this service.final Set<WriteFuture> Writes the specifiedmessageto all theIoSessions managed by this service.final voiddispose()Releases any resources allocated by this service.final voiddispose(boolean awaitTermination) Releases any resources allocated by this service.protected abstract voiddispose0()Implement this method to release any acquired resources.protected final voidexecuteWorker(Runnable worker) protected final voidexecuteWorker(Runnable worker, String suffix) protected voidfinishSessionInitialization0(IoSession session, IoFuture future) Implement this method to perform additional tasks required for session initialization.final longfinal IoFilterChainBuilderfinal IoHandlerfinal IoServiceListenerSupportfinal intintintprotected final voidinitSession(IoSession session, IoFuture future, IoSessionInitializer sessionInitializer) final booleanisActive()final booleanfinal booleanfinal voidremoveListener(IoServiceListener listener) Removed an existingIoServiceListenerthat listens any events related with this service.final voidSets theIoFilterChainBuilderwhich will build theIoFilterChainof allIoSessions which is created by this service.final voidsetHandler(IoHandler handler) Sets the handler which will handle all connections managed by this service.final voidsetSessionDataStructureFactory(IoSessionDataStructureFactory sessionDataStructureFactory) Sets theIoSessionDataStructureFactorythat provides related data structures for a new session created by this service.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface IoService
getSessionConfig, getTransportMetadata
-
Field Details
-
LOGGER
protected static final org.slf4j.Logger LOGGER -
id
The unique number identifying the Service. It's incremented for each new IoService created. -
threadName
The thread name built from the IoService inherited instance class name and the IoService Id -
executor
The associated executor, responsible for handling execution of I/O events. -
createdExecutor
private final boolean createdExecutorA flag used to indicate that the local executor has been created inside this instance, and not passed by a caller. If the executor is locally created, then it will be an instance of the ThreadPoolExecutor class. -
handler
The IoHandler in charge of managing all the I/O Events. It is -
sessionConfig
The defaultIoSessionConfigwhich will be used to configure new sessions. -
serviceActivationListener
-
filterChainBuilder
Current filter chain builder. -
sessionDataStructureFactory
-
listeners
Maintains theIoServiceListeners of this service. -
disposalLock
A lock object which must be acquired when related resources are destroyed. -
disposing
private volatile boolean disposing -
disposed
private volatile boolean disposed -
stats
-
-
Constructor Details
-
AbstractIoService
Constructor forAbstractIoService. You need to provide a default session configuration and anExecutorfor handling I/O events. If a nullExecutoris provided, a default one will be created usingExecutors.newCachedThreadPool().
-
-
Method Details
-
getFilterChainBuilder
- Specified by:
getFilterChainBuilderin interfaceIoService- Returns:
- the
IoFilterChainBuilderwhich will build theIoFilterChainof allIoSessions which is created by this service. The default value is an emptyDefaultIoFilterChainBuilder.
-
setFilterChainBuilder
Sets theIoFilterChainBuilderwhich will build theIoFilterChainof allIoSessions which is created by this service. If you specifynullthis property will be set to an emptyDefaultIoFilterChainBuilder.- Specified by:
setFilterChainBuilderin interfaceIoService- Parameters:
builder- The filter chain builder to use
-
getFilterChain
A shortcut for( ( DefaultIoFilterChainBuilder )IoService.getFilterChainBuilder()). Please note that the returned object is not a realIoFilterChainbut aDefaultIoFilterChainBuilder. Modifying the returned builder won't affect the existingIoSessions at all, becauseIoFilterChainBuilders affect only newly createdIoSessions.- Specified by:
getFilterChainin interfaceIoService- Returns:
- The filter chain in use
-
addListener
Adds anIoServiceListenerthat listens any events related with this service.- Specified by:
addListenerin interfaceIoService- Parameters:
listener- The listener to add
-
removeListener
Removed an existingIoServiceListenerthat listens any events related with this service.- Specified by:
removeListenerin interfaceIoService- Parameters:
listener- The listener to use
-
isActive
-
isDisposing
public final boolean isDisposing()- Specified by:
isDisposingin interfaceIoService- Returns:
trueif and if onlyIoService.dispose()method has been called. Please note that this method will returntrueeven after all the related resources are released.
-
isDisposed
public final boolean isDisposed()- Specified by:
isDisposedin interfaceIoService- Returns:
trueif and if only all resources of this processor have been disposed.
-
dispose
-
dispose
public final void dispose(boolean awaitTermination) Releases any resources allocated by this service. Please note that this method might block as long as there are any sessions managed by this service. Warning : calling this method from a IoFutureListener withawaitTermination= true will probably lead to a deadlock. -
dispose0
-
getManagedSessions
-
getManagedSessionCount
public final int getManagedSessionCount()- Specified by:
getManagedSessionCountin interfaceIoService- Returns:
- the number of all sessions which are currently managed by this service.
-
getHandler
- Specified by:
getHandlerin interfaceIoService- Returns:
- the handler which will handle all connections managed by this service.
-
setHandler
Sets the handler which will handle all connections managed by this service.- Specified by:
setHandlerin interfaceIoService- Parameters:
handler- The IoHandler to use
-
getSessionDataStructureFactory
- Specified by:
getSessionDataStructureFactoryin interfaceIoService- Returns:
- the
IoSessionDataStructureFactorythat provides related data structures for a new session created by this service.
-
setSessionDataStructureFactory
public final void setSessionDataStructureFactory(IoSessionDataStructureFactory sessionDataStructureFactory) Sets theIoSessionDataStructureFactorythat provides related data structures for a new session created by this service.- Specified by:
setSessionDataStructureFactoryin interfaceIoService- Parameters:
sessionDataStructureFactory- The factory to use
-
getStatistics
- Specified by:
getStatisticsin interfaceIoService- Returns:
- The statistics object for this service.
-
getActivationTime
public final long getActivationTime()- Specified by:
getActivationTimein interfaceIoService- Returns:
- the time when this service was activated. It returns the last time when this service was activated if the service is not active now.
-
broadcast
Writes the specifiedmessageto all theIoSessions managed by this service. This method is a convenience shortcut forIoUtil.broadcast(Object, Collection). -
getListeners
- Returns:
- The
IoServiceListenerSupportattached to this service
-
executeWorker
-
executeWorker
-
initSession
protected final void initSession(IoSession session, IoFuture future, IoSessionInitializer sessionInitializer) -
finishSessionInitialization0
Implement this method to perform additional tasks required for session initialization. Do not call this method directly;initSession(IoSession, IoFuture, IoSessionInitializer)will call this method instead.- Parameters:
session- The session to initializefuture- The Future to use
-
getScheduledWriteBytes
public int getScheduledWriteBytes()- Specified by:
getScheduledWriteBytesin interfaceIoService- Returns:
- The number of bytes scheduled to be written
-
getScheduledWriteMessages
public int getScheduledWriteMessages()- Specified by:
getScheduledWriteMessagesin interfaceIoService- Returns:
- The number of messages scheduled to be written
-