org.apache.mina.transport.socket.nio
Class NioSocketAcceptor

java.lang.Object
  extended by org.apache.mina.core.service.AbstractIoService
      extended by org.apache.mina.core.service.AbstractIoAcceptor
          extended by org.apache.mina.core.polling.AbstractPollingIoAcceptor<NioSession,ServerSocketChannel>
              extended by org.apache.mina.transport.socket.nio.NioSocketAcceptor
All Implemented Interfaces:
IoAcceptor, IoService, SocketAcceptor

public final class NioSocketAcceptor
extends AbstractPollingIoAcceptor<NioSession,ServerSocketChannel>
implements SocketAcceptor

IoAcceptor for socket transport (TCP/IP). This class handles incoming TCP/IP based socket connections.

Author:
Apache MINA Project

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.mina.core.service.AbstractIoAcceptor
AbstractIoAcceptor.AcceptorOperationFuture
 
Nested classes/interfaces inherited from class org.apache.mina.core.service.AbstractIoService
AbstractIoService.ServiceOperationFuture
 
Field Summary
 
Fields inherited from class org.apache.mina.core.polling.AbstractPollingIoAcceptor
backlog, reuseAddress
 
Fields inherited from class org.apache.mina.core.service.AbstractIoAcceptor
bindLock
 
Fields inherited from class org.apache.mina.core.service.AbstractIoService
disposalLock
 
Constructor Summary
NioSocketAcceptor()
          Constructor for NioSocketAcceptor using default parameters (multiple thread model).
NioSocketAcceptor(Executor executor, IoProcessor<NioSession> processor)
          Constructor for NioSocketAcceptor with a given Executor for handling connection events and a given IoProcessor for handling I/O events, useful for sharing the same processor and executor over multiple IoService of the same type.
NioSocketAcceptor(int processorCount)
          Constructor for NioSocketAcceptor using default parameters, and given number of NioProcessor for multithreading I/O operations.
NioSocketAcceptor(IoProcessor<NioSession> processor)
          Constructor for NioSocketAcceptor with default configuration but a specific IoProcessor, useful for sharing the same processor over multiple IoService of the same type.
 
Method Summary
protected  NioSession accept(IoProcessor<NioSession> processor, ServerSocketChannel handle)
          Accept a client connection for a server socket and return a new IoSession associated with the given IoProcessor
protected  void close(ServerSocketChannel handle)
          Close a server socket.
protected  void destroy()
          Destroy the polling system, will be called when this IoAcceptor implementation will be disposed.
 InetSocketAddress getDefaultLocalAddress()
          Returns the default local address to bind when no argument is specified in IoAcceptor.bind() method.
 InetSocketAddress getLocalAddress()
          Returns the local address which is bound currently.
 SocketSessionConfig getSessionConfig()
          Returns the default configuration of the new IoSessions created by this service.
 TransportMetadata getTransportMetadata()
          Returns the TransportMetadata that this service runs on.
protected  void init()
          Initialize the polling system, will be called at construction time.
protected  SocketAddress localAddress(ServerSocketChannel handle)
          Get the local address associated with a given server socket
protected  ServerSocketChannel open(SocketAddress localAddress)
          Open a server socket for a given local address.
protected  int select()
          Check if we have at least one key whose corresponding channels is ready for I/O operations.
protected  Iterator<ServerSocketChannel> selectedHandles()
          Iterator for the set of server sockets found with acceptable incoming connections during the last AbstractPollingIoAcceptor.select() call.
 void setDefaultLocalAddress(InetSocketAddress localAddress)
          
protected  void wakeup()
          Interrupt the AbstractPollingIoAcceptor.select() method.
 
Methods inherited from class org.apache.mina.core.polling.AbstractPollingIoAcceptor
bindInternal, dispose0, getBacklog, isReuseAddress, newSession, setBacklog, setReuseAddress, unbind0
 
Methods inherited from class org.apache.mina.core.service.AbstractIoAcceptor
bind, bind, bind, bind, getDefaultLocalAddresses, getLocalAddresses, isCloseOnDeactivation, setCloseOnDeactivation, setDefaultLocalAddress, setDefaultLocalAddresses, setDefaultLocalAddresses, setDefaultLocalAddresses, toString, unbind, unbind, unbind, unbind
 
Methods inherited from class org.apache.mina.core.service.AbstractIoService
addListener, broadcast, dispose, dispose, executeWorker, executeWorker, finishSessionInitialization0, getActivationTime, getFilterChain, getFilterChainBuilder, getHandler, getListeners, getManagedSessionCount, getManagedSessions, getScheduledWriteBytes, getScheduledWriteMessages, 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.transport.socket.SocketAcceptor
getBacklog, isReuseAddress, setBacklog, setReuseAddress
 
Methods inherited from interface org.apache.mina.core.service.IoAcceptor
bind, bind, bind, getDefaultLocalAddresses, getLocalAddresses, isCloseOnDeactivation, newSession, setCloseOnDeactivation, setDefaultLocalAddress, setDefaultLocalAddresses, setDefaultLocalAddresses, setDefaultLocalAddresses, unbind, unbind, unbind, unbind
 
Methods inherited from interface org.apache.mina.core.service.IoService
addListener, broadcast, dispose, dispose, getActivationTime, getFilterChain, getFilterChainBuilder, getHandler, getManagedSessionCount, getManagedSessions, getScheduledWriteBytes, getScheduledWriteMessages, getSessionDataStructureFactory, getStatistics, isActive, isDisposed, isDisposing, removeListener, setFilterChainBuilder, setHandler, setSessionDataStructureFactory
 

