Class AbstractIoAcceptor
java.lang.Object
org.apache.mina.core.service.AbstractIoService
org.apache.mina.core.service.AbstractIoAcceptor
- All Implemented Interfaces:
IoAcceptor, IoService
- Direct Known Subclasses:
AbstractPollingIoAcceptor, NioDatagramAcceptor, VmPipeAcceptor
A base implementation of
IoAcceptor.-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class AbstractIoService
AbstractIoService.ServiceOperationFuture -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final ObjectThe lock object which is acquired while bind or unbind operation is performed.private final Set<SocketAddress> private final List<SocketAddress> private booleanprivate final List<SocketAddress> Fields inherited from class AbstractIoService
disposalLock, LOGGER, sessionConfig -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractIoAcceptor(IoSessionConfig sessionConfig, Executor executor) Constructor forAbstractIoAcceptor. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidbind()Binds to the default local address(es) and start to accept incoming connections.final voidbind(Iterable<? extends SocketAddress> localAddresses) Binds to the specified local addresses and start to accept incoming connections.final voidbind(SocketAddress localAddress) Binds to the specified local address and start to accept incoming connections.final voidbind(SocketAddress... addresses) Binds to the specified local addresses and start to accept incoming connections.final voidbind(SocketAddress firstLocalAddress, SocketAddress... addresses) Binds to the specified local addresses and start to accept incoming connections.protected abstract Set<SocketAddress> bindInternal(List<? extends SocketAddress> localAddresses) Starts the acceptor, and register the given addressesprivate voidReturns the default local address to bind when no argument is specified inIoAcceptor.bind()method.final List<SocketAddress> Returns aListof the default local addresses to bind when no argument is specified inIoAcceptor.bind()method.Returns the local address which is bound currently.final Set<SocketAddress> Returns aSetof the local addresses which are bound currently.final booleanReturnstrueif and only if all clients are closed when this acceptor unbinds from all the related local address (i.e.final voidsetCloseOnDeactivation(boolean disconnectClientsOnUnbind) Sets whether all client sessions are closed when this acceptor unbinds from all the related local addresses (i.e.final voidsetDefaultLocalAddress(SocketAddress localAddress) Sets the default local address to bind when no argument is specified inIoAcceptor.bind()method.final voidsetDefaultLocalAddresses(Iterable<? extends SocketAddress> localAddresses) Sets the default local addresses to bind when no argument is specified inIoAcceptor.bind()method.final voidsetDefaultLocalAddresses(SocketAddress firstLocalAddress, SocketAddress... otherLocalAddresses) Sets the default local addresses to bind when no argument is specified inIoAcceptor.bind()method.final voidsetDefaultLocalAddresses(List<? extends SocketAddress> localAddresses) Sets the default local addresses to bind when no argument is specified inIoAcceptor.bind()method.toString()final voidunbind()Unbinds from all local addresses that this service is bound to and stops to accept incoming connections.final voidunbind(Iterable<? extends SocketAddress> localAddresses) Unbinds from the specified local addresses and stop to accept incoming connections.final voidunbind(SocketAddress localAddress) Unbinds from the specified local address and stop to accept incoming connections.final voidunbind(SocketAddress firstLocalAddress, SocketAddress... otherLocalAddresses) Unbinds from the specified local addresses and stop to accept incoming connections.protected abstract voidunbind0(List<? extends SocketAddress> localAddresses) Implement this method to perform the actual unbind operation.Methods inherited from class AbstractIoService
addListener, broadcast, dispose, dispose, dispose0, executeWorker, executeWorker, finishSessionInitialization0, getActivationTime, getFilterChain, getFilterChainBuilder, getHandler, getListeners, getManagedSessionCount, getManagedSessions, getScheduledWriteBytes, getScheduledWriteMessages, getSessionDataStructureFactory, getStatistics, initSession, isActive, isDisposed, isDisposing, removeListener, setFilterChainBuilder, setHandler, setSessionDataStructureFactoryMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface IoAcceptor
newSessionMethods inherited from interface 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 Details
-
defaultLocalAddresses
-
unmodifiableDefaultLocalAddresses
-
boundAddresses
-
disconnectOnUnbind
private boolean disconnectOnUnbind -
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 Details
-
AbstractIoAcceptor
Constructor forAbstractIoAcceptor. You need to provide a default session configuration and anExecutorfor handling I/O events. If nullExecutoris provided, a default one will be created usingExecutors.newCachedThreadPool().
-
-
Method Details
-
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:
getLocalAddressin interfaceIoAcceptor- Returns:
- The bound LocalAddress
-
getLocalAddresses
Returns aSetof the local addresses which are bound currently.- Specified by:
getLocalAddressesin interfaceIoAcceptor- Returns:
- The Set of bound LocalAddresses
-
getDefaultLocalAddress
Returns the default local address to bind when no argument is specified inIoAcceptor.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 inIoAcceptor.setDefaultLocalAddresses(List).- Specified by:
getDefaultLocalAddressin interfaceIoAcceptor- Returns:
- The default bound LocalAddress
-
setDefaultLocalAddress
Sets the default local address to bind when no argument is specified inIoAcceptor.bind()method. Please note that the default will not be used if any local address is specified.- Specified by:
setDefaultLocalAddressin interfaceIoAcceptor- Parameters:
localAddress- The local addresses to bind the acceptor on
-
getDefaultLocalAddresses
Returns aListof the default local addresses to bind when no argument is specified inIoAcceptor.bind()method. Please note that the default will not be used if any local address is specified.- Specified by:
getDefaultLocalAddressesin interfaceIoAcceptor- Returns:
- The list of default bound LocalAddresses
-
setDefaultLocalAddresses
Sets the default local addresses to bind when no argument is specified inIoAcceptor.bind()method. Please note that the default will not be used if any local address is specified.- Specified by:
setDefaultLocalAddressesin interfaceIoAcceptor- Parameters:
localAddresses- The local addresses to bind the acceptor on
-
setDefaultLocalAddresses
Sets the default local addresses to bind when no argument is specified inIoAcceptor.bind()method. Please note that the default will not be used if any local address is specified.- Specified by:
setDefaultLocalAddressesin interfaceIoAcceptor- Parameters:
localAddresses- The local addresses to bind the acceptor on
-
setDefaultLocalAddresses
public final void setDefaultLocalAddresses(SocketAddress firstLocalAddress, SocketAddress... otherLocalAddresses) Sets the default local addresses to bind when no argument is specified inIoAcceptor.bind()method. Please note that the default will not be used if any local address is specified.- Specified by:
setDefaultLocalAddressesin interfaceIoAcceptor- Parameters:
firstLocalAddress- The first local address to bind the acceptor onotherLocalAddresses- The other local addresses to bind the acceptor on
-
isCloseOnDeactivation
public final boolean isCloseOnDeactivation()Returnstrueif 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:
isCloseOnDeactivationin interfaceIoAcceptor- Returns:
trueif the service sets the closeOnDeactivation flag
-
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 istrue.- Specified by:
setCloseOnDeactivationin interfaceIoAcceptor- Parameters:
disconnectClientsOnUnbind-trueif we should close on deactivation
-
bind
Binds to the default local address(es) and start to accept incoming connections.- Specified by:
bindin interfaceIoAcceptor- Throws:
IOException- if failed to bind
-
bind
Binds to the specified local address and start to accept incoming connections.- Specified by:
bindin interfaceIoAcceptor- Parameters:
localAddress- The SocketAddress to bind to- Throws:
IOException- if failed to bind
-
bind
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:
bindin interfaceIoAcceptor- Parameters:
addresses- The SocketAddresses to bind to- Throws:
IOException- if failed to bind
-
bind
public final 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.- Specified by:
bindin interfaceIoAcceptor- Parameters:
firstLocalAddress- The first address to bind toaddresses- The SocketAddresses to bind to- Throws:
IOException- if failed to bind
-
bind
Binds to the specified local addresses and start to accept incoming connections.- Specified by:
bindin interfaceIoAcceptor- Parameters:
localAddresses- The local address we will be bound to- 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 ifdisconnectOnUnbindproperty istrue. This method returns silently if no local address is bound yet.- Specified by:
unbindin interfaceIoAcceptor
-
unbind
Unbinds from the specified local address and stop to accept incoming connections. All managed connections will be closed ifdisconnectOnUnbindproperty istrue. This method returns silently if the default local address is not bound yet.- Specified by:
unbindin interfaceIoAcceptor- Parameters:
localAddress- The local address we will be unbound from
-
unbind
Unbinds from the specified local addresses and stop to accept incoming connections. All managed connections will be closed ifdisconnectOnUnbindproperty istrue. This method returns silently if the default local addresses are not bound yet.- Specified by:
unbindin interfaceIoAcceptor- Parameters:
firstLocalAddress- The first local address to be unbound fromotherLocalAddresses- The other local address to be unbound from
-
unbind
Unbinds from the specified local addresses and stop to accept incoming connections. All managed connections will be closed ifdisconnectOnUnbindproperty istrue. This method returns silently if the default local addresses are not bound yet.- Specified by:
unbindin interfaceIoAcceptor- Parameters:
localAddresses- The local address we will be unbound from
-
bindInternal
protected abstract Set<SocketAddress> bindInternal(List<? extends SocketAddress> localAddresses) throws Exception Starts the acceptor, and register the given addresses -
unbind0
Implement this method to perform the actual unbind operation.- Parameters:
localAddresses- The address to unbind from- Throws:
Exception- If the unbind failed
-
toString
-
checkAddressType
-