JanosVM v1.0 API

edu.utah.janosvm.kit.comm.jsi
Class JSIMessage

java.lang.Object
  |
  +--edu.utah.janosvm.kit.comm.jsi.JSIMessage

public class JSIMessage
extends java.lang.Object

The JSIMessage


Field Summary
private  byte[] buffer
          The buffer used when marshalling/unmarshalling a flattened message.
static int CARRIER
           
static int CREATE_PROPERTY
           
private  int cursor
          The current position in the buffer.
static int DELETE_PROPERTY
           
static int ERROR
           
static int EXECUTE_PROPERTY
           
static int GET_PROPERTY
           
static int GET_SUITES
           
private  java.util.Vector identifiers
          The set of identifier/value pairs in the message.
static int LIST_PROPERTIES
           
static java.lang.String[] MESSAGE_TYPE_STRINGS
          An array of strings that correspond to the above message type enumeration.
private  int messageSize
          The size of the flattened message.
static int REPLY
           
static java.lang.String SET_DATA
          The name of the attribute that contains the data to be used in a set.
static int SET_PROPERTY
           
static int SHUTDOWN
           
(package private) static int SIZEOF_INT
          The size of an integer on the wire.
private  int specifierIndex
          The current position in the specifier stack.
private  java.util.Vector specifiers
          The specifier stack.
private  int what
          The type of message.
static int WHAT_MAX
           
static int WHAT_NONE
           
 
Constructor Summary
JSIMessage()
          Construct an empty message.
 
Method Summary
 JSIMessage add(JSIPair jp)
          Add an identifier/value pair to the message.
 JSIMessage add(java.lang.String tag, JSIPropertyInfo value)
          Add an identifier/value pair to the message.
 JSIMessage add(java.lang.String tag, JSIPropertyInfo[] value)
          Add an identifier/value pair to the message.
 JSIMessage add(java.lang.String tag, java.lang.String value)
          Add an identifier/value pair to the message.
(package private) static int alignedSize(int size)
           
 void clear()
          Clear the contents of a message so it can be reused.
 int count(java.lang.String tag)
          Count the number of identifier/value pairs in the message.
 void error(java.lang.String why)
          Clear the message and set it to be error reply with the given data.
 java.lang.String expect(java.lang.String tag)
          Expect an identifier/value pair in the message.
 JSIPair expectPair(java.lang.String tag)
          Expect an identifier/value pair in the message.
private  int findIdentifier(java.lang.String tag, int instance)
          Find an identifier instance in the message.
 byte[] flatten()
           
 java.lang.String get(java.lang.String tag)
          Get an identifier/value pair from the message.
 java.lang.String get(java.lang.String tag, int instance, java.lang.String defaultValue)
          Get an identifier/value pair from the message.
 java.lang.String get(java.lang.String tag, java.lang.String defaultValue)
          Get an identifier/value pair from the message.
 java.util.Vector getIdentifiers()
           
 JSIPair getPair(java.lang.String tag)
          Get an identifier/value pair from the message.
 JSIPair getPair(java.lang.String tag, int instance)
          Get an identifier/value pair from the message.
 int getRemainingSpecifierCount()
           
 int getSpecifierCount()
           
 int getWhat()
           
static JSIMessage instantiate(byte[] msg)
          Instantiate a flattened message.
 JSIPair popSpecifier()
          Pop a specifier off the stack.
 void pushSpecifier(JSIPair jp)
          Push a specifier onto the stack.
 void pushSpecifier(java.lang.String tag)
          Push a specifier onto the stack.
 void pushSpecifier(java.lang.String tag, java.lang.String value)
          Push a specifier onto the stack.
(package private)  byte[] readBytes(int length)
           
(package private)  int readInt()
           
 void remove(java.lang.String tag, int instance)
          Remove an identifier value pair from the message.
 void reply(JSIPropertyInfo[] result)
          Clear the message and set it to be a valid reply with the given data.
 void reply(long result)
          Clear the message and set it to be a valid reply with the given data.
 void reply(java.lang.String result)
          Clear the message and set it to be a valid reply with the given data.
 void restoreSpecifier()
          Restore the last specifier popped off the stack.
 void setWhat(int what)
           
 java.lang.String toString()
           
 void unflatten(byte[] buf)
          Unmarshal the message in this.buffer.
