public final class DataServerMessage extends Object
| Modifier and Type | Method and Description |
|---|---|
void |
checkReady()
Checks if the message is ready.
|
void |
close()
Closes the message.
|
static DataServerMessage |
createBlockRequestMessage()
Creates a default block request message, just allocates the message header, and no attribute is
set.
|
static DataServerMessage |
createBlockRequestMessage(long blockId)
Creates a block request message for an entire block by the block id, and the message is ready
to be sent.
|
static DataServerMessage |
createBlockRequestMessage(long blockId,
long offset,
long len)
Creates a block request message for a part of the block by the block id, the offset and the
length.
|
static DataServerMessage |
createBlockResponseMessage(boolean toSend,
long blockId,
ByteBuffer data)
Creates a block response message specified by the block's id.
|
static DataServerMessage |
createBlockResponseMessage(boolean toSend,
long blockId,
long offset,
long len,
ByteBuffer data)
Creates a block response message specified by the block's id, the offset and the length.
|
boolean |
finishSending()
Returns whether the message finishes sending or not.
|
long |
getBlockId()
Gets the id of the block.
|
long |
getLength()
Gets the length of the message's requested or responded data.
|
long |
getLockId()
Gets the id of the block's locker.
|
long |
getOffset()
Gets the offset of the message's data in the block.
|
ByteBuffer |
getReadOnlyData()
Gets the read only buffer of the message's data.
|
RPCResponse.Status |
getStatus()
Gets the status of the response.
|
boolean |
isMessageReady() |
int |
recv(SocketChannel socketChannel)
Use this message to receive from the specified socket channel.
|
void |
send(SocketChannel socketChannel)
Sends this message to the specified socket channel.
|
void |
setLockId(long lockId)
Sets the id of the block's locker.
|
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 requesting the
data from offset to the end of the block.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, ByteBuffer data)
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 blockdata - The data of the messagepublic static DataServerMessage createBlockResponseMessage(boolean toSend, long blockId, long offset, long len, ByteBuffer data)
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.data - The data of the messagepublic void checkReady()
public void close()
public boolean finishSending()
public long getBlockId()
public long getLength()
public long getLockId()
public long getOffset()
public RPCResponse.Status getStatus()
RPCResponse.Status of the responsepublic ByteBuffer getReadOnlyData()
public boolean isMessageReady()
public int recv(SocketChannel socketChannel) throws IOException
socketChannel - The socket channel to receive fromIOExceptionpublic void send(SocketChannel socketChannel) throws IOException
socketChannel - The socket channel to send toIOExceptionpublic void setLockId(long lockId)
lockId - The id of the block's lockerCopyright © 2015. All Rights Reserved.