public abstract class AbstractIoService extends Object implements IoService
IoService
s.
An instance of IoService contains an Executor which will handle the incoming
events.Modifier and Type | Class and Description |
---|---|
protected static class |
AbstractIoService.ServiceOperationFuture
A
IoFuture dedicated class for |
Modifier and Type | Field and Description |
---|---|
protected Object |
disposalLock
A lock object which must be acquired when related resources are
destroyed.
|
protected static org.slf4j.Logger |
LOGGER |
protected IoSessionConfig |
sessionConfig
The default
IoSessionConfig which will be used to configure new sessions. |
Modifier | Constructor and Description |
---|---|
protected |
AbstractIoService(IoSessionConfig sessionConfig,
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. |
Set<WriteFuture> |
broadcast(Object message)
Writes the specified
message to all the IoSession s
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(Runnable worker) |
protected void |
executeWorker(Runnable worker,
String suffix) |
protected void |
finishSessionInitialization0(IoSession session,
IoFuture future)
Implement this method to perform additional tasks required for session
initialization.
|
long |
getActivationTime() |
DefaultIoFilterChainBuilder |
getFilterChain()
A shortcut for ( ( DefaultIoFilterChainBuilder )
IoService.getFilterChainBuilder() ). |
IoFilterChainBuilder |
getFilterChainBuilder() |
IoHandler |
getHandler() |
IoServiceListenerSupport |
getListeners() |
int |
getManagedSessionCount() |
Map<Long,IoSession> |
getManagedSessions() |
int |
getScheduledWriteBytes() |
int |
getScheduledWriteMessages() |
IoSessionDataStructureFactory |
getSessionDataStructureFactory() |
IoServiceStatistics |
getStatistics() |
protected void |
initSession(IoSession session,
IoFuture future,
IoSessionInitializer sessionInitializer) |
boolean |
isActive() |
boolean |
isDisposed() |
boolean |
isDisposing() |
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 IoSession s 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, wait
getSessionConfig, getTransportMetadata
protected static final org.slf4j.Logger LOGGER
protected final IoSessionConfig sessionConfig
IoSessionConfig
which will be used to configure new sessions.protected final Object disposalLock
protected AbstractIoService(IoSessionConfig sessionConfig, 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()
.public final IoFilterChainBuilder getFilterChainBuilder()
getFilterChainBuilder
in interface IoService
IoFilterChainBuilder
which will build the
IoFilterChain
of all IoSession
s which is created
by this service.
The default value is an empty DefaultIoFilterChainBuilder
.public final void setFilterChainBuilder(IoFilterChainBuilder builder)
IoFilterChainBuilder
which will build the
IoFilterChain
of all IoSession
s which is created
by this service.
If you specify null this property will be set to
an empty DefaultIoFilterChainBuilder
.setFilterChainBuilder
in interface IoService
builder
- The filter chain builder to usepublic 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 IoSession
s at all, because
IoFilterChainBuilder
s affect only newly created IoSession
s.getFilterChain
in interface IoService
public final void addListener(IoServiceListener listener)
IoServiceListener
that listens any events related with
this service.addListener
in interface IoService
listener
- The listener to addpublic final void removeListener(IoServiceListener listener)
IoServiceListener
that listens any events
related with this service.removeListener
in interface IoService
listener
- The listener to usepublic final boolean isActive()
public final boolean isDisposing()
isDisposing
in interface IoService
IoService.dispose()
method has
been called. Please note that this method will return true
even after all the related resources are released.public final boolean isDisposed()
isDisposed
in interface IoService
public final void dispose()
public final void dispose(boolean awaitTermination)
awaitTermination
= true
will probably lead to a deadlock.protected abstract void dispose0() throws Exception
dispose()
.Exception
- If the dispose failedpublic final Map<Long,IoSession> getManagedSessions()
getManagedSessions
in interface IoService
ID
of the
session. An empty collection if there's no session.public final int getManagedSessionCount()
getManagedSessionCount
in interface IoService
public final IoHandler getHandler()
getHandler
in interface IoService
public final void setHandler(IoHandler handler)
setHandler
in interface IoService
handler
- The IoHandler to usepublic final IoSessionDataStructureFactory getSessionDataStructureFactory()
getSessionDataStructureFactory
in interface IoService
IoSessionDataStructureFactory
that provides
related data structures for a new session created by this service.public final void setSessionDataStructureFactory(IoSessionDataStructureFactory sessionDataStructureFactory)
IoSessionDataStructureFactory
that provides
related data structures for a new session created by this service.setSessionDataStructureFactory
in interface IoService
sessionDataStructureFactory
- The factory to usepublic IoServiceStatistics getStatistics()
getStatistics
in interface IoService
public final long getActivationTime()
getActivationTime
in interface IoService
public final Set<WriteFuture> broadcast(Object message)
message
to all the IoSession
s
managed by this service. This method is a convenience shortcut for
IoUtil.broadcast(Object, Collection)
.public final IoServiceListenerSupport getListeners()
IoServiceListenerSupport
attached to this serviceprotected final void executeWorker(Runnable worker)
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.session
- The session to initializefuture
- The Future to usepublic int getScheduledWriteBytes()
getScheduledWriteBytes
in interface IoService
public int getScheduledWriteMessages()
getScheduledWriteMessages
in interface IoService
Copyright © 2004–2021 Apache MINA Project. All rights reserved.