Class TcpNetServerConnectionFactory
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory
org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory
org.springframework.integration.ip.tcp.connection.TcpNetServerConnectionFactory
- All Implemented Interfaces:
Runnable
,Aware
,BeanFactoryAware
,BeanNameAware
,InitializingBean
,ApplicationContextAware
,ApplicationEventPublisherAware
,Lifecycle
,ExpressionCapable
,OrderlyShutdownCapable
,ConnectionFactory
,TcpServerConnectionFactory
,NamedComponent
,ManageableLifecycle
,SchedulingAwareRunnable
Implements a server connection factory that produces
TcpNetConnection
s using
a ServerSocket
. Must have a TcpListener
registered.- Since:
- 2.0
- Author:
- Gary Russell, Artem Bilan, Mário Dias
-
Field Summary
Fields inherited from class org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory
DEFAULT_REPLY_TIMEOUT, lifecycleMonitor
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
-
Constructor Summary
ConstructorDescriptionTcpNetServerConnectionFactory
(int port) Listens for incoming connections on the port. -
Method Summary
Modifier and TypeMethodDescriptionprotected ServerSocket
createServerSocket
(int port, int backlog, InetAddress whichNic) Create a newServerSocket
.Subclasses may implement this method to provide component type information.int
getPort()
Return the port this server is listening on.protected ServerSocket
Return theSocketAddress
that the underlyingServerSocket
is bound to.protected TcpSocketFactorySupport
void
run()
If no listener registers, exits.void
setTcpNetConnectionSupport
(TcpNetConnectionSupport connectionSupport) Set theTcpNetConnectionSupport
to use to create connection objects.void
setTcpSocketFactorySupport
(TcpSocketFactorySupport tcpSocketFactorySupport) Set theTcpSocketFactorySupport
used to create server sockets.void
stop()
Stops the server.Methods inherited from class org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory
afterShutdown, beforeShutdown, getBacklog, getConnection, getLocalAddress, initializeConnection, isListening, isLongLived, isShuttingDown, postProcessServerSocket, publishServerExceptionEvent, publishServerListeningEvent, setBacklog, setListening, setLocalAddress, 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, 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, toString, unregisterSender, wrapConnection
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler
-
Constructor Details
-
TcpNetServerConnectionFactory
public TcpNetServerConnectionFactory(int port) Listens for incoming connections on the port.- Parameters:
port
- The port.
-
-
Method Details
-
getComponentType
Description copied from class:IntegrationObjectSupport
Subclasses may implement this method to provide component type information.- Specified by:
getComponentType
in interfaceNamedComponent
- Overrides:
getComponentType
in classIntegrationObjectSupport
-
getPort
public int getPort()Description copied from interface:TcpServerConnectionFactory
Return the port this server is listening on. If the factory is configured to listen on a random port (0), this will return the actual port after the factory is started. It may return the previous value if the factory is stopped.- Specified by:
getPort
in interfaceTcpServerConnectionFactory
- Overrides:
getPort
in classAbstractConnectionFactory
- Returns:
- the port
-
getServerSocketAddress
Description copied from interface:TcpServerConnectionFactory
Return theSocketAddress
that the underlyingServerSocket
is bound to.- Specified by:
getServerSocketAddress
in interfaceTcpServerConnectionFactory
- Overrides:
getServerSocketAddress
in classAbstractServerConnectionFactory
- Returns:
- the socket address.
-
setTcpSocketFactorySupport
Set theTcpSocketFactorySupport
used to create server sockets.- Parameters:
tcpSocketFactorySupport
- theTcpSocketFactorySupport
-
setTcpNetConnectionSupport
Set theTcpNetConnectionSupport
to use to create connection objects.- Parameters:
connectionSupport
- the connection support.- Since:
- 5.0
-
run
public void run()If no listener registers, exits. Accepts incoming connections and creates TcpConnections for each new connection. Invokes {AbstractServerConnectionFactory.initializeConnection(TcpConnectionSupport, Socket)
and executes the connectionRunnable.run()
using the task executor. I/O errors on the server socket/channel are logged and the factory is stopped. -
createServerSocket
protected ServerSocket createServerSocket(int port, int backlog, @Nullable InetAddress whichNic) throws IOException Create a newServerSocket
. This default implementation uses the defaultServerSocketFactory
. Override to use some other mechanism- Parameters:
port
- The port.backlog
- The server socket backlog.whichNic
- An InetAddress if binding to a specific network interface. Set to null when configured to bind to all interfaces.- Returns:
- The Server Socket.
- Throws:
IOException
- Any IOException.
-
stop
public void stop()Description copied from class:AbstractConnectionFactory
Stops the server.- Specified by:
stop
in interfaceLifecycle
- Specified by:
stop
in interfaceManageableLifecycle
- Overrides:
stop
in classAbstractConnectionFactory
-
getServerSocket
- Returns:
- the serverSocket
-
getTcpSocketFactorySupport
-