Class AbstractConnectionFactory
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory
- All Implemented Interfaces:
- Aware,- BeanFactoryAware,- BeanNameAware,- InitializingBean,- ApplicationContextAware,- ApplicationEventPublisherAware,- Lifecycle,- ComponentSourceAware,- ExpressionCapable,- ConnectionFactory,- NamedComponent,- ManageableLifecycle
- Direct Known Subclasses:
- AbstractClientConnectionFactory,- AbstractServerConnectionFactory
public abstract class AbstractConnectionFactory
extends IntegrationObjectSupport
implements ConnectionFactory, ApplicationEventPublisherAware
Base class for all connection factories.
- Since:
- 2.0
- Author:
- Gary Russell, Artem Bilan, Christian Tzolov, Ngoc Nhan
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected final Map<String, TcpConnectionSupport> protected final Lockprotected static final intprotected final LockFields inherited from class org.springframework.integration.context.IntegrationObjectSupportEXPRESSION_PARSER, logger
- 
Constructor SummaryConstructorsConstructorDescriptionAbstractConnectionFactory(int port) AbstractConnectionFactory(String host, int port) 
- 
Method SummaryModifier and TypeMethodDescriptionprotected voidaddConnection(TcpConnectionSupport connection) protected voidbooleancloseConnection(String connectionId) Close a connection with the specified connection id.protected voiddelayRead(Selector selector, long now, SelectionKey key) protected voiddoAccept(Selector selector, ServerSocketChannel server, long now) protected BlockingQueue<org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory.PendingIO> Deserializer<?> getHost()protected ObjectReturns a list of (currently) openTcpConnectionconnection ids; allows, for example, broadcast operations to all open connections.intgetPort()protected longReturn the list of senders.Serializer<?> intintintintintprotected Integerprotected ExecutorCreates a taskExecutor (if one was not provided).protected TcpSocketSupportprotected voidCleans up this.connections by removing any closed connections.protected booleanisActive()booleanbooleanbooleanbooleanbooleanprotected voidonInit()Subclasses may implement this for initialization logic.protected voidprocessNioSelections(int selectionCount, Selector selector, ServerSocketChannel server, Map<SocketChannel, TcpNioConnection> connectionMap) Times out any expired connections then, ifselectionCount > 0, processes the selected keys.voidregisterListener(TcpListener listenerToRegister) Registers a TcpListener to receive messages after the payload has been converted from the input data.voidregisterSender(TcpSender senderToRegister) Registers a TcpSender; for server sockets, used to provide connection information so a sender can be used to reply to incoming messages.protected voidsetActive(boolean active) voidsetApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) voidsetDeserializer(Deserializer<?> deserializer) voidSet the host; requires the factory to be stopped.voidsetInterceptorFactoryChain(TcpConnectionInterceptorFactoryChain interceptorFactoryChain) voidsetLeaveOpen(boolean leaveOpen) If true, sockets created by this factory will be reused.voidsetLookupHost(boolean lookupHost) If true, DNS reverse lookup is done on the remote ip address.voidsetMapper(TcpMessageMapper mapper) voidsetNioHarvestInterval(int nioHarvestInterval) How often we clean up closed NIO connections if soTimeout is 0.voidsetPort(int port) Set the port; requires the factory to be stopped.voidsetReadDelay(long readDelay) The delay (in milliseconds) before retrying a read after the previous attempt failed due to insufficient threads.voidsetSerializer(Serializer<?> serializer) voidsetSingleUse(boolean singleUse) If true, sockets created by this factory will be used once.protected voidsetSocketAttributes(Socket socket) Sets socket attributes on the socket.voidsetSoKeepAlive(boolean soKeepAlive) voidsetSoLinger(int soLinger) voidsetSoReceiveBufferSize(int soReceiveBufferSize) voidsetSoSendBufferSize(int soSendBufferSize) voidsetSoTcpNoDelay(boolean soTcpNoDelay) voidsetSoTimeout(int soTimeout) voidsetSoTrafficClass(int soTrafficClass) voidsetSslHandshakeTimeout(int sslHandshakeTimeout) Set the handshake timeout used when waiting for SSL handshake data; only applies to SSL connections, when using NIO.voidsetTaskExecutor(Executor taskExecutor) voidsetTcpSocketSupport(TcpSocketSupport tcpSocketSupport) voidstart()voidstop()Stops the server.toString()booleanunregisterSender(TcpSender sender) Unregister a TcpSender.protected TcpConnectionSupportwrapConnection(TcpConnectionSupport connectionArg) Methods inherited from class org.springframework.integration.context.IntegrationObjectSupportafterPropertiesSet, 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, setTaskSchedulerMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.integration.ip.tcp.connection.ConnectionFactorygetConnection
- 
Field Details- 
DEFAULT_REPLY_TIMEOUTprotected static final int DEFAULT_REPLY_TIMEOUT- See Also:
 
