public abstract class AbstractIoService extends java.lang.Object implements IoService
IoService
s.
An instance of IoService contains an Executor which will handle the incoming
events.限定符和类型 | 类和说明 |
---|---|
protected static class |
AbstractIoService.ServiceOperationFuture
A specific class used to
|
限定符和类型 | 字段和说明 |
---|---|
protected java.lang.Object |
disposalLock
A lock object which must be acquired when related resources are
destroyed.
|
protected IoSessionConfig |
sessionConfig
The default
IoSessionConfig which will be used to configure new sessions. |
限定符 | 构造器和说明 |
---|---|
protected |
AbstractIoService(IoSessionConfig sessionConfig,
java.util.concurrent.Executor executor)
Constructor for
AbstractIoService . |
限定符和类型 | 方法和说明 |
---|---|
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 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(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() |
DefaultIoFilterChainBuilder |
getFilterChain()
A shortcut for ( ( DefaultIoFilterChainBuilder )
IoService.getFilterChainBuilder() ). |
IoFilterChainBuilder |
getFilterChainBuilder() |
IoHandler |
getHandler() |
IoServiceListenerSupport |
getListeners() |
int |
getManagedSessionCount() |
java.util.Map<java.lang.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 final IoSessionConfig sessionConfig
IoSessionConfig
which will be used to configure new sessions.protected final java.lang.Object disposalLock
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 IoSession
executor
- the Executor
used for handling execution of I/O
events. Can be null
.public final IoFilterChainBuilder getFilterChainBuilder()
getFilterChainBuilder
在接口中 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
在接口中 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
在接口中 IoService
public final void addListener(IoServiceListener listener)
IoServiceListener
that listens any events related with
this service.addListener
在接口中 IoService
listener
- The listener to addpublic final void removeListener(IoServiceListener listener)
IoServiceListener
that listens any events
related with this service.removeListener
在接口中 IoService
listener
- The listener to usepublic final boolean isActive()
public final boolean isDisposing()
isDisposing
在接口中 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
在接口中 IoService
public 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.Exception
- If the dispose failedpublic final java.util.Map<java.lang.Long,IoSession> getManagedSessions()
getManagedSessions
在接口中 IoService
ID
of the
session. An empty collection if there's no session.public final int getManagedSessionCount()
getManagedSessionCount
在接口中 IoService
public final IoHandler getHandler()
getHandler
在接口中 IoService
public final void setHandler(IoHandler handler)
setHandler
在接口中 IoService
handler
- The IoHandler to usepublic final IoSessionDataStructureFactory getSessionDataStructureFactory()
getSessionDataStructureFactory
在接口中 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
在接口中 IoService
sessionDataStructureFactory
- The factory to usepublic IoServiceStatistics getStatistics()
getStatistics
在接口中 IoService
public final long getActivationTime()
getActivationTime
在接口中 IoService
public final java.util.Set<WriteFuture> broadcast(java.lang.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()
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.session
- The session to initializefuture
- The Future to usepublic int getScheduledWriteBytes()
getScheduledWriteBytes
在接口中 IoService
public int getScheduledWriteMessages()
getScheduledWriteMessages
在接口中 IoService