nachos.kernel.filesys
Class Message

java.lang.Object
  extended by nachos.kernel.filesys.Message

public class Message
extends java.lang.Object

Class for messages representing a request to or a reply from a distributed filesystem (DFS) server.


Field Summary
static int BlockSize
          The size of data blocks used in the distributed filesystem.
static int CloseReq
          A type of DFS message, used as a value of field msgType.
static int CreateReq
          A type of DFS message, used as a value of field msgType.
 byte[] data
          The file data to write or read.
 int fileDesc
          The file descriptor.
 java.lang.String filename
          The file name.
static int headerLength
          Length of the message header, in bytes.
 int msgType
          type of message.
static java.lang.String[] msgTypeNames
          Names of the types of DFS messages (useful for debugging).
 int numBytes
          The number of bytes to be read, or the number of bytes successfully written.
static int OpenReply
          A type of DFS message, used as a value of field msgType.
static int OpenReq
          A type of DFS message, used as a value of field msgType.
 int position
          The starting position within the file.
static int ReadReply
          A type of DFS message, used as a value of field msgType.
static int ReadReq
          A type of DFS message, used as a value of field msgType.
static int RemoveReq
          A type of DFS message, used as a value of field msgType.
static int WriteReply
          A type of DFS message, used as a value of field msgType.
static int WriteReq
          A type of DFS message, used as a value of field msgType.
 
Constructor Summary
Message(byte[] msgAsBytes)
          Create a new message, and initialize it using the specified array of bytes, which should have been produced by Message.toByteArray.
Message(int msgType, int fileDesc, int position, int numBytes, java.lang.String filename, byte[] data)
          Allocate a new message, using the specified parameters, which have the same meaning as the fields with the same names.
 
Method Summary
 byte[] toByteArray()
          Returns this message represented as an array of bytes.
 java.lang.String toString()
          Returns this message represented as a string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

OpenReq

public static final int OpenReq
A type of DFS message, used as a value of field msgType.

See Also:
Constant Field Values

CloseReq

public static final int CloseReq
A type of DFS message, used as a value of field msgType.

See Also:
Constant Field Values

ReadReq

public static final int ReadReq
A type of DFS message, used as a value of field msgType.

See Also:
Constant Field Values

WriteReq

public static final int WriteReq
A type of DFS message, used as a value of field msgType.

See Also:
Constant Field Values

CreateReq

public static final int CreateReq
A type of DFS message, used as a value of field msgType.

See Also:
Constant Field Values

RemoveReq

public static final int RemoveReq
A type of DFS message, used as a value of field msgType.

See Also:
Constant Field Values

OpenReply

public static final int OpenReply
A type of DFS message, used as a value of field msgType.

See Also:
Constant Field Values

ReadReply

public static final int ReadReply
A type of DFS message, used as a value of field msgType.

See Also:
Constant Field Values

WriteReply

public static final int WriteReply
A type of DFS message, used as a value of field msgType.

See Also:
Constant Field Values

msgTypeNames

public static final java.lang.String[] msgTypeNames
Names of the types of DFS messages (useful for debugging).


msgType

public int msgType
type of message.


fileDesc

public int fileDesc
The file descriptor. This field is meaningful iff msgType is CloseReq, ReadReq, WriteReq, or OpenReply.


position

public int position
The starting position within the file. This field is meaningful iff msgType is ReadReq, WriteReq.


numBytes

public int numBytes
The number of bytes to be read, or the number of bytes successfully written. This field is meaningful iff msgType is ReadReq or WriteReply.


filename

public java.lang.String filename
The file name. This field is meaningful iff msgType is OpenReq, CreateReq, or RemoveReq. Otherwise, filename should be null.


data

public byte[] data
The file data to write or read. This field is meaningful iff msgType is WriteReq or ReadReply. If msgType is not WriteReq or ReadReply, data should be null.


headerLength

public static final int headerLength
Length of the message header, in bytes. The header consists of all fields except filename and data. Each field occupies 1 byte, except the position field, which occupies 2 bytes.

See Also:
Constant Field Values

BlockSize

public static final int BlockSize
The size of data blocks used in the distributed filesystem. To ensure that a Message containing a block of data will fit in packet, we require BlockSize <= Packet.maxContentsLength - Message.headerLength.

See Also:
Constant Field Values
Constructor Detail

Message

public Message(int msgType,
               int fileDesc,
               int position,
               int numBytes,
               java.lang.String filename,
               byte[] data)
Allocate a new message, using the specified parameters, which have the same meaning as the fields with the same names.


Message

public Message(byte[] msgAsBytes)
Create a new message, and initialize it using the specified array of bytes, which should have been produced by Message.toByteArray.

Parameters:
msgAsBytes - the message, represented as an array of bytes.
Method Detail

toByteArray

public byte[] toByteArray()
Returns this message represented as an array of bytes.

Returns:
this message, represented as an array of bytes.

toString

public java.lang.String toString()
Returns this message represented as a string. Useful for debugging.

Overrides:
toString in class java.lang.Object
Returns:
this message, represented as a string.