org.apache.mina.core.service
Class AbstractIoAcceptor

java.lang.Object
  extended by org.apache.mina.core.service.AbstractIoService
      extended by org.apache.mina.core.service.AbstractIoAcceptor
All Implemented Interfaces:
IoAcceptor, IoService
Direct Known Subclasses:
AbstractPollingConnectionlessIoAcceptor, AbstractPollingIoAcceptor, VmPipeAcceptor

public abstract class AbstractIoAcceptor
extends AbstractIoService
implements IoAcceptor

A base implementation of IoAcceptor.

Author:
Apache MINA Project

Nested Class Summary
static class AbstractIoAcceptor.AcceptorOperationFuture
           
 
Nested classes/interfaces inherited from class org.apache.mina.core.service.AbstractIoService
AbstractIoService.ServiceOperationFuture
 
Field Summary
protected  Object bindLock
          The lock object which is acquired while bind or unbind operation is performed.
 
Fields inherited from class org.apache.mina.core.service.AbstractIoService
disposalLock
 
Constructor Summary
protected AbstractIoAcceptor(IoSessionConfig sessionConfig, Executor executor)
          Constructor for AbstractIoAcceptor.
 
Method Summary
 void bind()
          Binds to the default local address(es) and start to accept incoming connections.
 void bind(Iterable<? extends SocketAddress> localAddresses)
          Binds to the specified local addresses and start to accept incoming connections.
 void bind(SocketAddress... addresses)
          Binds to the specified local addresses and start to accept incoming connections.
 void bind(SocketAddress localAddress)
          
