/************************************************* * * = PACKAGE * JACE.ASX * * = FILENAME * MessageBlock.java * *@author Prashant Jain * *************************************************/ package JACE.ASX; import JACE.OS.*; /** *
* Object used to store messages in the ASX framework. ** *
* MessageBlock is modeled after the message data structures * used in System V STREAMS. A MessageBlock is composed of * one or more MessageBlocks that are linked together by PREV * and NEXT pointers. In addition, a MessageBlock may also be * linked to a chain of other MessageBlocks. This structure * enables efficient manipulation of arbitrarily-large messages * without incurring memory copying overhead. ** *@see MessageQueue */ public class MessageBlock { /** * Create an empty Message Block */ public MessageBlock () { this (0); } /** * Create an empty Message Block. * Note that this assumes that type of MessageBlock is MB_DATA. *@param size size of the Message Block to create. */ public MessageBlock (int size) { // Note the explicit cast toString() is needed. For some strange // reason, it fails otherwise if size == 0. this ((new StringBuffer (size)).toString ()); } /** * Create a Message Block. Note that this assumes that type of * MessageBlock is MB_DATA. *@param data initial data to create a Message Block with. */ public MessageBlock (String data) { this (MessageType.MB_DATA, null, data); } /** * Create a Message Block. *@param type type of the Message Block (must be one of those * specified in class Message Type) *@param cont next block of data *@param data initial data to create Message Block with */ public MessageBlock (int type, MessageBlock cont, String data) { this.flags_ = 0; this.priority_ = 0; this.next_ = null; this.prev_ = null; this.init (type, cont, data); } /** * Create a Message Block. Note that this assumes that type of * MessageBlock is MB_OBJECT. *@param obj initial object to create a Message Block with. */ public MessageBlock (Object obj) { this (MessageType.MB_OBJECT, null, obj); } /** * Create a Message Block. *@param type type of the Message Block (must be one of those * specified in class Message Type) *@param cont next block of data *@param obj initial object to create Message Block with */ public MessageBlock (int type, MessageBlock cont, Object obj) { this.init (type, cont, obj); } /* Initialize the Message Block *@param data data to initialize Message Block with */ public void init (String data) { this.base_ = new StringBuffer (data); } /** * Initialize a Message Block. *@param type type of the Message Block (must be one of those * specified in class Message Type) *@param cont next block of data *@param data data to initialize Message Block with */ public void init (int msgType, MessageBlock msgCont, String data) { if (data.length () == 0) this.base_ = new StringBuffer (0); else this.base_ = new StringBuffer (data); this.type_ = msgType; this.cont_ = msgCont; } /** * Initialize a Message Block. Note that this assumes that type of * MessageBlock is MB_OBJECT. *@param obj initial object to initialize a Message Block with. */ public void init (Object obj) { this.init (MessageType.MB_OBJECT, null, obj); } /** * Initialize a Message Block. *@param type type of the Message Block (must be one of those * specified in class Message Type) *@param cont next block of data *@param obj object to initialize Message Block with */ public void init (int msgType, MessageBlock msgCont, Object obj) { this.obj_ = obj; this.type_ = msgType; this.cont_ = msgCont; this.flags_ = 0; this.priority_ = 0; this.next_ = null; this.prev_ = null; } /** * Set message flags. Note that the flags will be set on top of * already set flags. *@param moreFlags flags to set for the Message Block. */ public long setFlags (long moreFlags) { // Later we might mask more_flags so that user can't change // internal ones: more_flags &= ~(USER_FLAGS -1). this.flags_ = ACE.SET_BITS (this.flags_, moreFlags); return this.flags_; } /** * Unset message flags. *@param lessFlags flags to unset for the Message Block. */ public long clrFlags (long lessFlags) { // Later we might mask more_flags so that user can't change // internal ones: less_flags &= ~(USER_FLAGS -1). this.flags_ = ACE.CLR_BITS (this.flags_, lessFlags); return this.flags_; } /** * Get the message flags. *@return Message flags */ public long flags () { return this.flags_; } /** * Get the type of the message. *@return message type */ public int msgType () { return this.type_; } /** * Set the type of the message. *@param t type of the message */ public void msgType (int t) { this.type_ = t; } /** * Get the class of the message. Note there are two classes, *