Package org.apache.mina.core.service
Interface IoAcceptor
-
- All Superinterfaces:
IoService
- All Known Subinterfaces:
DatagramAcceptor
,SocketAcceptor
- All Known Implementing Classes:
AbstractIoAcceptor
,AbstractPollingIoAcceptor
,AprSocketAcceptor
,NioDatagramAcceptor
,NioSocketAcceptor
,VmPipeAcceptor
public interface IoAcceptor extends IoService
Accepts incoming connection, communicates with clients, and fires events toIoHandler
s.Please refer to EchoServer example.
You should bind to the desired socket address to accept incoming connections, and then events for incoming connections will be sent to the specified default
IoHandler
.Threads accept incoming connections start automatically when
bind()
is invoked, and stop whenunbind()
is invoked.- Author:
- Apache MINA Project
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description 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 localAddress)
Binds to the specified local address 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 firstLocalAddress, SocketAddress... addresses)
Binds to the specified local addresses and start to accept incoming connections.SocketAddress
getDefaultLocalAddress()
Returns the default local address to bind when no argument is specified inbind()
method.List<SocketAddress>
getDefaultLocalAddresses()
SocketAddress
getLocalAddress()
Returns the local address which is bound currently.Set<SocketAddress>
getLocalAddresses()
Returns aSet
of the local addresses which are bound currently.boolean
isCloseOnDeactivation()
Returnstrue
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).IoSession
newSession(SocketAddress remoteAddress, SocketAddress localAddress)
(Optional) Returns anIoSession
that is bound to the specifiedlocalAddress
and the specifiedremoteAddress
which reuses the local address that is already bound by this service.void
setCloseOnDeactivation(boolean closeOnDeactivation)
Sets whether all client sessions are closed when this acceptor unbinds from all the related local addresses (i.e. when the service is deactivated).void
setDefaultLocalAddress(SocketAddress localAddress)
Sets the default local address to bind when no argument is specified inbind()
method.void
setDefaultLocalAddresses(Iterable<? extends SocketAddress> localAddresses)
Sets the default local addresses to bind when no argument is specified inbind()
method.void
setDefaultLocalAddresses(SocketAddress firstLocalAddress, SocketAddress... otherLocalAddresses)
Sets the default local addresses to bind when no argument is specified inbind()
method.void
setDefaultLocalAddresses(List<? extends SocketAddress> localAddresses)
Sets the default local addresses to bind when no argument is specified inbind()
method.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.-
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
-
-
-
-
Method Detail
-
getLocalAddress
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.- Returns:
- The bound LocalAddress
-
getLocalAddresses
Set<SocketAddress> getLocalAddresses()
Returns aSet
of the local addresses which are bound currently.- Returns:
- The Set of bound LocalAddresses
-
getDefaultLocalAddress
SocketAddress getDefaultLocalAddress()
Returns the default local address to bind when no argument is specified inbind()
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 insetDefaultLocalAddresses(List)
.- Returns:
- The default bound LocalAddress
-
getDefaultLocalAddresses
List<SocketAddress> getDefaultLocalAddresses()
Returns aList
of the default local addresses to bind when no argument is specified inbind()
method. Please note that the default will not be used if any local address is specified.- Returns:
- The list of default bound LocalAddresses
-
setDefaultLocalAddress
void setDefaultLocalAddress(SocketAddress localAddress)
Sets the default local address to bind when no argument is specified inbind()
method. Please note that the default will not be used if any local address is specified.- Parameters:
localAddress
- The local addresses to bind the acceptor on
-
setDefaultLocalAddresses
void setDefaultLocalAddresses(SocketAddress firstLocalAddress, SocketAddress... otherLocalAddresses)
Sets the default local addresses to bind when no argument is specified inbind()
method. Please note that the default will not be used if any local address is specified.- Parameters:
firstLocalAddress
- The first local address to bind the acceptor onotherLocalAddresses
- The other local addresses to bind the acceptor on
-
setDefaultLocalAddresses
void setDefaultLocalAddresses(Iterable<? extends SocketAddress> localAddresses)
Sets the default local addresses to bind when no argument is specified inbind()
method. Please note that the default will not be used if any local address is specified.- Parameters:
localAddresses
- The local addresses to bind the acceptor on
-
setDefaultLocalAddresses
void setDefaultLocalAddresses(List<? extends SocketAddress> localAddresses)
Sets the default local addresses to bind when no argument is specified inbind()
method. Please note that the default will not be used if any local address is specified.- Parameters:
localAddresses
- The local addresses to bind the acceptor on
-
isCloseOnDeactivation
boolean isCloseOnDeactivation()
Returnstrue
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).- Returns:
true
if the service sets the closeOnDeactivation flag
-
setCloseOnDeactivation
void setCloseOnDeactivation(boolean closeOnDeactivation)
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 istrue
.- Parameters:
closeOnDeactivation
-true
if we should close on deactivation
-
bind
void bind() throws IOException
Binds to the default local address(es) and start to accept incoming connections.- Throws:
IOException
- if failed to bind
-
bind
void bind(SocketAddress localAddress) throws IOException
Binds to the specified local address and start to accept incoming connections.- Parameters:
localAddress
- The SocketAddress to bind to- Throws:
IOException
- if failed to bind
-
bind
void bind(SocketAddress firstLocalAddress, 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.- Parameters:
firstLocalAddress
- The first address to bind toaddresses
- The SocketAddresses to bind to- Throws:
IOException
- if failed to bind
-
bind
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.- Parameters:
addresses
- The SocketAddresses to bind to- Throws:
IOException
- if failed to bind
-
bind
void bind(Iterable<? extends SocketAddress> localAddresses) throws IOException
Binds to the specified local addresses and start to accept incoming connections.- Parameters:
localAddresses
- The local address we will be bound to- Throws:
IOException
- if failed to bind
-
unbind
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 ifdisconnectOnUnbind
property istrue
. This method returns silently if no local address is bound yet.
-
unbind
void unbind(SocketAddress localAddress)
Unbinds from the specified local address and stop to accept incoming connections. All managed connections will be closed ifdisconnectOnUnbind
property istrue
. This method returns silently if the default local address is not bound yet.- Parameters:
localAddress
- The local address we will be unbound from
-
unbind
void unbind(SocketAddress firstLocalAddress, SocketAddress... otherLocalAddresses)
Unbinds from the specified local addresses and stop to accept incoming connections. All managed connections will be closed ifdisconnectOnUnbind
property istrue
. This method returns silently if the default local addresses are not bound yet.- Parameters:
firstLocalAddress
- The first local address to be unbound fromotherLocalAddresses
- The other local address to be unbound from
-
unbind
void unbind(Iterable<? extends SocketAddress> localAddresses)
Unbinds from the specified local addresses and stop to accept incoming connections. All managed connections will be closed ifdisconnectOnUnbind
property istrue
. This method returns silently if the default local addresses are not bound yet.- Parameters:
localAddresses
- The local address we will be unbound from
-
newSession
IoSession newSession(SocketAddress remoteAddress, SocketAddress localAddress)
(Optional) Returns anIoSession
that is bound to the specifiedlocalAddress
and the specifiedremoteAddress
which reuses the local address that is already bound by this service.This operation is optional. Please throw
UnsupportedOperationException
if the transport type doesn't support this operation. This operation is usually implemented for connectionless transport types.- Parameters:
remoteAddress
- The remote address bound to the servicelocalAddress
- The local address the session will be bound to- Returns:
- The session bound to the the given localAddress and remote address
- Throws:
UnsupportedOperationException
- if this operation is not supportedIllegalStateException
- if this service is not running.IllegalArgumentException
- if this service is not bound to the specifiedlocalAddress
.
-
-