Class TcpNioServerConnectionFactory
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.TcpNioServerConnectionFactory
- All Implemented Interfaces:
Runnable
,Aware
,BeanFactoryAware
,BeanNameAware
,InitializingBean
,ApplicationContextAware
,ApplicationEventPublisherAware
,Lifecycle
,ComponentSourceAware
,ExpressionCapable
,OrderlyShutdownCapable
,ConnectionFactory
,TcpServerConnectionFactory
,NamedComponent
,ManageableLifecycle
,SchedulingAwareRunnable
/**
Implements a server connection factory that produces
TcpNioConnection
s using
a ServerSocketChannel
. Must have a TcpListener
registered.- Since:
- 2.0
- Author:
- Gary Russell, Artem Bilan, Ngoc Nhan
-
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
ConstructorDescriptionTcpNioServerConnectionFactory
(int port) Listens for incoming connections on the port. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
doAccept
(Selector selectorForNewSocket, ServerSocketChannel server, long now) Subclasses may implement this method to provide component type information.protected Map<SocketChannel,
TcpNioConnection> int
getPort()
Return the port this server is listening on.protected ServerSocketChannel
Return theSocketAddress
that the underlyingServerSocket
is bound to.protected boolean
void
run()
If no listener registers, exits.void
setMultiAccept
(boolean multiAccept) Set to false to only accept one connection per iteration over the selector keys.void
setTcpNioConnectionSupport
(TcpNioConnectionSupport tcpNioSupport) Set theTcpNioConnectionSupport
to use.void
setUsingDirectBuffers
(boolean usingDirectBuffers) Set to true to use direct buffers.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, 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, getComponentDescription, getComponentName, getComponentSource, 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
-
Constructor Details
-
TcpNioServerConnectionFactory
public TcpNioServerConnectionFactory(int port) Listens for incoming connections on the port.- Parameters:
port
- The port.
-
-
Method Details
-
setMultiAccept
public void setMultiAccept(boolean multiAccept) Set to false to only accept one connection per iteration over the selector keys. This might be necessary to avoid accepts overwhelming reads of existing sockets. By default when theOP_ACCEPT
operation is ready, we will keep accepting connections in a loop until no more arrive.- Parameters:
multiAccept
- false to accept connections one-at-a-time.- Since:
- 5.1.4
-
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.
-
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. -
doAccept
- Overrides:
doAccept
in classAbstractConnectionFactory
- Parameters:
selectorForNewSocket
- The selector.server
- The server socket channel.now
- The current time.
-
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
-
setUsingDirectBuffers
public void setUsingDirectBuffers(boolean usingDirectBuffers) Set to true to use direct buffers.- Parameters:
usingDirectBuffers
- true for direct.
-
setTcpNioConnectionSupport
Set theTcpNioConnectionSupport
to use.- Parameters:
tcpNioSupport
- theTcpNioConnectionSupport
.
-
getServerChannel
- Returns:
- the serverChannel
-
isUsingDirectBuffers
protected boolean isUsingDirectBuffers()- Returns:
- the usingDirectBuffers
-
getConnections
- Returns:
- the connections
-