public abstract class AbstractConnectionFactory extends IntegrationObjectSupport implements ConnectionFactory, org.springframework.context.SmartLifecycle, org.springframework.context.ApplicationEventPublisherAware
Modifier and Type | Field and Description |
---|---|
protected static int |
DEFAULT_REPLY_TIMEOUT |
protected java.lang.Object |
lifecycleMonitor |
logger
Constructor and Description |
---|
AbstractConnectionFactory(int port) |
AbstractConnectionFactory(java.lang.String host,
int port) |
Modifier and Type | Method and Description |
---|---|
protected void |
addConnection(TcpConnectionSupport connection) |
protected void |
checkActive() |
abstract void |
close()
Deprecated.
As of 3.0; use
stop() . |
boolean |
closeConnection(java.lang.String connectionId)
Close a connection with the specified connection id.
|
protected void |
doAccept(java.nio.channels.Selector selector,
java.nio.channels.ServerSocketChannel server,
long now) |
protected org.springframework.context.ApplicationEventPublisher |
getApplicationEventPublisher() |
org.springframework.core.serializer.Deserializer<?> |
getDeserializer() |
java.lang.String |
getHost() |
TcpListener |
getListener() |
TcpMessageMapper |
getMapper() |
java.util.List<java.lang.String> |
getOpenConnectionIds()
Returns a list of (currently) open
TcpConnection connection ids; allows,
for example, broadcast operations to all open connections. |
int |
getPhase() |
int |
getPort() |
TcpSender |
getSender() |
org.springframework.core.serializer.Serializer<?> |
getSerializer() |
int |
getSoLinger() |
int |
getSoReceiveBufferSize() |
int |
getSoSendBufferSize() |
int |
getSoTimeout() |
int |
getSoTrafficClass() |
protected java.util.concurrent.Executor |
getTaskExecutor()
Creates a taskExecutor (if one was not provided).
|
protected TcpSocketSupport |
getTcpSocketSupport() |
protected void |
harvestClosedConnections()
Cleans up this.connections by removing any closed connections.
|
protected boolean |
isActive() |
boolean |
isAutoStartup()
We are controlled by the startup options of
the bound endpoint.
|
boolean |
isLookupHost() |
boolean |
isRunning() |
boolean |
isSingleUse() |
boolean |
isSoKeepAlive() |
boolean |
isSoTcpNoDelay() |
protected void |
processNioSelections(int selectionCount,
java.nio.channels.Selector selector,
java.nio.channels.ServerSocketChannel server,
java.util.Map<java.nio.channels.SocketChannel,TcpNioConnection> connections)
Times out any expired connections then, if
selectionCount > 0 ,
processes the selected keys. |
void |
registerListener(TcpListener listener)
Registers a TcpListener to receive messages after
the payload has been converted from the input data.
|
void |
registerSender(TcpSender sender)
Registers a TcpSender; for server sockets, used to
provide connection information so a sender can be used
to reply to incoming messages.
|
protected void |
setActive(boolean active) |
void |
setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher) |
void |
setDeserializer(org.springframework.core.serializer.Deserializer<?> deserializer) |
void |
setInterceptorFactoryChain(TcpConnectionInterceptorFactoryChain interceptorFactoryChain) |
void |
setLookupHost(boolean lookupHost)
If true, DNS reverse lookup is done on the remote ip address.
|
void |
setMapper(TcpMessageMapper mapper) |
void |
setNioHarvestInterval(int nioHarvestInterval)
How often we clean up closed NIO connections if soTimeout is 0.
|
void |
setSerializer(org.springframework.core.serializer.Serializer<?> serializer) |
void |
setSingleUse(boolean singleUse)
If true, sockets created by this factory will be used once.
|
protected void |
setSocketAttributes(java.net.Socket socket)
Sets socket attributes on the socket.
|
void |
setSoKeepAlive(boolean soKeepAlive) |
void |
setSoLinger(int soLinger) |
void |
setSoReceiveBufferSize(int soReceiveBufferSize) |
void |
setSoSendBufferSize(int soSendBufferSize) |
void |
setSoTcpNoDelay(boolean soTcpNoDelay) |
void |
setSoTimeout(int soTimeout) |
void |
setSoTrafficClass(int soTrafficClass) |
void |
setTaskExecutor(java.util.concurrent.Executor taskExecutor) |
void |
setTcpSocketSupport(TcpSocketSupport tcpSocketSupport) |
void |
start() |
void |
stop()
Stops the server.
|
void |
stop(java.lang.Runnable callback) |
protected TcpConnectionSupport |
wrapConnection(TcpConnectionSupport connection) |
afterPropertiesSet, getApplicationContextId, getBeanFactory, getComponentName, getComponentType, getConversionService, getIntegrationProperties, getIntegrationProperty, getTaskScheduler, onInit, setApplicationContext, setBeanFactory, setBeanName, setComponentName, setConversionService, setTaskScheduler, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getConnection
protected static final int DEFAULT_REPLY_TIMEOUT
protected final java.lang.Object lifecycleMonitor
public AbstractConnectionFactory(int port)
public AbstractConnectionFactory(java.lang.String host, int port)
public void setApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher applicationEventPublisher)
setApplicationEventPublisher
in interface org.springframework.context.ApplicationEventPublisherAware
protected org.springframework.context.ApplicationEventPublisher getApplicationEventPublisher()
protected void setSocketAttributes(java.net.Socket socket) throws java.net.SocketException
socket
- The socket.java.net.SocketException
public int getSoTimeout()
public void setSoTimeout(int soTimeout)
soTimeout
- the soTimeout to setpublic int getSoReceiveBufferSize()
public void setSoReceiveBufferSize(int soReceiveBufferSize)
soReceiveBufferSize
- the soReceiveBufferSize to setpublic int getSoSendBufferSize()
public void setSoSendBufferSize(int soSendBufferSize)
soSendBufferSize
- the soSendBufferSize to setpublic boolean isSoTcpNoDelay()
public void setSoTcpNoDelay(boolean soTcpNoDelay)
soTcpNoDelay
- the soTcpNoDelay to setpublic int getSoLinger()
public void setSoLinger(int soLinger)
soLinger
- the soLinger to setpublic boolean isSoKeepAlive()
public void setSoKeepAlive(boolean soKeepAlive)
soKeepAlive
- the soKeepAlive to setpublic int getSoTrafficClass()
public void setSoTrafficClass(int soTrafficClass)
soTrafficClass
- the soTrafficClass to setpublic java.lang.String getHost()
public int getPort()
public TcpListener getListener()
public TcpSender getSender()
public org.springframework.core.serializer.Serializer<?> getSerializer()
public org.springframework.core.serializer.Deserializer<?> getDeserializer()
public TcpMessageMapper getMapper()
public void registerListener(TcpListener listener)
listener
- the TcpListener.public void registerSender(TcpSender sender)
sender
- The senderpublic void setTaskExecutor(java.util.concurrent.Executor taskExecutor)
taskExecutor
- the taskExecutor to setpublic void setDeserializer(org.springframework.core.serializer.Deserializer<?> deserializer)
deserializer
- the deserializer to setpublic void setSerializer(org.springframework.core.serializer.Serializer<?> serializer)
serializer
- the serializer to setpublic void setMapper(TcpMessageMapper mapper)
mapper
- the mapper to set; defaults to a TcpMessageMapper
public boolean isSingleUse()
public void setSingleUse(boolean singleUse)
singleUse
- public void setInterceptorFactoryChain(TcpConnectionInterceptorFactoryChain interceptorFactoryChain)
public void setLookupHost(boolean lookupHost)
lookupHost
- the lookupHost to setpublic boolean isLookupHost()
public void setNioHarvestInterval(int nioHarvestInterval)
soTimeout > 0
because the clean up
process is run as part of the timeout handling.
Default 2000 milliseconds.nioHarvestInterval
- The interval in milliseconds.@Deprecated public abstract void close()
stop()
.public void start()
start
in interface org.springframework.context.Lifecycle
protected java.util.concurrent.Executor getTaskExecutor()
public void stop()
stop
in interface org.springframework.context.Lifecycle
protected TcpConnectionSupport wrapConnection(TcpConnectionSupport connection) throws java.lang.Exception
java.lang.Exception
protected void processNioSelections(int selectionCount, java.nio.channels.Selector selector, java.nio.channels.ServerSocketChannel server, java.util.Map<java.nio.channels.SocketChannel,TcpNioConnection> connections) throws java.io.IOException
selectionCount > 0
,
processes the selected keys.
Removes closed connections from the connections field, and from the connections parameter.selectionCount
- Number of IO Events, if 0 we were probably woken up by a close.selector
- The selectorconnections
- Map of connectionsjava.io.IOException
protected void doAccept(java.nio.channels.Selector selector, java.nio.channels.ServerSocketChannel server, long now) throws java.io.IOException
selector
- now
- java.io.IOException
public int getPhase()
getPhase
in interface org.springframework.context.Phased
public boolean isAutoStartup()
isAutoStartup
in interface org.springframework.context.SmartLifecycle
public void stop(java.lang.Runnable callback)
stop
in interface org.springframework.context.SmartLifecycle
protected void addConnection(TcpConnectionSupport connection)
protected void harvestClosedConnections()
public boolean isRunning()
isRunning
in interface org.springframework.context.Lifecycle
protected boolean isActive()
protected void setActive(boolean active)
active
- the active to setprotected void checkActive() throws java.io.IOException
java.io.IOException
protected TcpSocketSupport getTcpSocketSupport()
public void setTcpSocketSupport(TcpSocketSupport tcpSocketSupport)
public java.util.List<java.lang.String> getOpenConnectionIds()
TcpConnection
connection ids; allows,
for example, broadcast operations to all open connections.public boolean closeConnection(java.lang.String connectionId)
connectionId
- the connection id.