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
public class TcpNioConnection extends TcpConnectionSupport
A TcpConnection that uses and underlying
SocketChannel
.- Since:
- 2.0
- Author:
- Gary Russell, John Anderson, Artem Bilan
-
Field Summary
Fields inherited from class org.springframework.integration.ip.tcp.connection.TcpConnectionSupport
logger
-
Constructor Summary
Constructors Constructor Description TcpNioConnection(SocketChannel socketChannel, boolean server, boolean lookupHost, ApplicationEventPublisher applicationEventPublisher, String connectionFactoryName)
Construct a TcpNetConnection for the SocketChannel. -
Method Summary
Modifier and Type Method Description protected ByteBuffer
allocate(int length)
Allocate a ByteBuffer of the requested length using normal or direct buffers, depending on the usingDirectBuffers field.void
close()
Close this connection.protected org.springframework.integration.ip.tcp.connection.TcpNioConnection.ChannelOutputStream
getChannelOutputStream()
Object
getDeserializerStateKey()
long
getLastRead()
long
getLastSend()
Object
getPayload()
Uses the deserializer to obtain the message payload from the connection's input stream.int
getPort()
SSLSession
getSslSession()
protected InputStream
inputStream()
Subclasses can override this, for example to wrap the input stream.boolean
isOpen()
protected boolean
isUsingDirectBuffers()
void
readPacket()
Invoked by the factory when there is data to be read.void
run()
If there is no listener, this method exits.void
send(Message<?> message)
Converts and sends the message.protected void
sendToPipe(ByteBuffer rawBufferToSend)
void
setLastRead(long lastRead)
void
setPipeTimeout(long pipeTimeout)
void
setTaskExecutor(Executor taskExecutor)
void
setUsingDirectBuffers(boolean usingDirectBuffers)
If true, connection will attempt to use direct buffers where possible.void
shutdownInput()
Set the socket's input stream to end of stream.void
shutdownOutput()
Disable 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:TcpConnectionSupport
Close this connection.- Specified by:
close
in interfaceTcpConnection
- Overrides:
close
in classTcpConnectionSupport
-
isOpen
public boolean isOpen()- Returns:
- true if the connection is open.
-
send
Description copied from interface:TcpConnection
Converts and sends the message.- Parameters:
message
- The message,
-
getPayload
Description copied from interface:TcpConnection
Uses 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
Deserializer
that 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
SSLSession
associated 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:
SocketChannel.shutdownInput()
-
shutdownOutput
Disable the socket's output stream.- Throws:
IOException
- an IO Exception- Since:
- 5.2
- See Also:
SocketChannel.shutdownOutput()
-