org.apache.mina.core.service
Class AbstractIoService

java.lang.Object
  extended by 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 of IoServices. An instance of IoService contains an Executor which will handle the incoming events.

Version:
$Rev: 684597 $, $Date: 2008-08-10 23:20:07 +0200 (dim, 10 aoĆ» 2008) $
Author:
The Apache MINA Project (dev@mina.apache.org)

Nested Class Summary
protected static class AbstractIoService.ServiceOperationFuture
           
 
Field Summary
protected  Object disposalLock
          A lock object which must be acquired when related resources are destroyed.
 
Constructor Summary
protected AbstractIoService(IoSessionConfig sessionConfig, Executor executor)
          Constructor for AbstractIoService.
 
Method Summary
 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 IoSessions managed by this service.
 void dispose()
          Releases any resources allocated by this service.
protected abstract  IoFuture dispose0()
          Implement this method to release any acquired resources.
protected  void executeWorker(Runnable worker)
           
protected  void executeWorker(Runnable worker, String suffix)
           
protected  void finishSessionInitialization(IoSession session, IoFuture future, IoSessionInitializer sessionInitializer)
           
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.
 IoServiceIdleState getIdleState()
          Returns the IoServiceIdleState for this service.
protected  IdleStatusChecker getIdleStatusChecker()
           
 IoServiceListenerSupport getListeners()
           
 int getManagedSessionCount()
          Returns the number of all sessions which are currently managed by this service.
 Map<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
 IoSessionConfig getSessionConfig()
          Returns the default configuration of the new IoSessions created by this service.
 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.
 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 notifyIdleness(long currentTime)
          TODO
 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.
 
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
getTransportMetadata
 

Field Detail

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 for 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().

Parameters:
sessionConfig - the default configuration for the managed IoSession
executor - the Executor used for handling execution of I/O events. Can be null.
Method Detail

getFilterChainBuilder

public final IoFilterChainBuilder getFilterChainBuilder()
Returns the IoFilterChainBuilder which will build the IoFilterChain of all IoSessions which is created by this service. The default value is an empty DefaultIoFilterChainBuilder.

Specified by:
getFilterChainBuilder in interface IoService

setFilterChainBuilder

public final void setFilterChainBuilder(IoFilterChainBuilder builder)
Sets the 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.

Specified by:
setFilterChainBuilder in interface IoService

getFilterChain

public final DefaultIoFilterChainBuilder getFilterChain()
A shortcut for ( ( DefaultIoFilterChainBuilder ) 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.

Specified by:
getFilterChain in interface IoService

addListener

public final void addListener(IoServiceListener listener)
Adds an IoServiceListener that listens any events related with this service.

Specified by:
addListener in interface IoService

removeListener

public final void removeListener(IoServiceListener listener)
Removed an existing IoServiceListener that listens any events related with this service.

Specified by:
removeListener in interface IoService

isActive

public final boolean isActive()
Returns a value of whether or not this service is active

Specified by:
isActive in interface IoService
Returns:
whether of not the service is active.

isDisposing

public final boolean isDisposing()
Returns true if and if only IoService.dispose() method has been called. Please note that this method will return true even after all the related resources are released.

Specified by:
isDisposing in interface IoService

isDisposed

public final boolean isDisposed()
Returns true if and if only all resources of this processor have been disposed.

Specified by:
isDisposed in interface IoService

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.

Specified by:
dispose in interface IoService

dispose0

protected abstract IoFuture dispose0()
                              throws Exception
Implement this method to release any acquired resources. This method is invoked only once by dispose().

Throws:
Exception

getManagedSessions

public final Map<Long,IoSession> getManagedSessions()
Returns the map of all sessions which are currently managed by this service. The key of map is the ID of the session.

Specified by:
getManagedSessions in interface IoService
Returns:
the sessions. An empty collection if there's no session.

getManagedSessionCount

public final int getManagedSessionCount()
Returns the number of all sessions which are currently managed by this service.

Specified by:
getManagedSessionCount in interface IoService

getHandler

public final IoHandler getHandler()
Returns the handler which will handle all connections managed by this service.

Specified by:
getHandler in interface IoService

setHandler

public final void setHandler(IoHandler handler)
Sets the handler which will handle all connections managed by this service.

Specified by:
setHandler in interface IoService

getSessionConfig

public IoSessionConfig getSessionConfig()
Returns the default configuration of the new IoSessions created by this service.

Specified by:
getSessionConfig in interface IoService

getSessionDataStructureFactory

public final IoSessionDataStructureFactory getSessionDataStructureFactory()
Returns the IoSessionDataStructureFactory that provides related data structures for a new session created by this service.

Specified by:
getSessionDataStructureFactory in interface IoService

setSessionDataStructureFactory

public final void setSessionDataStructureFactory(IoSessionDataStructureFactory sessionDataStructureFactory)
Sets the IoSessionDataStructureFactory that provides related data structures for a new session created by this service.

Specified by:
setSessionDataStructureFactory in interface IoService

getIdleState

public IoServiceIdleState getIdleState()
Returns the IoServiceIdleState for this service.

Specified by:
getIdleState in interface IoService
Returns:
The idle state object for this service.

getStatistics

public IoServiceStatistics getStatistics()
Returns the IoServiceStatistics object for this service.

Specified by:
getStatistics in interface IoService
Returns:
The statistics object for this service.

getActivationTime

public final long getActivationTime()
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.

Specified by:
getActivationTime in interface IoService
Returns:
The time by using System.currentTimeMillis()

broadcast

public final Set<WriteFuture> broadcast(Object message)
Writes the specified message to all the IoSessions managed by this service. This method is a convenience shortcut for IoUtil.broadcast(Object, Collection).

Specified by:
broadcast in interface IoService

getListeners

public final IoServiceListenerSupport getListeners()

getIdleStatusChecker

protected final IdleStatusChecker getIdleStatusChecker()

executeWorker

protected final void executeWorker(Runnable worker)

executeWorker

protected final void executeWorker(Runnable worker,
                                   String suffix)

finishSessionInitialization

protected final void finishSessionInitialization(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; finishSessionInitialization(IoSession, IoFuture, IoSessionInitializer) will call this method instead.


getScheduledWriteBytes

public int getScheduledWriteBytes()
Returns the number of bytes scheduled to be written

Specified by:
getScheduledWriteBytes in interface IoService
Returns:
The number of bytes scheduled to be written

getScheduledWriteMessages

public int getScheduledWriteMessages()
Returns the number of messages scheduled to be written

Specified by:
getScheduledWriteMessages in interface IoService
Returns:
The number of messages scheduled to be written

notifyIdleness

public void notifyIdleness(long currentTime)
TODO



Copyright © 2004-2008 Apache MINA Project. All Rights Reserved.