public abstract class AbstractConnectionFactory extends IntegrationObjectSupport implements ConnectionFactory, SmartLifecycle, ApplicationEventPublisherAware
Modifier and Type | Field and Description |
---|---|
protected static int |
DEFAULT_REPLY_TIMEOUT |
protected Object |
lifecycleMonitor |
logger
Constructor and Description |
---|
AbstractConnectionFactory(int port) |
AbstractConnectionFactory(String host,
int port) |
Modifier and Type | Method and Description |
---|---|
protected void |
addConnection(TcpConnectionSupport connection) |
protected void |
checkActive() |
boolean |
closeConnection(String connectionId)
Close a connection with the specified connection id.
|
protected void |
doAccept(Selector selector,
ServerSocketChannel server,
long now) |
protected ApplicationEventPublisher |
getApplicationEventPublisher() |
Deserializer<?> |
getDeserializer() |
String |
getHost() |
TcpListener |
getListener() |
TcpMessageMapper |
getMapper() |
List<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() |
Serializer<?> |
getSerializer() |
int |
getSoLinger() |
int |
getSoReceiveBufferSize() |
int |
getSoSendBufferSize() |
int |
getSoTimeout() |
int |
getSoTrafficClass() |
protected 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 |
onInit()
Subclasses may implement this for initialization logic.
|
protected void |
processNioSelections(int selectionCount,
Selector selector,
ServerSocketChannel server,
Map<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(ApplicationEventPublisher applicationEventPublisher) |
void |
setDeserializer(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(Serializer<?> serializer) |
void |
setSingleUse(boolean singleUse)
If true, sockets created by this factory will be used once.
|
protected void |
setSocketAttributes(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(Executor taskExecutor) |
void |
setTcpSocketSupport(TcpSocketSupport tcpSocketSupport) |
void |
start() |
void |
stop()
Stops the server.
|
void |
stop(Runnable callback) |
protected TcpConnectionSupport |
wrapConnection(TcpConnectionSupport connection) |
afterPropertiesSet, getApplicationContextId, getBeanFactory, getComponentName, getComponentType, getConversionService, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, setApplicationContext, setBeanFactory, setBeanName, setComponentName, setConversionService, setMessageBuilderFactory, setTaskScheduler, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
getConnection
protected static final int DEFAULT_REPLY_TIMEOUT
protected final Object lifecycleMonitor
public AbstractConnectionFactory(int port)
public AbstractConnectionFactory(String host, int port)
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher)
setApplicationEventPublisher
in interface ApplicationEventPublisherAware
protected ApplicationEventPublisher getApplicationEventPublisher()
protected void setSocketAttributes(Socket socket) throws SocketException
socket
- The socket.SocketException
- Any 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 String getHost()
public int getPort()
public TcpListener getListener()
public TcpSender getSender()
public Serializer<?> getSerializer()
public Deserializer<?> getDeserializer()
public TcpMessageMapper getMapper()
public void registerListener(TcpListener listener)
listener
- the TcpListener.public void registerSender(TcpSender sender)
sender
- The senderpublic void setTaskExecutor(Executor taskExecutor)
taskExecutor
- the taskExecutor to setpublic void setDeserializer(Deserializer<?> deserializer)
deserializer
- the deserializer to setpublic void setSerializer(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
- The singleUse to set.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.protected void onInit() throws Exception
IntegrationObjectSupport
onInit
in class IntegrationObjectSupport
Exception
- Any exception.protected Executor getTaskExecutor()
protected TcpConnectionSupport wrapConnection(TcpConnectionSupport connection) throws Exception
Exception
protected void processNioSelections(int selectionCount, Selector selector, ServerSocketChannel server, Map<SocketChannel,TcpNioConnection> connections) throws 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 selector.server
- The server socket channel.connections
- Map of connections.IOException
- Any IOException.protected void doAccept(Selector selector, ServerSocketChannel server, long now) throws IOException
selector
- The selector.server
- The server socket channel.now
- The current time.IOException
- Any IOException.public boolean isAutoStartup()
isAutoStartup
in interface SmartLifecycle
public void stop(Runnable callback)
stop
in interface SmartLifecycle
protected void addConnection(TcpConnectionSupport connection)
protected void harvestClosedConnections()
protected boolean isActive()
protected void setActive(boolean active)
active
- the active to setprotected void checkActive() throws IOException
IOException
protected TcpSocketSupport getTcpSocketSupport()
public void setTcpSocketSupport(TcpSocketSupport tcpSocketSupport)
public List<String> getOpenConnectionIds()
TcpConnection
connection ids; allows,
for example, broadcast operations to all open connections.public boolean closeConnection(String connectionId)
connectionId
- the connection id.