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 class org.springframework.integration.gateway.MessagingGatewaySupport
MessagingGatewaySupport.ConvertingMessagingTemplateNested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longA default retry interval in milliseconds - 60000L.Fields inherited from class org.springframework.integration.gateway.MessagingGatewaySupport
messagingTemplateFields inherited from class org.springframework.integration.endpoint.AbstractEndpoint
lifecycleCondition, lifecycleLockFields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, loggerFields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAMEFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddNewConnection(TcpConnection connection) When we are using sockets owned by aTcpListener, this method is called each time a new connection is made.intCalled 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.intCalled before shutdown begins.protected voiddoStart()Subclasses must implement this method with the start behavior.protected voiddoStop()Subclasses must implement this method with the stop behavior.Subclasses may implement this method to provide component type information.longbooleanbooleanbooleanprotected voidonInit()Subclasses may implement this for initialization logic.booleanCalled by a TCPConnection when a new message arrives.voidremoveDeadConnection(TcpConnection connection) When we are using sockets owned by aTcpListener, this method is called each time a connection is closed.voidImmediately attempt to establish the connection.voidsetClientMode(boolean isClientMode) voidsetConnectionFactory(AbstractConnectionFactory connectionFactory) voidsetRetryInterval(long retryInterval) Configure a retry interval.Methods inherited from class org.springframework.integration.gateway.MessagingGatewaySupport
buildErrorMessage, buildSendTimer, destroy, getErrorChannel, getErrorMessageAttributes, getErrorMessageStrategy, getIntegrationPatternType, getManagedName, getManagedType, getOverrides, getReplyChannel, getRequestChannel, isLoggingEnabled, isObserved, receive, receive, receiveMessage, receiveMessage, registerMetricsCaptor, registerObservationRegistry, registerReplyMessageCorrelatorIfNecessary, send, sendAndReceive, sendAndReceiveMessage, sendAndReceiveMessageReactive, sendTimer, setErrorChannel, setErrorChannelName, setErrorMessageStrategy, setErrorOnTimeout, setLoggingEnabled, setManagedName, setManagedType, setObservationConvention, setReceiverObservationConvention, setReplyChannel, setReplyChannelName, setReplyMapper, setReplyTimeout, setRequestChannel, setRequestChannelName, setRequestMapper, setRequestTimeout, setShouldTrackMethods inherited from class org.springframework.integration.endpoint.AbstractEndpoint
doStop, getPhase, getRole, isActive, isAutoStartup, isRunning, setAutoStartup, setPhase, setRole, start, stop, stopMethods 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, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getThisAsMethods 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:
-
-
Constructor Details
-
TcpInboundGateway
public TcpInboundGateway()
-
-
Method Details
-
onMessage
Description copied from interface:TcpListenerCalled by a TCPConnection when a new message arrives.- Specified by:
onMessagein 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:TcpSenderWhen we are using sockets owned by aTcpListener, this method is called each time a new connection is made.- Specified by:
addNewConnectionin interfaceTcpSender- Parameters:
connection- The connection.
-
removeDeadConnection
Description copied from interface:TcpSenderWhen we are using sockets owned by aTcpListener, this method is called each time a connection is closed.- Specified by:
removeDeadConnectionin interfaceTcpSender- Parameters:
connection- The connection.
-
getComponentType
Description copied from class:IntegrationObjectSupportSubclasses may implement this method to provide component type information.- Specified by:
getComponentTypein interfaceNamedComponent- Overrides:
getComponentTypein classMessagingGatewaySupport
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupportSubclasses may implement this for initialization logic.- Overrides:
onInitin classMessagingGatewaySupport
-
doStart
protected void doStart()Description copied from class:AbstractEndpointSubclasses must implement this method with the start behavior. This method will be invoked while holding theAbstractEndpoint.lifecycleLock.- Overrides:
doStartin classMessagingGatewaySupport
-
doStop
protected void doStop()Description copied from class:AbstractEndpointSubclasses must implement this method with the stop behavior. This method will be invoked while holding theAbstractEndpoint.lifecycleLock.- Overrides:
doStopin classMessagingGatewaySupport
-
isClientMode
public boolean isClientMode()- Specified by:
isClientModein 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:
isClientModeConnectedin interfaceClientModeCapable- Returns:
- true if the endpoint is running in client mode.
-
retryConnection
public void retryConnection()Description copied from interface:ClientModeCapableImmediately attempt to establish the connection.- Specified by:
retryConnectionin interfaceClientModeCapable
-
beforeShutdown
public int beforeShutdown()Description copied from interface:OrderlyShutdownCapableCalled before shutdown begins. Implementations should stop accepting new messages. Can optionally return the number of active messages in process.- Specified by:
beforeShutdownin interfaceOrderlyShutdownCapable- Returns:
- The number of active messages if available.
-
afterShutdown
public int afterShutdown()Description copied from interface:OrderlyShutdownCapableCalled 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:
afterShutdownin interfaceOrderlyShutdownCapable- Returns:
- The number of active messages if available.
-