protected abstract  Set<SocketAddress> bindInternal(List<? extends SocketAddress> localAddresses)
          Starts the acceptor, and register the given addresses
 SocketAddress getDefaultLocalAddress()
          Returns the default local address to bind when no argument is specified in IoAcceptor.bind() method.
 List<SocketAddress> getDefaultLocalAddresses()
          Returns a List of the default local addresses to bind when no argument is specified in IoAcceptor.bind() method.
 SocketAddress getLocalAddress()
          Returns the local address which is bound currently.
 Set<SocketAddress> getLocalAddresses()
          Returns a Set of the local addresses which are bound currently.
 boolean isCloseOnDeactivation()
          Returns true if and only if all clients are closed when this acceptor unbinds from all the related local address (i.e.
 void setCloseOnDeactivation(boolean disconnectClientsOnUnbind)
          Sets whether all client sessions are closed when this acceptor unbinds from all the related local addresses (i.e.
 void setDefaultLocalAddress(SocketAddress localAddress)
          Sets the default local address to bind when no argument is specified in IoAcceptor.bind() method.
 void setDefaultLocalAddresses(Iterable<? extends SocketAddress> localAddresses)
          Sets the default local addresses to bind when no argument is specified in IoAcceptor.bind() method.
 void setDefaultLocalAddresses(List<? extends SocketAddress> localAddresses)
          Sets the default local addresses to bind when no argument is specified in IoAcceptor.bind() method.
 void setDefaultLocalAddresses(SocketAddress firstLocalAddress, SocketAddress... otherLocalAddresses)
          Sets the default local addresses to bind when no argument is specified in IoAcceptor.bind() method.
 String toString()
           
 void unbind()
          Unbinds from all local addresses that this service is bound to and stops to accept incoming connections.
 void unbind(Iterable<? extends SocketAddress> localAddresses)
          Unbinds from the specified local addresses and stop to accept incoming connections.
 void unbind(SocketAddress localAddress)
          Unbinds from the specified local address and stop to accept incoming connections.
 void unbind(SocketAddress firstLocalAddress, SocketAddress... otherLocalAddresses)
          Unbinds from the specified local addresses and stop to accept incoming connections.
protected abstract  void unbind0(List<? extends SocketAddress> localAddresses)
          Implement this method to perform the actual unbind operation.
 
Methods inherited from class org.apache.mina.core.service.AbstractIoService
addListener, broadcast, dispose, dispose, dispose0, executeWorker, executeWorker, finishSessionInitialization0, getActivationTime, getFilterChain, getFilterChainBuilder, getHandler, getListeners, getManagedSessionCount, getManagedSessions, getScheduledWriteBytes, getScheduledWriteMessages, getSessionConfig, getSessionDataStructureFactory, getStatistics, initSession, isActive, isDisposed, isDisposing, removeListener, setFilterChainBuilder, setHandler, setSessionDataStructureFactory
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.mina.core.service.IoAcceptor
newSession
 
Methods inherited from interface org.apache.mina.core.service.IoService
addListener, broadcast, dispose, dispose, getActivationTime, getFilterChain, getFilterChainBuilder, getHandler, getManagedSessionCount, getManagedSessions, getScheduledWriteBytes, getScheduledWriteMessages, getSessionConfig, getSessionDataStructureFactory, getStatistics, getTransportMetadata, isActive, isDisposed, isDisposing, removeListener, setFilterChainBuilder, setHandler, setSessionDataStructureFactory
 

Field Detail

bindLock

protected final Object bindLock
The lock object which is acquired while bind or unbind operation is performed. Acquire this lock in your property setters which shouldn't be changed while the service is bound.

Constructor Detail

AbstractIoAcceptor

protected AbstractIoAcceptor(IoSessionConfig sessionConfig,
                             Executor executor)
Constructor for AbstractIoAcceptor. You need to provide a default session configuration and an Executor for handling I/O events. If null Executor is provided, a default one will be created using Executors.newCachedThreadPool(). AbstractIoService.AbstractIoService(IoSessionConfig, Executor)

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

getLocalAddress

public SocketAddress getLocalAddress()
Returns the local address which is bound currently. If more than one address are bound, only one of them will be returned, but it's not necessarily the firstly bound address.

Specified by:
getLocalAddress in interface IoAcceptor

getLocalAddresses

public final Set<SocketAddress> getLocalAddresses()
Returns a Set of the local addresses which are bound currently.

Specified by:
getLocalAddresses in interface IoAcceptor

getDefaultLocalAddress

public SocketAddress getDefaultLocalAddress()
Returns the default local address to bind when no argument is specified in IoAcceptor.bind() method. Please note that the default will not be used if any local address is specified. If more than one address are set, only one of them will be returned, but it's not necessarily the firstly specified address in IoAcceptor.setDefaultLocalAddresses(List).

Specified by:
getDefaultLocalAddress in interface IoAcceptor

setDefaultLocalAddress

public final void setDefaultLocalAddress(SocketAddress localAddress)
Sets the default local address to bind when no argument is specified in IoAcceptor.bind() method. Please note that the default will not be used if any local address is specified.

Specified by:
setDefaultLocalAddress in interface IoAcceptor

getDefaultLocalAddresses

public final List<SocketAddress> getDefaultLocalAddresses()
Returns a List of the default local addresses to bind when no argument is specified in IoAcceptor.bind() method. Please note that the default will not be used if any local address is specified.

Specified by:
getDefaultLocalAddresses in interface IoAcceptor

setDefaultLocalAddresses

public final void setDefaultLocalAddresses(List<? extends SocketAddress> localAddresses)
Sets the default local addresses to bind when no argument is specified in IoAcceptor.bind() method. Please note that the default will not be used if any local address is specified.

Specified by:
setDefaultLocalAddresses in interface IoAcceptor

setDefaultLocalAddresses

public final void setDefaultLocalAddresses(Iterable<? extends SocketAddress> localAddresses)
Sets the default local addresses to bind when no argument is specified in IoAcceptor.bind() method. Please note that the default will not be used if any local address is specified.

Specified by:
setDefaultLocalAddresses in interface IoAcceptor

setDefaultLocalAddresses

public final void setDefaultLocalAddresses(SocketAddress firstLocalAddress,
                                           SocketAddress... otherLocalAddresses)
Sets the default local addresses to bind when no argument is specified in IoAcceptor.bind() method. Please note that the default will not be used if any local address is specified.

Specified by:
setDefaultLocalAddresses in interface IoAcceptor

isCloseOnDeactivation

public final boolean isCloseOnDeactivation()
Returns true if and only if all clients are closed when this acceptor unbinds from all the related local address (i.e. when the service is deactivated).

Specified by:
isCloseOnDeactivation in interface IoAcceptor

setCloseOnDeactivation

public final void setCloseOnDeactivation(boolean disconnectClientsOnUnbind)
Sets whether all client sessions are closed when this acceptor unbinds from all the related local addresses (i.e. when the service is deactivated). The default value is true.

Specified by:
setCloseOnDeactivation in interface IoAcceptor

bind

public final void bind()
                throws IOException
Binds to the default local address(es) and start to accept incoming connections.

Specified by:
bind in interface IoAcceptor
Throws:
IOException - if failed to bind

bind

public final void bind(SocketAddress localAddress)
                throws IOException

Throws:
IOException

bind

public final void bind(SocketAddress... addresses)
                throws IOException
Binds to the specified local addresses and start to accept incoming connections. If no address is given, bind on the default local address.

Specified by:
bind in interface IoAcceptor
Parameters:
addresses - The SocketAddresses to bind to
Throws:
IOException - if failed to bind

bind

public final void bind(Iterable<? extends SocketAddress> localAddresses)
                throws IOException
Binds to the specified local addresses and start to accept incoming connections.

Specified by:
bind in interface IoAcceptor
Throws:
IOException - if failed to bind

unbind

public final void unbind()
Unbinds from all local addresses that this service is bound to and stops to accept incoming connections. All managed connections will be closed if disconnectOnUnbind property is true. This method returns silently if no local address is bound yet.

Specified by:
unbind in interface IoAcceptor

unbind

public final void unbind(SocketAddress localAddress)
Unbinds from the specified local address and stop to accept incoming connections. All managed connections will be closed if disconnectOnUnbind property is true. This method returns silently if the default local address is not bound yet.

Specified by:
unbind in interface IoAcceptor

unbind

public final void unbind(SocketAddress firstLocalAddress,
                         SocketAddress... otherLocalAddresses)
Unbinds from the specified local addresses and stop to accept incoming connections. All managed connections will be closed if disconnectOnUnbind property is true. This method returns silently if the default local addresses are not bound yet.

Specified by:
unbind in interface IoAcceptor

unbind

public final void unbind(Iterable<? extends SocketAddress> localAddresses)
Unbinds from the specified local addresses and stop to accept incoming connections. All managed connections will be closed if disconnectOnUnbind property is true. This method returns silently if the default local addresses are not bound yet.

Specified by:
unbind in interface IoAcceptor

bindInternal

protected abstract Set<SocketAddress> bindInternal(List<? extends SocketAddress> localAddresses)
                                            throws Exception
Starts the acceptor, and register the given addresses

Returns:
the Set of the local addresses which is bound actually
Throws:
Exception

unbind0

protected abstract void unbind0(List<? extends SocketAddress> localAddresses)
                         throws Exception
Implement this method to perform the actual unbind operation.

Throws:
Exception

toString

public String toString()
Overrides:
toString in class Object


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