- 
lifecycleMonitor
- 
connections
- 
connectionsMonitor
 
- 
- 
Constructor Details- 
AbstractConnectionFactorypublic AbstractConnectionFactory(int port) 
- 
AbstractConnectionFactory
 
- 
- 
Method Details- 
setApplicationEventPublisher- Specified by:
- setApplicationEventPublisherin interface- ApplicationEventPublisherAware
 
- 
getApplicationEventPublisher
- 
setSocketAttributesSets socket attributes on the socket.- Parameters:
- socket- The socket.
- Throws:
- SocketException- Any SocketException.
 
- 
getSoTimeoutpublic int getSoTimeout()- Returns:
- the soTimeout
 
- 
setSoTimeoutpublic void setSoTimeout(int soTimeout) - Parameters:
- soTimeout- the soTimeout to set, in milliseconds
 
- 
getSoReceiveBufferSizepublic int getSoReceiveBufferSize()- Returns:
- the soReceiveBufferSize
 
- 
setSoReceiveBufferSizepublic void setSoReceiveBufferSize(int soReceiveBufferSize) - Parameters:
- soReceiveBufferSize- the soReceiveBufferSize to set
 
- 
getSoSendBufferSizepublic int getSoSendBufferSize()- Returns:
- the soSendBufferSize
 
- 
setSoSendBufferSizepublic void setSoSendBufferSize(int soSendBufferSize) - Parameters:
- soSendBufferSize- the soSendBufferSize to set
 
- 
isSoTcpNoDelaypublic boolean isSoTcpNoDelay()- Returns:
- the soTcpNoDelay
 
- 
setSoTcpNoDelaypublic void setSoTcpNoDelay(boolean soTcpNoDelay) - Parameters:
- soTcpNoDelay- the soTcpNoDelay to set
 
- 
getSoLingerpublic int getSoLinger()- Returns:
- the soLinger
 
- 
setSoLingerpublic void setSoLinger(int soLinger) - Parameters:
- soLinger- the soLinger to set
 
- 
isSoKeepAlivepublic boolean isSoKeepAlive()- Returns:
- the soKeepAlive
 
- 
setSoKeepAlivepublic void setSoKeepAlive(boolean soKeepAlive) - Parameters:
- soKeepAlive- the soKeepAlive to set
 
- 
getSoTrafficClasspublic int getSoTrafficClass()- Returns:
- the soTrafficClass
 
- 
setSoTrafficClasspublic void setSoTrafficClass(int soTrafficClass) - Parameters:
- soTrafficClass- the soTrafficClass to set
 
- 
setHostSet the host; requires the factory to be stopped.- Parameters:
- host- the host.
- Since:
- 5.0
 
- 
getHost- Returns:
- the host
 
- 
setPortpublic void setPort(int port) Set the port; requires the factory to be stopped.- Parameters:
- port- the port.
- Since:
- 5.0
 
- 
getPortpublic int getPort()- Returns:
- the port
 
- 
getListener- Returns:
- the listener
 
- 
getSender
- 
getSenders
- 
getSerializer- Returns:
- the serializer
 
- 
getDeserializer- Returns:
- the deserializer
 
- 
getMapper- Returns:
- the mapper
 
- 
registerListenerRegisters a TcpListener to receive messages after the payload has been converted from the input data.- Parameters:
- listenerToRegister- the TcpListener.
 
- 
registerSenderRegisters a TcpSender; for server sockets, used to provide connection information so a sender can be used to reply to incoming messages.- Parameters:
- senderToRegister- The sender
 
- 
unregisterSenderUnregister a TcpSender.- Parameters:
- sender- the sender.
- Returns:
- true if the sender was registered.
 
- 
setTaskExecutor- Parameters:
- taskExecutor- the taskExecutor to set
 
- 
setDeserializer- Parameters:
- deserializer- the deserializer to set
 
- 
setSerializer- Parameters:
- serializer- the serializer to set
 
- 
setMapper- Parameters:
- mapper- the mapper to set; defaults to a- TcpMessageMapper
 