(package private)  void writeBytes(byte[] b)
           
(package private)  void writeInt(int i)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait, wait0
 

Field Detail

WHAT_NONE

public static final int WHAT_NONE

ERROR

public static final int ERROR

SHUTDOWN

public static final int SHUTDOWN

CARRIER

public static final int CARRIER

REPLY

public static final int REPLY

GET_SUITES

public static final int GET_SUITES

LIST_PROPERTIES

public static final int LIST_PROPERTIES

GET_PROPERTY

public static final int GET_PROPERTY

SET_PROPERTY

public static final int SET_PROPERTY

CREATE_PROPERTY

public static final int CREATE_PROPERTY

DELETE_PROPERTY

public static final int DELETE_PROPERTY

EXECUTE_PROPERTY

public static final int EXECUTE_PROPERTY

WHAT_MAX

public static final int WHAT_MAX

MESSAGE_TYPE_STRINGS

public static final java.lang.String[] MESSAGE_TYPE_STRINGS
An array of strings that correspond to the above message type enumeration.

SET_DATA

public static final java.lang.String SET_DATA
The name of the attribute that contains the data to be used in a set.

SIZEOF_INT

static final int SIZEOF_INT
The size of an integer on the wire.

buffer

private byte[] buffer
The buffer used when marshalling/unmarshalling a flattened message.

cursor

private int cursor
The current position in the buffer.

messageSize

private int messageSize
The size of the flattened message.

what

private int what
The type of message.

specifiers

private final java.util.Vector specifiers
The specifier stack.

specifierIndex

private int specifierIndex
The current position in the specifier stack.

identifiers

private final java.util.Vector identifiers
The set of identifier/value pairs in the message.
Constructor Detail

JSIMessage

public JSIMessage()
Construct an empty message.
Method Detail

alignedSize

static int alignedSize(int size)
Parameters:
size - The size to align.
Returns:
The wire aligned size.

setWhat

public void setWhat(int what)
Parameters:
what - The message type.

getWhat

public int getWhat()
Returns:
The message type.

pushSpecifier

public void pushSpecifier(JSIPair jp)
Push a specifier onto the stack.
Parameters:
jp - The specifier to add.

pushSpecifier

public void pushSpecifier(java.lang.String tag,
                          java.lang.String value)
Push a specifier onto the stack.
Parameters:
tag - The specifier name.
value - The specifier value.

pushSpecifier

public void pushSpecifier(java.lang.String tag)
Push a specifier onto the stack.
Parameters:
tag - The specifier name.

popSpecifier

public JSIPair popSpecifier()
Pop a specifier off the stack.
Returns:
The specifier at the top of the stack.

restoreSpecifier

public void restoreSpecifier()
Restore the last specifier popped off the stack.

getSpecifierCount

public int getSpecifierCount()
Returns:
The number of specifiers on the stack.

getRemainingSpecifierCount

public int getRemainingSpecifierCount()
Returns:
The number of specifiers left on the stack.

getIdentifiers

public java.util.Vector getIdentifiers()
Returns:
An enumeration containing the identifier/value pairs.

add

public JSIMessage add(JSIPair jp)
Add an identifier/value pair to the message.
Parameters:
jp - The pair to add.
Returns:
this

add

public JSIMessage add(java.lang.String tag,
                      java.lang.String value)
Add an identifier/value pair to the message.
Parameters:
tag - The identifier
value - The value
Returns:
this

add

public JSIMessage add(java.lang.String tag,
                      JSIPropertyInfo value)
Add an identifier/value pair to the message.
Parameters:
tag - The identifier
value - The value
Returns:
this

add

public JSIMessage add(java.lang.String tag,
                      JSIPropertyInfo[] value)
Add an identifier/value pair to the message.
Parameters:
tag - The identifier
value - An array of JSIPropertyInfo's to add to the message.
Returns:
this

findIdentifier

private int findIdentifier(java.lang.String tag,
                           int instance)
Find an identifier instance in the message.
Parameters:
tag - The identifier to find.
instance - The instance of the identifier to find.
Returns:
The index of the identifier in the Vector or -1 if it couldn't

