Class TcpSendingMessageHandler
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.handler.MessageHandlerSupport
org.springframework.integration.handler.AbstractMessageHandler
org.springframework.integration.ip.tcp.TcpSendingMessageHandler
- All Implemented Interfaces:
org.reactivestreams.Subscriber<Message<?>>
,Aware
,BeanFactoryAware
,BeanNameAware
,DisposableBean
,InitializingBean
,ApplicationContextAware
,Lifecycle
,Ordered
,ExpressionCapable
,Orderable
,IntegrationPattern
,ClientModeCapable
,TcpSender
,NamedComponent
,IntegrationManagement
,ManageableLifecycle
,TrackableComponent
,MessageHandler
,reactor.core.CoreSubscriber<Message<?>>
public class TcpSendingMessageHandler
extends AbstractMessageHandler
implements TcpSender, ManageableLifecycle, ClientModeCapable
Tcp outbound channel adapter using a TcpConnection to
send data - if the connection factory is a server
factory, the TcpListener owns the connections. If it is
a client factory, this object owns the connection.
- Since:
- 2.0
- Author:
- Gary Russell, Artem Bilan, Christian Tzolov
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides
-
Field Summary
Modifier and TypeFieldDescriptionstatic final long
A default retry interval for theClientModeConnectionManager
rescheduling.protected final Lock
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
Fields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME
Fields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addNewConnection
(TcpConnection connection) When we are using sockets owned by aTcpListener
, this method is called each time a new connection is made.protected TcpConnection
Method that actually does the write.protected ConnectionFactory
Subclasses may implement this method to provide component type information.protected Map<String,
TcpConnection> long
protected ConnectionFactory
void
handleMessageInternal
(Message<?> message) Writes the message payload to the underlying socket, using the specified message format.boolean
boolean
boolean
protected TcpConnection
obtainConnection
(Message<?> message) protected void
onInit()
Subclasses may implement this for initialization logic.void
removeDeadConnection
(TcpConnection connection) When we are using sockets owned by aTcpListener
, this method is called each time a connection is closed.void
Immediately attempt to establish the connection.void
setClientMode
(boolean isClientMode) void
setConnectionFactory
(AbstractConnectionFactory connectionFactory) Sets the client or server connection factory; for this (an outbound adapter), if the factory is a server connection factory, the sockets are owned by a receiving channel adapter and this adapter is used to send replies.void
setRetryInterval
(long retryInterval) void
start()
void
stop()
Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler
handleMessage, onComplete, onError, onNext, onSubscribe, setObservationConvention
Methods inherited from class org.springframework.integration.handler.MessageHandlerSupport
buildSendTimer, destroy, getIntegrationPatternType, getManagedName, getManagedType, getMetricsCaptor, getObservationRegistry, getOrder, getOverrides, isLoggingEnabled, isObserved, registerMetricsCaptor, registerObservationRegistry, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrack
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface reactor.core.CoreSubscriber
currentContext
Methods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getThisAs
Methods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
Field Details
-
DEFAULT_RETRY_INTERVAL
public static final long DEFAULT_RETRY_INTERVALA default retry interval for theClientModeConnectionManager
rescheduling.- See Also:
-
lifecycleMonitor
-
-
Constructor Details
-
TcpSendingMessageHandler
public TcpSendingMessageHandler()
-
-
Method Details
-
obtainConnection
-
handleMessageInternal
Writes the message payload to the underlying socket, using the specified message format.- Specified by:
handleMessageInternal
in classAbstractMessageHandler
- See Also:
-
doWrite
Method that actually does the write.- Parameters:
message
- The message to write.- Returns:
- the connection.
-
setConnectionFactory
Sets the client or server connection factory; for this (an outbound adapter), if the factory is a server connection factory, the sockets are owned by a receiving channel adapter and this adapter is used to send replies.- Parameters:
connectionFactory
- the connectionFactory to set
-
addNewConnection
Description copied from interface:TcpSender
When we are using sockets owned by aTcpListener
, this method is called each time a new connection is made.- Specified by:
addNewConnection
in interfaceTcpSender
- Parameters:
connection
- The connection.
-
removeDeadConnection
Description copied from interface:TcpSender
When we are using sockets owned by aTcpListener
, this method is called each time a connection is closed.- Specified by:
removeDeadConnection
in interfaceTcpSender
- Parameters:
connection
- The connection.
-
getComponentType
Description copied from class:IntegrationObjectSupport
Subclasses may implement this method to provide component type information.- Specified by:
getComponentType
in interfaceNamedComponent
- Overrides:
getComponentType
in classMessageHandlerSupport
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupport
Subclasses may implement this for initialization logic.- Overrides:
onInit
in classIntegrationObjectSupport
-
start
public void start()- Specified by:
start
in interfaceLifecycle
- Specified by:
start
in interfaceManageableLifecycle
-
stop
public void stop()- Specified by:
stop
in interfaceLifecycle
- Specified by:
stop
in interfaceManageableLifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunning
in interfaceLifecycle
- Specified by:
isRunning
in interfaceManageableLifecycle
-
getClientConnectionFactory
- Returns:
- the clientConnectionFactory
-
getServerConnectionFactory
- Returns:
- the serverConnectionFactory
-
getConnections
- Returns:
- the connections
-
isClientMode
public boolean isClientMode()- Specified by:
isClientMode
in interfaceClientModeCapable
- Returns:
- the isClientMode
-
setClientMode
public void setClientMode(boolean isClientMode) - Parameters:
isClientMode
- the isClientMode to set
-
getRetryInterval
public long getRetryInterval()- Returns:
- the retryInterval
-
setRetryInterval
public void setRetryInterval(long retryInterval) - Parameters:
retryInterval
- the retryInterval to set
-
isClientModeConnected
public boolean isClientModeConnected()- Specified by:
isClientModeConnected
in interfaceClientModeCapable
- Returns:
- true if the endpoint is running in client mode.
-
retryConnection
public void retryConnection()Description copied from interface:ClientModeCapable
Immediately attempt to establish the connection.- Specified by:
retryConnection
in interfaceClientModeCapable
-