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:
java.lang.Runnable,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanFactoryAware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.InitializingBean,org.springframework.context.ApplicationContextAware,org.springframework.context.ApplicationEventPublisherAware,org.springframework.context.Lifecycle,org.springframework.integration.context.ExpressionCapable,org.springframework.integration.context.OrderlyShutdownCapable,ConnectionFactory,TcpServerConnectionFactory,org.springframework.integration.support.context.NamedComponent,org.springframework.integration.support.management.ManageableLifecycle,org.springframework.scheduling.SchedulingAwareRunnable
public class TcpNetServerConnectionFactory extends AbstractServerConnectionFactory
Implements a server connection factory that produces
TcpNetConnections using
a ServerSocket. Must have a TcpListener registered.- Since:
- 2.0
-
Field Summary
Fields inherited from class org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory
DEFAULT_REPLY_TIMEOUT, lifecycleMonitor -
Constructor Summary
Constructors Constructor Description TcpNetServerConnectionFactory(int port)Listens for incoming connections on the port. -
Method Summary
Modifier and Type Method Description protected java.net.ServerSocketcreateServerSocket(int port, int backlog, java.net.InetAddress whichNic)Create a newServerSocket.java.lang.StringgetComponentType()intgetPort()Return the port this server is listening on.protected java.net.ServerSocketgetServerSocket()java.net.SocketAddressgetServerSocketAddress()Return theSocketAddressthat the underlyingServerSocketis bound to.protected TcpSocketFactorySupportgetTcpSocketFactorySupport()voidrun()If no listener registers, exits.voidsetTcpNetConnectionSupport(TcpNetConnectionSupport connectionSupport)Set theTcpNetConnectionSupportto use to create connection objects.voidsetTcpSocketFactorySupport(TcpSocketFactorySupport tcpSocketFactorySupport)voidstop()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, startMethods 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, wrapConnectionMethods 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
public java.lang.String getComponentType()- Specified by:
getComponentTypein interfaceorg.springframework.integration.support.context.NamedComponent- Overrides:
getComponentTypein classorg.springframework.integration.context.IntegrationObjectSupport
-
getPort
public int getPort()Description copied from interface:TcpServerConnectionFactoryReturn 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:
getPortin interfaceTcpServerConnectionFactory- Overrides:
getPortin classAbstractConnectionFactory- Returns:
- the port
-
getServerSocketAddress
@Nullable public java.net.SocketAddress getServerSocketAddress()Description copied from interface:TcpServerConnectionFactoryReturn theSocketAddressthat the underlyingServerSocketis bound to.- Specified by:
getServerSocketAddressin interfaceTcpServerConnectionFactory- Overrides:
getServerSocketAddressin classAbstractServerConnectionFactory- Returns:
- the socket address.
-
setTcpSocketFactorySupport
-
setTcpNetConnectionSupport
Set theTcpNetConnectionSupportto 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 java.net.ServerSocket createServerSocket(int port, int backlog, @Nullable java.net.InetAddress whichNic) throws java.io.IOExceptionCreate 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:
java.io.IOException- Any IOException.
-
stop
public void stop()Description copied from class:AbstractConnectionFactoryStops the server.- Specified by:
stopin interfaceorg.springframework.context.Lifecycle- Specified by:
stopin interfaceorg.springframework.integration.support.management.ManageableLifecycle- Overrides:
stopin classAbstractConnectionFactory
-
getServerSocket
protected java.net.ServerSocket getServerSocket()- Returns:
- the serverSocket
-
getTcpSocketFactorySupport
-