Package jade.imtp.leap.nio
Class NIOJICPConnection
- java.lang.Object
-
- jade.imtp.leap.JICP.Connection
-
- jade.imtp.leap.nio.NIOJICPConnection
-
- Direct Known Subclasses:
NIOHTTPConnection,NIOJICPSConnection
public class NIOJICPConnection extends Connection
- Author:
- Giovanni Caire - TILAB
-
-
Field Summary
Fields Modifier and Type Field Description static intINITIAL_BUFFER_SIZEstatic intMAX_HEADER_SIZE-
Fields inherited from class jade.imtp.leap.JICP.Connection
socketCnt
-
-
Constructor Summary
Constructors Modifier Constructor Description NIOJICPConnection()protectedNIOJICPConnection(boolean wrapper)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBufferTransformer(BufferTransformer transformer)voidclose()Close the connectionSocketChannelgetChannel()StringgetRemoteHost()booleanisClosed()booleanmoreDataAvailable()JICPPacketreadPacket()Read a JICPPacket from the connection.intwritePacket(JICPPacket pkt)Write a JICPPacket on the connection, first calls#preprocessBufferToWrite(java.nio.ByteBuffer).intwriteToChannel(ByteBuffer bb)writes data to the channel
-
-
-
Field Detail
-
MAX_HEADER_SIZE
public static final int MAX_HEADER_SIZE
- See Also:
- Constant Field Values
-
INITIAL_BUFFER_SIZE
public static final int INITIAL_BUFFER_SIZE
- See Also:
- Constant Field Values
-
-
Method Detail
-
getChannel
public SocketChannel getChannel()
-
readPacket
public JICPPacket readPacket() throws IOException
Read a JICPPacket from the connection. The method is synchronized since we reuse the same Buffer object for reading the packet header. It should be noted that the packet data may not be completely available when the embedded channel is ready for a READ operation. In that case a PacketIncompleteException is thrown to indicate that successive calls to this method must occur in order to fully read the packet.- Specified by:
readPacketin classConnection- Throws:
IOException
-
moreDataAvailable
public boolean moreDataAvailable()
-
writePacket
public int writePacket(JICPPacket pkt) throws IOException
Write a JICPPacket on the connection, first calls#preprocessBufferToWrite(java.nio.ByteBuffer). When the buffer returned by#preprocessBufferToWrite(java.nio.ByteBuffer), no write will be performed.- Specified by:
writePacketin classConnection- Returns:
- number of application bytes written to the socket
- Throws:
IOException
-
writeToChannel
public int writeToChannel(ByteBuffer bb) throws IOException
writes data to the channel- Parameters:
bb-- Returns:
- the number of bytes written to the channel
- Throws:
IOException
-
close
public void close() throws IOExceptionClose the connection- Specified by:
closein classConnection- Throws:
IOException
-
isClosed
public boolean isClosed()
-
getRemoteHost
public String getRemoteHost()
- Specified by:
getRemoteHostin classConnection
-
addBufferTransformer
public void addBufferTransformer(BufferTransformer transformer)
-
-