public class DataServerMessage extends Object
Modifier and Type | Field and Description |
---|---|
static short |
DATA_SERVER_REQUEST_MESSAGE |
static short |
DATA_SERVER_RESPONSE_MESSAGE |
Modifier and Type | Method and Description |
---|---|
void |
checkReady()
Check if the message is ready.
|
void |
close()
Close the message.
|
static DataServerMessage |
createBlockRequestMessage()
Create a default block request message, just allocate the message header, and no attribute is
set.
|
static DataServerMessage |
createBlockRequestMessage(long blockId)
Create a block request message specified by the block's id, and the message is ready to be
sent.
|
static DataServerMessage |
createBlockRequestMessage(long blockId,
long offset,
long len)
Create a block request message specified by the block's id, the offset and the length.
|
static DataServerMessage |
createBlockResponseMessage(boolean toSend,
long blockId)
Create a block response message specified by the block's id.
|
static DataServerMessage |
createBlockResponseMessage(boolean toSend,
long blockId,
long offset,
long len)
Create a block response message specified by the block's id, the offset and the length.
|
boolean |
finishSending()
Return whether the message finishes sending or not.
|
long |
getBlockId()
Get the id of the block.
|
long |
getLength()
Get the length of the message's requested or responded data.
|
long |
getOffset()
Get the offset of the message's data in the block.
|
ByteBuffer |
getReadOnlyData()
Get the read only buffer of the message's data.
|
boolean |
isMessageReady() |
int |
recv(SocketChannel socketChannel)
Use this message to receive from the specified socket channel.
|
void |
send(SocketChannel socketChannel)
Send this message to the specified socket channel.
|
public static final short DATA_SERVER_REQUEST_MESSAGE
public static final short DATA_SERVER_RESPONSE_MESSAGE
public static DataServerMessage createBlockRequestMessage()
public static DataServerMessage createBlockRequestMessage(long blockId)
blockId
- The id of the blockpublic static DataServerMessage createBlockRequestMessage(long blockId, long offset, long len)
len
is -1, it means request the data from offset
to the block's end.blockId
- The id of the blockoffset
- The requested data's offset in the blocklen
- The length of the requested data. If it's -1, it means request the data from offset to
the block's end.public static DataServerMessage createBlockResponseMessage(boolean toSend, long blockId)
toSend
is true, it
will prepare the data to be sent, otherwise the message is used to receive data.toSend
- If true the message is to send the data, otherwise it's used to receive data.blockId
- The id of the blockpublic static DataServerMessage createBlockResponseMessage(boolean toSend, long blockId, long offset, long len)
toSend
is true, it will prepare the data to be sent, otherwise the message is used
to receive data. If len
is -1, it means response the data from offset to the
block's end.toSend
- If true the message is to send the data, otherwise it's used to receive datablockId
- The id of the blockoffset
- The responded data's offset in the blocklen
- The length of the responded data. If it's -1, it means respond the data from offset to
the block's end.public void checkReady()
public void close()
public boolean finishSending()
public long getBlockId()
public long getLength()
public long getOffset()
public ByteBuffer getReadOnlyData()
public boolean isMessageReady()
public int recv(SocketChannel socketChannel) throws IOException
socketChannel
- The socket channel to receive fromIOException
public void send(SocketChannel socketChannel) throws IOException
socketChannel
- The socket channel to send toIOException
Copyright © 2014. All rights reserved.