remove

public void remove(java.lang.String tag,
                   int instance)
Remove an identifier value pair from the message.
Parameters:
tag - The identifier to remove.
instance - The instance of the identifier to remove.

count

public int count(java.lang.String tag)
Count the number of identifier/value pairs in the message.
Parameters:
tag - The identifier to count.
Returns:
The number of occurrences of the given identifier in the message

get

public java.lang.String get(java.lang.String tag,
                            int instance,
                            java.lang.String defaultValue)
Get an identifier/value pair from the message.
Parameters:
tag - The identifier to get.
instance - The instance of the identifier to get.
defaultValue - The value to return if the identifier isn't found.
Returns:
The string value of the identifier or the defaultValue if it

get

public java.lang.String get(java.lang.String tag)
Get an identifier/value pair from the message.
Parameters:
tag - The identifier to get.
Returns:
The string value of the identifier or null if it wasn't found.

get

public java.lang.String get(java.lang.String tag,
                            java.lang.String defaultValue)
Get an identifier/value pair from the message.
Parameters:
tag - The identifier to get.
defaultValue - The value to return if the identifier isn't found.
Returns:
The string value of the identifier or the defaultValue if it

getPair

public JSIPair getPair(java.lang.String tag,
                       int instance)
Get an identifier/value pair from the message.
Parameters:
tag - The identifier to get.
instance - The instance of the identifier to get.
Returns:
The pair associated with the given identifier or null if it

getPair

public JSIPair getPair(java.lang.String tag)
Get an identifier/value pair from the message.
Parameters:
tag - The identifier to get.
Returns:
The pair associated with the given identifier or null if it

expect

public java.lang.String expect(java.lang.String tag)
                        throws MissingPairException
Expect an identifier/value pair in the message.
Parameters:
tag - The identifier to get.
Returns:
The string value of the pair.
Throws:
Throws - a MissingPairException if the tag couldn't be found.

expectPair

public JSIPair expectPair(java.lang.String tag)
                   throws MissingPairException
Expect an identifier/value pair in the message.
Parameters:
tag - The identifier to get.
Returns:
The pair associated with the given identifier.
Throws:
Throws - a MissingPairException if the tag couldn't be found.

clear

public void clear()
Clear the contents of a message so it can be reused.

reply

public void reply(java.lang.String result)
Clear the message and set it to be a valid reply with the given data.
Parameters:
result - The string value to send back as the reply.

reply

public void reply(JSIPropertyInfo[] result)
Clear the message and set it to be a valid reply with the given data.
Parameters:
result - The property info array to send back as the reply.

reply

public void reply(long result)
Clear the message and set it to be a valid reply with the given data.
Parameters:
result - The integer value to send back as the reply.

error

public void error(java.lang.String why)
Clear the message and set it to be error reply with the given data.
Parameters:
why - A brief explanation of the error.

flatten

public byte[] flatten()
Returns:
A flattened version of this message.

unflatten

public void unflatten(byte[] buf)
               throws JSIEncodingException
Unmarshal the message in this.buffer.
Returns:
True if the process worked.

writeInt

void writeInt(int i)
Parameters:
i - The integer to write to the internal buffer.

writeBytes

void writeBytes(byte[] b)
Parameters:
b - The byte array to write to the internal buffer.

readInt

int readInt()
Returns:
An integer decoded from the internal buffer.

readBytes

byte[] readBytes(int length)
Parameters:
length - The length of the byte array to unmarshal from the
length - internal buffer.
Returns:
The unmarshalled byte array from the internal buffer.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

instantiate

public static final JSIMessage instantiate(byte[] msg)
                                    throws JSIEncodingException
Instantiate a flattened message.
Parameters:
msg - The byte array containing the flattened message.
Returns:
The unflattened JSIMessage or null if the process failed.

JanosVM v1.0 API

This documentation is Copyright (C) 2000-2003 The University of Utah. All Rights Reserved. See the documentation license for distribution terms and restrictions.
Documentation, software, and mailing lists for the JanosVM can be found at the Janos Project web page: http://www.cs.utah.edu/flux/janos/
Generated on Feb 13, 2003