Class TcpNioConnection
java.lang.Object
org.springframework.integration.ip.tcp.connection.TcpConnectionSupport
org.springframework.integration.ip.tcp.connection.TcpNioConnection
- All Implemented Interfaces:
java.lang.Runnable,TcpConnection
- Direct Known Subclasses:
TcpNioSSLConnection
public class TcpNioConnection extends TcpConnectionSupport
A TcpConnection that uses and underlying
SocketChannel.- Since:
- 2.0
-
Field Summary
Fields inherited from class org.springframework.integration.ip.tcp.connection.TcpConnectionSupport
logger -
Constructor Summary
Constructors Constructor Description TcpNioConnection(java.nio.channels.SocketChannel socketChannel, boolean server, boolean lookupHost, org.springframework.context.ApplicationEventPublisher applicationEventPublisher, java.lang.String connectionFactoryName)Constructs a TcpNetConnection for the SocketChannel. -
Method Summary
Modifier and Type Method Description protected java.nio.ByteBufferallocate(int length)Allocates a ByteBuffer of the requested length using normal or direct buffers, depending on the usingDirectBuffers field.voidclose()Closes this connection.protected org.springframework.integration.ip.tcp.connection.TcpNioConnection.ChannelOutputStreamgetChannelOutputStream()java.lang.ObjectgetDeserializerStateKey()longgetLastRead()longgetLastSend()java.lang.ObjectgetPayload()Uses the deserializer to obtain the message payload from the connection's input stream.intgetPort()javax.net.ssl.SSLSessiongetSslSession()protected java.io.InputStreaminputStream()Subclasses can override this, for example to wrap the input stream.booleanisOpen()protected booleanisUsingDirectBuffers()voidreadPacket()Invoked by the factory when there is data to be read.voidrun()If there is no listener, this method exits.voidsend(org.springframework.messaging.Message<?> message)Converts and sends the message.protected voidsendToPipe(java.nio.ByteBuffer rawBufferToSend)voidsetLastRead(long lastRead)voidsetPipeTimeout(long pipeTimeout)voidsetTaskExecutor(java.util.concurrent.Executor taskExecutor)voidsetUsingDirectBuffers(boolean usingDirectBuffers)If true, connection will attempt to use direct buffers where possible.voidshutdownInput()Set the socket's input stream to end of stream.voidshutdownOutput()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, toString
-
Constructor Details
-
TcpNioConnection
public TcpNioConnection(java.nio.channels.SocketChannel socketChannel, boolean server, boolean lookupHost, @Nullable org.springframework.context.ApplicationEventPublisher applicationEventPublisher, @Nullable java.lang.String connectionFactoryName)Constructs 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:TcpConnectionSupportCloses this connection.- Specified by:
closein interfaceTcpConnection- Overrides:
closein classTcpConnectionSupport
-
isOpen
public boolean isOpen()- Returns:
- true if the connection is open.
-
send
public void send(org.springframework.messaging.Message<?> message)Description copied from interface:TcpConnectionConverts and sends the message.- Parameters:
message- The message,
-
getPayload
public java.lang.Object 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
public java.lang.Object 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
@Nullable public javax.net.ssl.SSLSession getSslSession()- Returns:
- the
SSLSessionassociated with this connection, if SSL is in use, null otherwise.
-
inputStream
protected java.io.InputStream inputStream()Subclasses can override this, for example to wrap the input stream.- Returns:
- the input stream.
- Since:
- 5.0
-
allocate
protected java.nio.ByteBuffer allocate(int length)Allocates 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
protected void sendToPipe(java.nio.ByteBuffer rawBufferToSend) throws java.io.IOException- Throws:
java.io.IOException
-
readPacket
public void readPacket()Invoked by the factory when there is data to be read. -
setTaskExecutor
public void setTaskExecutor(java.util.concurrent.Executor taskExecutor)- 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
public void shutdownInput() throws java.io.IOExceptionSet the socket's input stream to end of stream.- Throws:
java.io.IOException- an IO Exception.- Since:
- 5.2
- See Also:
SocketChannel.shutdownInput()
-
shutdownOutput
public void shutdownOutput() throws java.io.IOExceptionDisable the socket's output stream.- Throws:
java.io.IOException- an IO Exception- Since:
- 5.2
- See Also:
SocketChannel.shutdownOutput()
-