- 
isSingleUsepublic boolean isSingleUse()- Returns:
- the singleUse
 
- 
setSingleUsepublic void setSingleUse(boolean singleUse) If true, sockets created by this factory will be used once.- Parameters:
- singleUse- The singleUse to set.
 
- 
setLeaveOpenpublic void setLeaveOpen(boolean leaveOpen) If true, sockets created by this factory will be reused. Inverse ofsetSingleUse(boolean).- Parameters:
- leaveOpen- The keepOpen to set.
- Since:
- 5.0
 
- 
setInterceptorFactoryChainpublic void setInterceptorFactoryChain(TcpConnectionInterceptorFactoryChain interceptorFactoryChain) 
- 
setLookupHostpublic void setLookupHost(boolean lookupHost) If true, DNS reverse lookup is done on the remote ip address. Default false: not all environments (e.g. Docker containers) perform reliable DNS resolution.- Parameters:
- lookupHost- the lookupHost to set
 
- 
isLookupHostpublic boolean isLookupHost()- Returns:
- the lookupHost
 
- 
setNioHarvestIntervalpublic void setNioHarvestInterval(int nioHarvestInterval) How often we clean up closed NIO connections if soTimeout is 0. Ignored whensoTimeout > 0because the clean up process is run as part of the timeout handling. Default 2000 milliseconds.- Parameters:
- nioHarvestInterval- The interval in milliseconds.
 
- 
setSslHandshakeTimeoutpublic void setSslHandshakeTimeout(int sslHandshakeTimeout) Set the handshake timeout used when waiting for SSL handshake data; only applies to SSL connections, when using NIO.- Parameters:
- sslHandshakeTimeout- the timeout.
- Since:
- 4.3.6
 
- 
getSslHandshakeTimeout
- 
getDelayedReadsprotected BlockingQueue<org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory.PendingIO> getDelayedReads()
- 
getReadDelayprotected long getReadDelay()
- 
setReadDelaypublic void setReadDelay(long readDelay) The delay (in milliseconds) before retrying a read after the previous attempt failed due to insufficient threads. Default 100.- Parameters:
- readDelay- the readDelay to set.
 
- 
getLifecycleMonitor
- 
onInitprotected void onInit()Description copied from class:IntegrationObjectSupportSubclasses may implement this for initialization logic.- Overrides:
- onInitin class- IntegrationObjectSupport
 
- 
startpublic void start()- Specified by:
- startin interface- Lifecycle
- Specified by:
- startin interface- ManageableLifecycle
 
- 
getTaskExecutorCreates a taskExecutor (if one was not provided).- Returns:
- The executor.
 
- 
stoppublic void stop()Stops the server.- Specified by:
- stopin interface- Lifecycle
- Specified by:
- stopin interface- ManageableLifecycle
 
- 
wrapConnection
- 
processNioSelectionsprotected void processNioSelections(int selectionCount, Selector selector, @Nullable ServerSocketChannel server, Map<SocketChannel, TcpNioConnection> connectionMap) Times out any expired connections then, ifselectionCount > 0, processes the selected keys. Removes closed connections from the connections field, and from the connections parameter.- Parameters:
- selectionCount- Number of IO Events, if 0 we were probably woken up by a close.
- selector- The selector.
- server- The server socket channel.
- connectionMap- Map of connections.
 
- 
delayRead
- 
doAccept- Parameters:
- selector- The selector.
- server- The server socket channel.
- now- The current time.
 
- 
addConnection
- 
harvestClosedConnectionsprotected void harvestClosedConnections()Cleans up this.connections by removing any closed connections.
- 
isRunningpublic boolean isRunning()- Specified by:
- isRunningin interface- Lifecycle
- Specified by:
- isRunningin interface- ManageableLifecycle
 
- 
isActiveprotected boolean isActive()- Returns:
- the active
 
- 
setActiveprotected void setActive(boolean active) - Parameters:
- active- the active to set
 
- 
checkActiveprotected void checkActive()
- 
getTcpSocketSupport
- 
setTcpSocketSupport
- 
getOpenConnectionIdsReturns a list of (currently) openTcpConnectionconnection ids; allows, for example, broadcast operations to all open connections.- Returns:
- the list of connection ids.
 
- 
closeConnectionClose a connection with the specified connection id.- Parameters:
- connectionId- the connection id.
- Returns:
- true if the connection was closed.
 
- 
toString- Overrides:
- toStringin class- IntegrationObjectSupport
 
 
-