Package org.apache.mina.core.service
Class AbstractIoService
- java.lang.Object
-
- org.apache.mina.core.service.AbstractIoService
-
- All Implemented Interfaces:
IoService
- Direct Known Subclasses:
AbstractIoAcceptor,AbstractIoConnector
public abstract class AbstractIoService extends Object implements IoService
Base implementation ofIoServices. An instance of IoService contains an Executor which will handle the incoming events.- Author:
- Apache MINA Project
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static classAbstractIoService.ServiceOperationFutureAIoFuturededicated class for
-
Field Summary
Fields Modifier and Type Field Description protected ObjectdisposalLockA lock object which must be acquired when related resources are destroyed.protected static LoggerLOGGERprotected IoSessionConfigsessionConfigThe defaultIoSessionConfigwhich will be used to configure new sessions.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractIoService(IoSessionConfig sessionConfig, Executor executor)Constructor forAbstractIoService.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddListener(IoServiceListener listener)Adds anIoServiceListenerthat listens any events related with this service.Set<WriteFuture>broadcast(Object message)Writes the specifiedmessageto all theIoSessions managed by this service.voiddispose()Releases any resources allocated by this service.voiddispose(boolean awaitTermination)Releases any resources allocated by this service.protected abstract voiddispose0()Implement this method to release any acquired resources.protected voidexecuteWorker(Runnable worker)protected voidexecuteWorker(Runnable worker, String suffix)protected voidfinishSessionInitialization0(IoSession session, IoFuture future)Implement this method to perform additional tasks required for session initialization.longgetActivationTime()DefaultIoFilterChainBuildergetFilterChain()IoFilterChainBuildergetFilterChainBuilder()IoHandlergetHandler()IoServiceListenerSupportgetListeners()intgetManagedSessionCount()Map<Long,IoSession>getManagedSessions()intgetScheduledWriteBytes()intgetScheduledWriteMessages()IoSessionDataStructureFactorygetSessionDataStructureFactory()IoServiceStatisticsgetStatistics()protected voidinitSession(IoSession session, IoFuture future, IoSessionInitializer sessionInitializer)booleanisActive()booleanisDisposed()booleanisDisposing()voidremoveListener(IoServiceListener listener)Removed an existingIoServiceListenerthat listens any events related with this service.voidsetFilterChainBuilder(IoFilterChainBuilder builder)Sets theIoFilterChainBuilderwhich will build theIoFilterChainof allIoSessions which is created by this service.voidsetHandler(IoHandler handler)Sets the handler which will handle all connections managed by this service.voidsetSessionDataStructureFactory(IoSessionDataStructureFactory sessionDataStructureFactory)Sets theIoSessionDataStructureFactorythat provides related data structures for a new session created by this service.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.mina.core.service.IoService
getSessionConfig, getTransportMetadata
-
-
-
-
Field Detail
-
LOGGER
protected static final Logger LOGGER
-
sessionConfig
protected final IoSessionConfig sessionConfig
The defaultIoSessionConfigwhich will be used to configure new sessions.
-
disposalLock
protected final Object disposalLock
A lock object which must be acquired when related resources are destroyed.
-
-
Constructor Detail
-
AbstractIoService
protected AbstractIoService(IoSessionConfig sessionConfig, Executor executor)
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 Detail
-
getFilterChainBuilder
public final IoFilterChainBuilder 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
public final void setFilterChainBuilder(IoFilterChainBuilder builder)
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
public final DefaultIoFilterChainBuilder 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
public final void addListener(IoServiceListener listener)
Adds anIoServiceListenerthat listens any events related with this service.- Specified by:
addListenerin interfaceIoService- Parameters:
listener- The listener to add
-
removeListener
public final void removeListener(IoServiceListener listener)
Removed an existingIoServiceListenerthat listens any events related with this service.- Specified by:
removeListenerin interfaceIoService- Parameters:
listener- The listener to use
-
isActive
public final boolean 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
public final void dispose()
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.
-
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
protected abstract void dispose0() throws ExceptionImplement this method to release any acquired resources. This method is invoked only once bydispose().- Throws:
Exception- If the dispose failed
-
getManagedSessions
public final Map<Long,IoSession> getManagedSessions()
- Specified by:
getManagedSessionsin interfaceIoService- Returns:
- the map of all sessions which are currently managed by this
service. The key of map is the
IDof the session. An empty collection if there's no session.
-
getManagedSessionCount
public final int getManagedSessionCount()
- Specified by:
getManagedSessionCountin interfaceIoService- Returns:
- the number of all sessions which are currently managed by this service.
-
getHandler
public final IoHandler getHandler()
- Specified by:
getHandlerin interfaceIoService- Returns:
- the handler which will handle all connections managed by this service.
-
setHandler
public final void setHandler(IoHandler handler)
Sets the handler which will handle all connections managed by this service.- Specified by:
setHandlerin interfaceIoService- Parameters:
handler- The IoHandler to use
-
getSessionDataStructureFactory
public final IoSessionDataStructureFactory 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
public IoServiceStatistics 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
public final Set<WriteFuture> broadcast(Object message)
Writes the specifiedmessageto all theIoSessions managed by this service. This method is a convenience shortcut forIoUtil.broadcast(Object, Collection).
-
getListeners
public final IoServiceListenerSupport getListeners()
- Returns:
- The
IoServiceListenerSupportattached to this service
-
executeWorker
protected final void executeWorker(Runnable worker)
-
initSession
protected final void initSession(IoSession session, IoFuture future, IoSessionInitializer sessionInitializer)
-
finishSessionInitialization0
protected void finishSessionInitialization0(IoSession session, IoFuture future)
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
-
-