Constructor Detail

NioSocketAcceptor

public NioSocketAcceptor()
Constructor for NioSocketAcceptor using default parameters (multiple thread model).


NioSocketAcceptor

public NioSocketAcceptor(int processorCount)
Constructor for NioSocketAcceptor using default parameters, and given number of NioProcessor for multithreading I/O operations.

Parameters:
processorCount - the number of processor to create and place in a SimpleIoProcessorPool

NioSocketAcceptor

public NioSocketAcceptor(IoProcessor<NioSession> processor)
Constructor for NioSocketAcceptor with default configuration but a specific IoProcessor, useful for sharing the same processor over multiple IoService of the same type.

Parameters:
processor - the processor to use for managing I/O events

NioSocketAcceptor

public NioSocketAcceptor(Executor executor,
                         IoProcessor<NioSession> processor)
Constructor for NioSocketAcceptor with a given Executor for handling connection events and a given IoProcessor for handling I/O events, useful for sharing the same processor and executor over multiple IoService of the same type.

Parameters:
executor - the executor for connection
processor - the processor for I/O operations
Method Detail

init

protected void init()
             throws Exception
Initialize the polling system, will be called at construction time.

Specified by:
init in class AbstractPollingIoAcceptor<NioSession,ServerSocketChannel>
Throws:
Exception - any exception thrown by the underlying system calls

destroy

protected void destroy()
                throws Exception
Destroy the polling system, will be called when this IoAcceptor implementation will be disposed.

Specified by:
destroy in class AbstractPollingIoAcceptor<NioSession,ServerSocketChannel>
Throws:
Exception - any exception thrown by the underlying systems calls

getTransportMetadata

public TransportMetadata getTransportMetadata()
Returns the TransportMetadata that this service runs on.

Specified by:
getTransportMetadata in interface IoService

getSessionConfig

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

Specified by:
getSessionConfig in interface IoService
Specified by:
getSessionConfig in interface SocketAcceptor
Overrides:
getSessionConfig in class AbstractIoService

getLocalAddress

public InetSocketAddress 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
Specified by:
getLocalAddress in interface SocketAcceptor
Overrides:
getLocalAddress in class AbstractIoAcceptor

getDefaultLocalAddress

public InetSocketAddress 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
Specified by:
getDefaultLocalAddress in interface SocketAcceptor
Overrides:
getDefaultLocalAddress in class AbstractIoAcceptor

setDefaultLocalAddress

public void setDefaultLocalAddress(InetSocketAddress localAddress)

Specified by:
setDefaultLocalAddress in interface SocketAcceptor

accept

protected NioSession accept(IoProcessor<NioSession> processor,
                            ServerSocketChannel handle)
                     throws Exception
Accept a client connection for a server socket and return a new IoSession associated with the given IoProcessor

Specified by:
accept in class AbstractPollingIoAcceptor<NioSession,ServerSocketChannel>
Parameters:
processor - the IoProcessor to associate with the IoSession
handle - the server handle
Returns:
the created IoSession
Throws:
Exception - any exception thrown by the underlying systems calls

open

protected ServerSocketChannel open(SocketAddress localAddress)
                            throws Exception
Open a server socket for a given local address.

Specified by:
open in class AbstractPollingIoAcceptor<NioSession,ServerSocketChannel>
Parameters:
localAddress - the associated local address
Returns:
the opened server socket
Throws:
Exception - any exception thrown by the underlying systems calls

localAddress

protected SocketAddress localAddress(ServerSocketChannel handle)
                              throws Exception
Get the local address associated with a given server socket

Specified by:
localAddress in class AbstractPollingIoAcceptor<NioSession,ServerSocketChannel>
Parameters:
handle - the server socket
Returns:
the local SocketAddress associated with this handle
Throws:
Exception - any exception thrown by the underlying systems calls

select

protected int select()
              throws Exception
Check if we have at least one key whose corresponding channels is ready for I/O operations. This method performs a blocking selection operation. It returns only after at least one channel is selected, this selector's wakeup method is invoked, or the current thread is interrupted, whichever comes first.

Specified by:
select in class AbstractPollingIoAcceptor<NioSession,ServerSocketChannel>
Returns:
The number of keys having their ready-operation set updated
Throws:
IOException - If an I/O error occurs
ClosedSelectorException - If this selector is closed
Exception - any exception thrown by the underlying systems calls

selectedHandles

protected Iterator<ServerSocketChannel> selectedHandles()
Iterator for the set of server sockets found with acceptable incoming connections during the last AbstractPollingIoAcceptor.select() call.

Specified by:
selectedHandles in class AbstractPollingIoAcceptor<NioSession,ServerSocketChannel>
Returns:
the list of server handles ready

close

protected void close(ServerSocketChannel handle)
              throws Exception
Close a server socket.

Specified by:
close in class AbstractPollingIoAcceptor<NioSession,ServerSocketChannel>
Parameters:
handle - the server socket
Throws:
Exception - any exception thrown by the underlying systems calls

wakeup

protected void wakeup()
Interrupt the AbstractPollingIoAcceptor.select() method. Used when the poll set need to be modified.

Specified by:
wakeup in class AbstractPollingIoAcceptor<NioSession,ServerSocketChannel>


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