Class AbstractServerConnectionFactory
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory
org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory
- All Implemented Interfaces:
Runnable
,Aware
,BeanFactoryAware
,BeanNameAware
,InitializingBean
,ApplicationContextAware
,ApplicationEventPublisherAware
,Lifecycle
,ComponentSourceAware
,ExpressionCapable
,OrderlyShutdownCapable
,ConnectionFactory
,TcpServerConnectionFactory
,NamedComponent
,ManageableLifecycle
,SchedulingAwareRunnable
- Direct Known Subclasses:
TcpNetServerConnectionFactory
,TcpNioServerConnectionFactory
public abstract class AbstractServerConnectionFactory
extends AbstractConnectionFactory
implements TcpServerConnectionFactory, SchedulingAwareRunnable, OrderlyShutdownCapable
Base class for all server connection factories. Server connection factories
listen on a port for incoming connections and create new TcpConnection objects
for each new connection.
- Since:
- 2.0
- Author:
- Gary Russell, Artem Bilan, Christian Tzolov
-
Field Summary
Fields inherited from class org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory
connections, connectionsMonitor, DEFAULT_REPLY_TIMEOUT, lifecycleMonitor
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
-
Constructor Summary
ConstructorDescriptionAbstractServerConnectionFactory
(int port) The port on which the factory will listen. -
Method Summary
Modifier and TypeMethodDescriptionint
Called after normal shutdown of schedulers, executors etc, and after the shutdown delay has elapsed, but before any forced shutdown of any remaining active scheduler/executor threads.Can optionally return the number of active messages still in process.int
Called before shutdown begins.int
The number of sockets in the server connection backlog.Not supported because the factory manages multiple connections and this method cannot discriminate.Return theSocketAddress
that the underlyingServerSocket
is bound to.protected void
initializeConnection
(TcpConnectionSupport connection, Socket socket) Transfers attributes such as (de)serializer, mapper etc to a new connection.boolean
boolean
protected boolean
protected void
postProcessServerSocket
(ServerSocket serverSocket) protected void
protected void
publishServerListeningEvent
(int port) void
setBacklog
(int backlog) The number of sockets in the connection backlog.protected void
setListening
(boolean listening) void
setLocalAddress
(String localAddress) Used on multi-homed systems to enforce the server to listen on a specific network address instead of all network adapters.void
start()
Methods inherited from class org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory
addConnection, checkActive, closeConnection, delayRead, doAccept, getApplicationEventPublisher, getDelayedReads, getDeserializer, getHost, getLifecycleMonitor, getListener, getMapper, getOpenConnectionIds, getPort, getReadDelay, getSender, getSenders, getSerializer, getSoLinger, getSoReceiveBufferSize, getSoSendBufferSize, getSoTimeout, getSoTrafficClass, getSslHandshakeTimeout, getTaskExecutor, getTcpSocketSupport, harvestClosedConnections, isActive, isLookupHost, isRunning, isSingleUse, isSoKeepAlive, isSoTcpNoDelay, onInit, processNioSelections, registerListener, registerSender, setActive, setApplicationEventPublisher, setDeserializer, setHost, setInterceptorFactoryChain, setLeaveOpen, setLookupHost, setMapper, setNioHarvestInterval, setPort, setReadDelay, setSerializer, setSingleUse, setSocketAttributes, setSoKeepAlive, setSoLinger, setSoReceiveBufferSize, setSoSendBufferSize, setSoTcpNoDelay, setSoTimeout, setSoTrafficClass, setSslHandshakeTimeout, setTaskExecutor, setTcpSocketSupport, stop, toString, unregisterSender, wrapConnection
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentDescription, getComponentName, getComponentSource, getComponentType, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentDescription, setComponentName, setComponentSource, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.scheduling.SchedulingAwareRunnable
getQualifier
Methods inherited from interface org.springframework.integration.ip.tcp.connection.TcpServerConnectionFactory
getPort
-
Constructor Details
-
AbstractServerConnectionFactory
public AbstractServerConnectionFactory(int port) The port on which the factory will listen.- Parameters:
port
- The port.
-
-
Method Details
-
isLongLived
public boolean isLongLived()- Specified by:
isLongLived
in interfaceSchedulingAwareRunnable
-
getServerSocketAddress
Description copied from interface:TcpServerConnectionFactory
Return theSocketAddress
that the underlyingServerSocket
is bound to.- Specified by:
getServerSocketAddress
in interfaceTcpServerConnectionFactory
- Returns:
- the socket address.
-
start
public void start()- Specified by:
start
in interfaceLifecycle
- Specified by:
start
in interfaceManageableLifecycle
- Overrides:
start
in classAbstractConnectionFactory
-
getConnection
Not supported because the factory manages multiple connections and this method cannot discriminate.- Specified by:
getConnection
in interfaceConnectionFactory
-
setListening
protected void setListening(boolean listening) - Parameters:
listening
- the listening to set
-
isListening
public boolean isListening()- Returns:
- true if the server is listening on the port.
-
isShuttingDown
protected boolean isShuttingDown() -
initializeConnection
Transfers attributes such as (de)serializer, mapper etc to a new connection. For single use sockets, enforces a socket timeout (default 10 seconds) to prevent DoS attacks.- Parameters:
connection
- The new connection.socket
- The new socket.
-
postProcessServerSocket
-
getLocalAddress
- Returns:
- the localAddress
-
setLocalAddress
Used on multi-homed systems to enforce the server to listen on a specific network address instead of all network adapters.- Parameters:
localAddress
- the ip address of the required adapter.
-
getBacklog
public int getBacklog()The number of sockets in the server connection backlog.- Returns:
- The backlog.
-
setBacklog
public void setBacklog(int backlog) The number of sockets in the connection backlog. Default 5; increase if you expect high connection rates.- Parameters:
backlog
- The backlog to set.
-
beforeShutdown
public int beforeShutdown()Description copied from interface:OrderlyShutdownCapable
Called before shutdown begins. Implementations should stop accepting new messages. Can optionally return the number of active messages in process.- Specified by:
beforeShutdown
in interfaceOrderlyShutdownCapable
- Returns:
- The number of active messages if available.
-
afterShutdown
public int afterShutdown()Description copied from interface:OrderlyShutdownCapable
Called after normal shutdown of schedulers, executors etc, and after the shutdown delay has elapsed, but before any forced shutdown of any remaining active scheduler/executor threads.Can optionally return the number of active messages still in process.- Specified by:
afterShutdown
in interfaceOrderlyShutdownCapable
- Returns:
- The number of active messages if available.
-
publishServerExceptionEvent
-
publishServerListeningEvent
protected void publishServerListeningEvent(int port)
-