|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object de.netseeker.ejoe.io.DataChannel
public class DataChannel
Utility class handling all socket oriented data IO on nio channels. DataChannels must be implemented as singletons to avoid creation of a new object for each socket IO operation. Otherwise heavy load could result in fast-growing memory consumption.
Constructor Summary | |
---|---|
protected |
DataChannel()
Singleton with hidden constructor, only child classes are allowed to construct new instances |
Method Summary | |
---|---|
java.nio.ByteBuffer |
decode(java.nio.ByteBuffer buffer)
Decodes and reformats request data if the underlying protocol layer makes it neccessary |
static DataChannel |
getInstance()
Invoking this method has the same effect as invoking DataChannel#getInstance(null) |
static DataChannel |
getInstance(ConnectionHeader header)
Returns appropiate instance of DataChannel for the given connection header. |
ConnectionHeader |
handshake(ConnectionHeader header,
java.nio.channels.SocketChannel channel,
long timeout)
Handshake for a socket channel. |
static void |
nonBlockingRead(java.nio.channels.ReadableByteChannel channel,
java.nio.ByteBuffer buffer)
Tries to send the given ByteBuffer completely through the given SocketChannel within a given timeout |
void |
nonBlockingWrite(java.nio.channels.WritableByteChannel channel,
java.nio.ByteBuffer buffer)
Tries to send the given ByteBuffer completely through the given SocketChannel three times |
int |
readHeader(ConnectionHeader header,
long timeout)
Receives a EJOE specific header containing the size of the next ByteBuffer. |
static void |
semiBlockingRead(java.nio.channels.ReadableByteChannel channel,
java.nio.ByteBuffer buffer,
long timeout)
Tries to read ByteBuffer.remaining() bytes the into given ByteBuffer from the given SocketChannel within a given timeout. |
void |
semiBlockingWrite(java.nio.channels.WritableByteChannel channel,
java.nio.ByteBuffer buffer,
long timeout)
Tries to send the given ByteBuffer completely through the given SocketChannel within a given timeout |
void |
writeHeader(ConnectionHeader header,
java.nio.ByteBuffer buffer,
long timeout)
Sends a EJOE specific header containing the lengh of the given ByteBuffer |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected DataChannel()
Method Detail |
---|
public static DataChannel getInstance()
DataChannel#getInstance(null)
public static DataChannel getInstance(ConnectionHeader header)
header
- a valid connection header or null
public ConnectionHeader handshake(ConnectionHeader header, java.nio.channels.SocketChannel channel, long timeout) throws java.io.IOException, java.text.ParseException
sendBeforeReceive
- if true we will try to send one byte then read one byte otherwise we will use the
opposite way around.
java.io.IOException
java.text.ParseException
public void nonBlockingWrite(java.nio.channels.WritableByteChannel channel, java.nio.ByteBuffer buffer) throws java.io.IOException
channel
- buffer
-
IncompleteIOException
- if the given ByteBuffer could not be send completely
java.io.IOException
public void semiBlockingWrite(java.nio.channels.WritableByteChannel channel, java.nio.ByteBuffer buffer, long timeout) throws java.io.IOException
channel
- buffer
- timeout
-
IncompleteIOException
- if the given ByteBuffer could not be send completely
java.io.IOException
public static void nonBlockingRead(java.nio.channels.ReadableByteChannel channel, java.nio.ByteBuffer buffer) throws java.io.IOException
channel
- buffer
-
java.io.IOException
public static void semiBlockingRead(java.nio.channels.ReadableByteChannel channel, java.nio.ByteBuffer buffer, long timeout) throws java.io.IOException
channel
- buffer
- timeout
-
java.io.IOException
public int readHeader(ConnectionHeader header, long timeout) throws java.io.IOException
timeout
- read timeout
java.io.IOException
public void writeHeader(ConnectionHeader header, java.nio.ByteBuffer buffer, long timeout) throws java.io.IOException
timeout
- write timeout
java.io.IOException
public java.nio.ByteBuffer decode(java.nio.ByteBuffer buffer) throws java.io.UnsupportedEncodingException
buffer
-
java.io.UnsupportedEncodingException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |