Class TcpNioConnection
java.lang.Object
org.springframework.integration.ip.tcp.connection.TcpConnectionSupport
org.springframework.integration.ip.tcp.connection.TcpNioConnection
- All Implemented Interfaces:
Runnable,TcpConnection
- Direct Known Subclasses:
TcpNioSSLConnection
A TcpConnection that uses and underlying
SocketChannel.- Since:
- 2.0
- Author:
- Gary Russell, John Anderson, Artem Bilan, David Herschler Shvo, Christian Tzolov
-
Field Summary
Fields inherited from class org.springframework.integration.ip.tcp.connection.TcpConnectionSupport
logger -
Constructor Summary
ConstructorsConstructorDescriptionTcpNioConnection(SocketChannel socketChannel, boolean server, boolean lookupHost, ApplicationEventPublisher applicationEventPublisher, String connectionFactoryName) Construct a TcpNetConnection for the SocketChannel. -
Method Summary
Modifier and TypeMethodDescriptionprotected ByteBufferallocate(int length) Allocate a ByteBuffer of the requested length using normal or direct buffers, depending on the usingDirectBuffers field.voidclose()Close this connection.protected org.springframework.integration.ip.tcp.connection.TcpNioConnection.ChannelOutputStreamlonglongUses the deserializer to obtain the message payload from the connection's input stream.intgetPort()protected InputStreamSubclasses can override this, for example to wrap the input stream.booleanisOpen()protected booleanvoidInvoked by the factory when there is data to be read.voidrun()If there is no listener, this method exits.voidConverts and sends the message.protected voidsendToPipe(ByteBuffer rawBufferToSend) voidsetLastRead(long lastRead) voidsetPipeTimeout(long pipeTimeout) voidsetTaskExecutor(Executor taskExecutor) voidsetUsingDirectBuffers(boolean usingDirectBuffers) If true, connection will attempt to use direct buffers where possible.voidSet the socket's input stream to end of stream.voidDisable the socket's output stream.Methods inherited from class org.springframework.integration.ip.tcp.connection.TcpConnectionSupport
closeConnection, enableManualListenerRegistration, getConnectionFactoryName, getConnectionId, getDeserializer, getHostAddress, getHostName, getListener, getMapper, getSender, getSenders, getSerializer, getSocketInfo, incrementAndGetConnectionSequence, isNoReadErrorOnClose, isServer, publishConnectionCloseEvent, publishConnectionExceptionEvent, publishConnectionOpenEvent, publishEvent, registerListener, registerSender, registerSenders, registerTestListener, sendExceptionToListener, setDeserializer, setMapper, setNeedsTest, setNoReadErrorOnClose, setSerializer, setWrapped, setWrapper, toString
-
Constructor Details
-
TcpNioConnection
public TcpNioConnection(SocketChannel socketChannel, boolean server, boolean lookupHost, @Nullable ApplicationEventPublisher applicationEventPublisher, @Nullable String connectionFactoryName) Construct a TcpNetConnection for the SocketChannel.- Parameters:
socketChannel- The socketChannel.server- If true, this connection was created as a result of an incoming request.lookupHost- true to perform reverse lookups.applicationEventPublisher- The event publisher.connectionFactoryName- The name of the connection factory creating this connection.
-
-
Method Details
-
setPipeTimeout
public void setPipeTimeout(long pipeTimeout) -
close
public void close()Description copied from class:TcpConnectionSupportClose this connection.- Specified by:
closein interfaceTcpConnection- Overrides:
closein classTcpConnectionSupport
-
isOpen
public boolean isOpen()- Returns:
- true if the connection is open.
-
send
Description copied from interface:TcpConnectionConverts and sends the message.- Parameters:
message- The message,
-
getPayload
Description copied from interface:TcpConnectionUses the deserializer to obtain the message payload from the connection's input stream.- Returns:
- The payload.
-
getPort
public int getPort()- Returns:
- the port
-
getDeserializerStateKey
- Returns:
- a key that can be used to reference state in a
Deserializerthat maintains state for this connection. Currently, this would be the InputStream associated with the connection, but the object should be treated as opaque and ONLY used as a key.
-
getSslSession
- Returns:
- the
SSLSessionassociated with this connection, if SSL is in use, null otherwise.
-
inputStream
Subclasses can override this, for example to wrap the input stream.- Returns:
- the input stream.
- Since:
- 5.0
-
allocate
Allocate a ByteBuffer of the requested length using normal or direct buffers, depending on the usingDirectBuffers field.- Parameters:
length- The buffer length.- Returns:
- The buffer.
-
run
public void run()If there is no listener, this method exits. When there is a listener, this method assembles data into messages by invoking convertAndSend whenever there is data in the input Stream. Method exits when a message is complete and there is no more data; thus freeing the thread to work on other sockets. -
sendToPipe
- Throws:
IOException
-
readPacket
public void readPacket()Invoked by the factory when there is data to be read. -
setTaskExecutor
- Parameters:
taskExecutor- the taskExecutor to set
-
setUsingDirectBuffers
public void setUsingDirectBuffers(boolean usingDirectBuffers) If true, connection will attempt to use direct buffers where possible.- Parameters:
usingDirectBuffers- the usingDirectBuffers to set.
-
isUsingDirectBuffers
protected boolean isUsingDirectBuffers() -
getChannelOutputStream
protected org.springframework.integration.ip.tcp.connection.TcpNioConnection.ChannelOutputStream getChannelOutputStream() -
getLastRead
public long getLastRead()- Returns:
- Time of last read.
-
setLastRead
public void setLastRead(long lastRead) - Parameters:
lastRead- The time of the last read.
-
getLastSend
public long getLastSend()- Returns:
- the time of the last send
-
shutdownInput
Set the socket's input stream to end of stream.- Throws:
IOException- an IO Exception.- Since:
- 5.2
- See Also:
-
shutdownOutput
Disable the socket's output stream.- Throws:
IOException- an IO Exception- Since:
- 5.2
- See Also:
-