os
Class OSProcess

java.lang.Object
  |
  +--os.OSProcess
Direct Known Subclasses:
ClearChatterVector, Describe, Echo, Emote, Go, GoHome, initialize, Listen, LoadCommands, LoadConnection, LoadMudMap, LoadPlayerMap, LoadPlayerParser, LoadResponders, LoadRoomDescriptionParser, LoadWhereisParser, LoginToMud, LogPlayers, MapMud, Mutter, Page, Pose, Respond, Say, sbsl, Set, Whisper, Yell

public abstract class OSProcess
extends java.lang.Object

OSProcess is a abstract base class used to write processes that run under the Bot Operating System. The process contains information about the id of the process, the parent id of the process, whether or not the process is waiting for another process to complete, whether it is initialized and what its arguments list is. In addition it has access to the shared interprocess communication space so that it can communicate with other processes that are running.

Version:
1.1
Author:
Thaddeus O. Cooper (cooper@tweenproject.org)

Constructor Summary
OSProcess()
          Create a process that can run in the Bot Operating System.
 
Method Summary
 void done()
          This is called by the operating system during the clean up phase of the process.
 java.lang.String[] getArgs()
          Gets the arguments that were passed to this process.
 int getExitStatus()
          Gets the exit status for this process.
 int getId()
          Gets the id of this process.
 java.lang.Object getObject()
          Gets an object for use by this process.
 int getParentId()
          Gets the parentId of this process.
 Shared getShared()
          Gets the shared interprocess communication area for this process.
 int getWaitingFor()
          Gets the process id of the process this process is waiting for.
 void initialize()
          This is called by the operating system during the initialization phase of the process.
 boolean isInitialized()
          Determines if the process has been initialized.
 boolean isWaitingFor()
          Determines if this process is waiting for another process to complete.
 void registerObject(java.lang.String name, java.lang.Object o)
          Register an object in the shared interprocess communication space.
 java.lang.Object requestObject(java.lang.String name)
          Request an object from the shared interprocess communication space.
abstract  void run()
          The method that is called to do the real work of the process.
 void setArgs(java.lang.String args)
          Sets the arguments from the string that is specified.
 void setArgs(java.lang.String[] args)
          Sets the arguments array to the specified String array.
 void setExitStatus(int exitStatus)
          Sets the exit status for this process.
 void setId(int id)
          Sets the id of this process.
 void setInitialized(boolean initialized)
          Sets the processes initialized flag.
 void setObject(java.lang.Object o)
          Sets an object for use by this process.
 void setParentId(int parentId)
          Sets the parent id of this process.
 void setShared(Shared shared)
          Sets the shared interprocess communication area for this process.
 void setWaitingFor(int waitingFor)
          Sets the process id of the process this process is waiting for.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OSProcess

public OSProcess()
Create a process that can run in the Bot Operating System.
Method Detail

setId

public void setId(int id)
Sets the id of this process.
Parameters:
id - the id to set this process to.

getId

public int getId()
Gets the id of this process.
Returns:
the id that this process is set to.

setParentId

public void setParentId(int parentId)
Sets the parent id of this process.
Parameters:
parentId - the parentId to set this process to.

getParentId

public int getParentId()
Gets the parentId of this process.
Returns:
the parentId of this process.

setWaitingFor

public void setWaitingFor(int waitingFor)
Sets the process id of the process this process is waiting for.
Parameters:
waitingFor - the id of the process that this process is waiting to complete.

getWaitingFor

public int getWaitingFor()
Gets the process id of the process this process is waiting for.
Returns:
the id of the process that this process is waiting to complete.

isWaitingFor

public boolean isWaitingFor()
Determines if this process is waiting for another process to complete.
Returns:
true if this process is waiting for another process to complete, otherwise false.

setExitStatus

public void setExitStatus(int exitStatus)
Sets the exit status for this process.
Parameters:
exitStatus - the exit status of this process.

getExitStatus

public int getExitStatus()
Gets the exit status for this process.
Returns:
the exit status of this process.

initialize

public void initialize()
This is called by the operating system during the initialization phase of the process. By default this method sets the process to the initialized state and returns. More sophisticated processes should override this method and place their initialization code here. When initialization is complete, a call to setInitialized with a value of true will set the process to its initialized state.

setShared

public void setShared(Shared shared)
Sets the shared interprocess communication area for this process.
Parameters:
shared - the shared interprocess communication area.

getShared

public Shared getShared()
Gets the shared interprocess communication area for this process.
Returns:
the shared interprocess communication area.

registerObject

public void registerObject(java.lang.String name,
                           java.lang.Object o)
Register an object in the shared interprocess communication space.
Parameters:
name - the name of the object for reference in the shared interprocess communication space.
o - the object to add to the shared interprocess communication space.

requestObject

public java.lang.Object requestObject(java.lang.String name)
Request an object from the shared interprocess communication space.
Parameters:
name - the name that the object was registered with.
Returns:
the object from the shared interprocess communication space. It is the responsibility of the calling method to know in advance the type of the object and cast it appropriately.

run

public abstract void run()
                  throws OSProcessRelinquishControl,
                         OSProcessDone,
                         OSProcessLoadProcess,
                         OSProcessExecProcess,
                         OSProcessWaitForProcess
The method that is called to do the real work of the process. The process should not hold the CPU forever, or no other processes will be able to run.
Throws:
OSProcessRelinquishControl - thrown when the process wants to temporarily relinquish control and let another process run.
OSProcessDone - thrown when the process is finished.
OSProcessLoadProcess - thrown when the process is requesting that the operating system load a process for it.
OSProcessExecProcess - thrown when the process is requesting that the operating system load a process and replace it with the new process. This process exits by default.
OSProcessWaitForProcess - thrown when the process wants to wait for another process to complete before continuing to run.

done

public void done()
This is called by the operating system during the clean up phase of the process. By default it does nothing. Processes that allocate resources should dispose of them here.

isInitialized

public boolean isInitialized()
Determines if the process has been initialized. Usually called by the operating system to determine if it should call the initialize method, or the run method.
Returns:
true if the process is initialized, false otherwise.

setInitialized

public void setInitialized(boolean initialized)
Sets the processes initialized flag.
Parameters:
initialized - the flag that specifies whether the process has been initialized.

setObject

public void setObject(java.lang.Object o)
Sets an object for use by this process.
Parameters:
o - the object to be set.

getObject

public java.lang.Object getObject()
Gets an object for use by this process.
Returns:
the object.

setArgs

public void setArgs(java.lang.String[] args)
Sets the arguments array to the specified String array.
Parameters:
args - the arguments to the program.

setArgs

public void setArgs(java.lang.String args)
Sets the arguments from the string that is specified. Quoted arguments are kept together as a single argument otherwise arguments are parsed on space boundaries.
Parameters:
args - the args to parse.

getArgs

public java.lang.String[] getArgs()
Gets the arguments that were passed to this process.
Returns:
a String array of arguments that were passed to this process.

toString

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