Class TcpInboundGateway
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.endpoint.AbstractEndpoint
org.springframework.integration.gateway.MessagingGatewaySupport
org.springframework.integration.ip.tcp.TcpInboundGateway
- All Implemented Interfaces:
Aware
,BeanFactoryAware
,BeanNameAware
,DisposableBean
,InitializingBean
,ApplicationContextAware
,Lifecycle
,Phased
,SmartLifecycle
,ExpressionCapable
,OrderlyShutdownCapable
,IntegrationPattern
,ClientModeCapable
,TcpListener
,TcpSender
,NamedComponent
,IntegrationInboundManagement
,IntegrationManagement
,ManageableLifecycle
,ManageableSmartLifecycle
,TrackableComponent
public class TcpInboundGateway extends MessagingGatewaySupport implements TcpListener, TcpSender, ClientModeCapable, OrderlyShutdownCapable
Inbound Gateway using a server connection factory - threading is controlled by the
factory. For java.net connections, each socket can process only one message at a time.
For java.nio connections, messages may be multiplexed but the client will need to
provide correlation logic. If the client is a
TcpOutboundGateway
multiplexing
is not used, but multiple concurrent connections can be used if the connection factory uses
single-use connections. For true asynchronous bi-directional communication, a pair of
inbound / outbound channel adapters should be used.- Since:
- 2.0
- Author:
- Gary Russell, Artem Bilan
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides
-
Field Summary
Fields Modifier and Type Field Description static long
DEFAULT_RETRY_INTERVAL
A default retry interval in milliseconds - 60000L.Fields inherited from class org.springframework.integration.gateway.MessagingGatewaySupport
messagingTemplate
Fields inherited from class org.springframework.integration.endpoint.AbstractEndpoint
lifecycleCondition, lifecycleLock
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
-
Constructor Summary
Constructors Constructor Description TcpInboundGateway()
-
Method Summary
Modifier and Type Method Description void
addNewConnection(TcpConnection connection)
When we are using sockets owned by aTcpListener
, this method is called each time a new connection is made.int
afterShutdown()
Called after normal shutdown of schedulers, executors etc, and after the shutdown delay has elapsed, but before any forced shutdown of any remaining active scheduler/executor threads.Can optionally return the number of active messages still in process.int
beforeShutdown()
Called before shutdown begins.protected void
doStart()
Subclasses must implement this method with the start behavior.protected void
doStop()
Subclasses must implement this method with the stop behavior.String
getComponentType()
Subclasses may implement this method to provide component type information.long
getRetryInterval()
boolean
isClientMode()
boolean
isClientModeConnected()
boolean
isListening()
protected void
onInit()
Subclasses may implement this for initialization logic.boolean
onMessage(Message<?> message)
Called by a TCPConnection when a new message arrives.void
removeDeadConnection(TcpConnection connection)
When we are using sockets owned by aTcpListener
, this method is called each time a connection is closed.void
retryConnection()
Immediately attempt to establish the connection.void
setClientMode(boolean isClientMode)
void
setConnectionFactory(AbstractConnectionFactory connectionFactory)
void
setRetryInterval(long retryInterval)
Configure a retry interval.Methods inherited from class org.springframework.integration.gateway.MessagingGatewaySupport
buildErrorMessage, buildSendTimer, destroy, getErrorChannel, getErrorMessageAttributes, getIntegrationPatternType, getManagedName, getManagedType, getOverrides, getReplyChannel, getRequestChannel, isLoggingEnabled, receive, receive, receiveMessage, receiveMessage, registerMetricsCaptor, registerReplyMessageCorrelatorIfNecessary, send, sendAndReceive, sendAndReceiveMessage, sendAndReceiveMessageReactive, sendTimer, setErrorChannel, setErrorChannelName, setErrorMessageStrategy, setErrorOnTimeout, setLoggingEnabled, setManagedName, setManagedType, setReplyChannel, setReplyChannelName, setReplyMapper, setReplyTimeout, setRequestChannel, setRequestChannelName, setRequestMapper, setRequestTimeout, setShouldTrack
Methods inherited from class org.springframework.integration.endpoint.AbstractEndpoint
doStop, getPhase, getRole, isActive, isAutoStartup, isRunning, setAutoStartup, setPhase, setRole, start, stop, stop
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, 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 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 in milliseconds - 60000L.- See Also:
- Constant Field Values
-
-
Constructor Details
-
TcpInboundGateway
public TcpInboundGateway()
-
-
Method Details
-
onMessage
Description copied from interface:TcpListener
Called by a TCPConnection when a new message arrives.- Specified by:
onMessage
in interfaceTcpListener
- Parameters:
message
- The message.- Returns:
- true if the message was intercepted
-
isListening
public boolean isListening()- Returns:
- true if the associated connection factory is listening.
-
setConnectionFactory
- Parameters:
connectionFactory
- the Connection Factory
-
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 classMessagingGatewaySupport
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupport
Subclasses may implement this for initialization logic.- Overrides:
onInit
in classMessagingGatewaySupport
-
doStart
protected void doStart()Description copied from class:AbstractEndpoint
Subclasses must implement this method with the start behavior. This method will be invoked while holding theAbstractEndpoint.lifecycleLock
.- Overrides:
doStart
in classMessagingGatewaySupport
-
doStop
protected void doStop()Description copied from class:AbstractEndpoint
Subclasses must implement this method with the stop behavior. This method will be invoked while holding theAbstractEndpoint.lifecycleLock
.- Overrides:
doStop
in classMessagingGatewaySupport
-
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)Configure a retry interval. Defaults toDEFAULT_RETRY_INTERVAL
.- 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
-
beforeShutdown
public int beforeShutdown()Description copied from interface:OrderlyShutdownCapable
Called before shutdown begins. Implementations should stop accepting new messages. Can optionally return the number of active messages in process.- Specified by:
beforeShutdown
in interfaceOrderlyShutdownCapable
- Returns:
- The number of active messages if available.
-
afterShutdown
public int afterShutdown()Description copied from interface:OrderlyShutdownCapable
Called after normal shutdown of schedulers, executors etc, and after the shutdown delay has elapsed, but before any forced shutdown of any remaining active scheduler/executor threads.Can optionally return the number of active messages still in process.- Specified by:
afterShutdown
in interfaceOrderlyShutdownCapable
- Returns:
- The number of active messages if available.
-