osl.manager.basic
Class StreamOutputActorImpl

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--osl.manager.ActorImpl
              |
              +--osl.manager.basic.StreamOutputActorImpl

public class StreamOutputActorImpl
extends ActorImpl
implements StreamOutputActor

This class defines the implementation of an actor used to control an output stream on behalf of external actors. We require an implementation (rather than an Actor) because if a security manager is running (i.e. startfoundry was specified with the -secure option), then user-written actors will not have direct access to several standard streams (e.g. System.out). Since instances of ActorImpl are privileged they may control such streams and provide their services to specific actors. The methods exported to external actors is defined by the StreamOutputActor interface. In the current implementation, the first argument passed in the creation request for this actor is used to determine which output stream to manage. If the argument is "out", then System.out is managed. If the argument is "err", then System.err is managed. Otherwise, an error is returned by actorInitialize.

Version:
$Revision: 1.3 $ ($Date: 1999/01/19 18:43:34 $)
See Also:
osl.manager.basic.StreamOutputActor, Serialized Form

Field Summary
protected  WaitQueue mailQueue
          The queue which holds incoming requests.
protected  ActorManager ourManager
          The manager which manages this implementation.
 
Fields inherited from class osl.manager.ActorImpl
actorClass, classRef, context, extensionMethods, nextID, self
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
StreamOutputActorImpl()
           
 
Method Summary
protected  void actorDeliver(ActorMsgRequest msg)
          This method is called by a manager to deliver a new message to the local actor.
protected  void actorInitialize(ActorManager ourMgr, ActorName you, ActorCreateRequest req)
          This method is called by a manager to initialize an actor implementation after it is instantiated.
protected  void actorPostMigrateRebuild(ActorManager ourMgr)
          This method is called by the new manager of an actor implementation just after migration has occurred.
 void close()
          Close the internal output stream.
 void flush()
          Flush the internal output stream.
protected  ActorName implCreate(ActorCreateRequest req)
          Request a new actor to be created.
protected  void implDestroy(java.lang.String reason)
          Request to remove this actor from the system.
protected  java.lang.Object implInvokeService(ServiceName name, java.lang.String meth, java.lang.Object[] args)
          Request a service invocation on the named node service.
protected  void implMigrate(ActorManagerName loc)
          Request that this actor wishes to be migrated to a new location.
protected  java.lang.Object implSend(ActorMsgRequest msg)
          Request a message to be sent.
 void print(java.lang.Object s)
          Print an object representation to the output stream.
 void print(java.lang.String s)
          Print a string to the output stream.
 void println(java.lang.Object s)
          Print an object representation followed by a newline character.
 void println(java.lang.String s)
          Print a string followed by a newline character.
 void run()
          The main run loop for this implementation.
 void write(java.lang.Byte[] b)
          Write the contents of a byte array to the internal output stream.
 void write(java.lang.Byte[] b, java.lang.Integer off, java.lang.Integer len)
          Write a subsequence of a byte array to the output stream.
 void write(java.lang.Integer b)
          Writes a byte to the internal output stream.
 
Methods inherited from class osl.manager.ActorImpl
buildAsynchException, finalize, formatAsynchException, implExtension, mgrActorCreate, mgrActorFatalError, mgrActorInvokeService, mgrActorMigrate, mgrActorSend, registerExtension, removeExtension, setCreatingThread, stampRequest
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ourManager

protected ActorManager ourManager
The manager which manages this implementation.

mailQueue

protected WaitQueue mailQueue
The queue which holds incoming requests.
Constructor Detail

StreamOutputActorImpl

public StreamOutputActorImpl()
Method Detail

actorInitialize

protected void actorInitialize(ActorManager ourMgr,
                               ActorName you,
                               ActorCreateRequest req)
This method is called by a manager to initialize an actor implementation after it is instantiated. The manager provides a reference to itself, a reference giving the name of the new actor, and a create request describing the new Actor that should be created and managed. After calling this method, a manager will call the run method in this class to start the actor executing. Note that the protection of this method prevents it from being called external to osl.manager. This was done to prevent arbitrary classes from initializing new actors. However, managers in different packages may invoke this method using implInitialize.

For this implementation, the manager reference and actor name are saved. The first constructor argument in the creation request is expected to be either the strint "out" or "err", indicating which System stream should be managed. An error is returned if no string is present.

Parameters:
ourMgr - The ActorManager which should be used by this actor implementation to invoke actor services.
you - The ActorName that should be used as the name of the new actor.
rtClass - The run-time Class of the user-written actor that should be instantiated by this implementation. This class will always be an extension of the Actor class.
initArgs - The array of arguments to pass to the constructor of the user-defined actor when it is instantiated.
Throws:
java.lang.RuntimeException - Thrown if no stream was specified in the first constructor argument.
Overrides:
actorInitialize in class ActorImpl
See Also:
ActorManager.implInitialize(osl.manager.ActorImpl, osl.manager.ActorName, osl.manager.ActorCreateRequest)

actorDeliver

protected void actorDeliver(ActorMsgRequest msg)
This method is called by a manager to deliver a new message to the local actor. This method is protected so that it has package level protection and therefore may not be invoked directly by user-written actor code.

For this implementation, we deposit the new message in our mail queue so that it can be processed in the main run loop.

Parameters:
msg - The ActorMsgRequest structure to be delivered. This structure must be maintained by the actor as it is required if an exception is returned to the manager.
Overrides:
actorDeliver in class ActorImpl

actorPostMigrateRebuild

protected void actorPostMigrateRebuild(ActorManager ourMgr)
This method is called by the new manager of an actor implementation just after migration has occurred. The implementation is expected to perform any re-initialization necessary after a migration (e.g. rebuilding transient fields). This method will be called before the implementations thread is restarted.

This method should never be called for this implementation as StreamOutputActorImpls will never migrate. If this method IS called for some reason then a runtime exception is thrown.

Parameters:
ourMgr - A reference to the new manager of the implementation after migration has occurred.
Throws:
java.lang.RuntimeException - Thrown if this method is ever called.
Overrides:
actorPostMigrateRebuild in class ActorImpl

implSend

protected java.lang.Object implSend(ActorMsgRequest msg)
                             throws RemoteCodeException
Request a message to be sent. The message argument is forwarded to the manager. If the RPC field of the message is set to true then the caller is blocked while the RPC takes place. This method is protected so that it has package level protection and therefore may not be invoked directly by user-written actor code.

This method should never be called in this implementation since no internal actor is ever created.

Parameters:
msg - The ActorMsgRequest describing the message to send.
Returns:
If this is an RPC request, then the return value from the message call is returned. Otherwise, null is returned.
Throws:
RemoteCodeException - Thrown only if this is an RPC exception which throws an exception during invocation. An exception thrown in any other case is an error.
java.lang.RuntimeException - Thrown if this method is ever called.
Overrides:
implSend in class ActorImpl
See Also:
Actor.send(ActorName, String), Actor.call(ActorName, String)

implCreate

protected ActorName implCreate(ActorCreateRequest req)
                        throws java.lang.SecurityException,
                               RemoteCodeException
Request a new actor to be created. The request argument is forwarded to the manager and the returned name is passed on to the Actor caller. This method is protected so that it has package level protection and therefore may not be invoked directly by user-written actor code.

This method should never be called in this implementation since no internal actor is ever created.

Parameters:
req - The ActorCreateRequest describing the new actor to create.
Returns:
The ActorName of the new actor.
Throws:
java.lang.SecurityException - Thrown if the behavior of the new actor is not a subclass of Actor.
RemoteCodeException - Thrown as a wrapper for any other error that is encountered while attempting the create. Note that such errors may also be thrown asynchronously.
java.lang.RuntimeException - Thrown if this method is ever called.
Overrides:
implCreate in class ActorImpl
See Also:
Actor.create(String), Actor.create(Class), Actor.create(ActorManagerName, String), Actor.create(ActorManagerName, Class)

implMigrate

protected void implMigrate(ActorManagerName loc)
Request that this actor wishes to be migrated to a new location. By convention, this call is meant to indicate a request rather than serving as a notice to immediately migrate the actor. Normally, the implementation will record the request but wait to migrate the actor until the current message being processed has completed. Once this occurs the actor is migrated and restarted at its new node. This method is protected so that it has package level protection and therefore may not be invoked directly by user-written actor code.

This method should never be called in this implementation since no internal actor is ever created.

Parameters:
loc - The ActorManagerName of the node to migrate to.
Throws:
java.lang.RuntimeException - Thrown if this method is ever called.
Overrides:
implMigrate in class ActorImpl
See Also:
Actor.migrate(osl.manager.ActorManagerName), Actor.cancelMigrate()

implInvokeService

protected java.lang.Object implInvokeService(ServiceName name,
                                             java.lang.String meth,
                                             java.lang.Object[] args)
                                      throws ServiceNotFoundException,
                                             ServiceException
Request a service invocation on the named node service. This request is forwarded to the actor manager and the appropriate return value is provided. This method is protected so that it has package level protection and therefore may not be invoked directly by user-written actor code.

This method should never be called in this implementation since no internal actor is ever created.

Parameters:
name - The ServiceName describing the service to invoke.
args - The Object argument to pass to the service invocation function.
Returns:
The Object returned as a result of the service invocation.
Throws:
ServiceNotFoundException - Thrown if no instance of the named service can be found on this node.
ServiceException - Thrown if the service throws an exception while processing the request.
java.lang.RuntimeException - Thrown if this method is ever called.
Overrides:
implInvokeService in class ActorImpl
See Also:
Actor.invokeService(osl.service.ServiceName, java.lang.String)

implDestroy

protected void implDestroy(java.lang.String reason)
Request to remove this actor from the system. Normally, this method will not return as the actor is immediately removed from the system. Note that any actor garbage collection process is ignored in this call so that this actor may be removed even though it is accessible by other actors.

This method should never be called in this implementation since no internal actor is ever created.

Parameters:
reason - A String giving a "reason" for the removal. This string should normally be appended to the log for the actor before removing it from the system.
Throws:
java.lang.RuntimeException - Thrown if this method is ever called.
Overrides:
implDestroy in class ActorImpl
See Also:
Actor.destroy(java.lang.String)

write

public void write(java.lang.Integer b)
           throws java.io.IOException
Writes a byte to the internal output stream.
Specified by:
write in interface StreamOutputActor
Parameters:
b - An Integer giving the byte to write.
Throws:
java.io.IOException - Thrown if an I/O error occurs while writing the byte.

write

public void write(java.lang.Byte[] b)
           throws java.io.IOException
Write the contents of a byte array to the internal output stream.
Specified by:
write in interface StreamOutputActor
Parameters:
b - A Byte array of data to write to the output stream.
Throws:
java.io.IOException - Thrown if an I/O error occurs while writing the byte array.

write

public void write(java.lang.Byte[] b,
                  java.lang.Integer off,
                  java.lang.Integer len)
           throws java.io.IOException
Write a subsequence of a byte array to the output stream.
Specified by:
write in interface StreamOutputActor
Parameters:
b - A Byte array of data from which a subsequence will be written to the output stream.
off - An Integer giving the index in the data to start the write from.
len - An Integer giving the total number of bytes to write.
Throws:
java.io.IOException - Thrown if an I/O error occurs while writing the subsequence of the byte array.

print

public void print(java.lang.String s)
           throws java.io.IOException
Print a string to the output stream.
Specified by:
print in interface StreamOutputActor
Parameters:
s - The String to display.
Throws:
java.io.IOException - Thrown if an I/O error occurs while displaying the string.

println

public void println(java.lang.String s)
             throws java.io.IOException
Print a string followed by a newline character.
Specified by:
println in interface StreamOutputActor
Parameters:
s - The String to display.
Throws:
java.io.IOException - Thrown if an I/O error occurs while displaying the string.

print

public void print(java.lang.Object s)
           throws java.io.IOException
Print an object representation to the output stream.
Parameters:
s - The String to display.
Throws:
java.io.IOException - Thrown if an I/O error occurs while displaying the string.

println

public void println(java.lang.Object s)
             throws java.io.IOException
Print an object representation followed by a newline character.
Parameters:
s - The String to display.
Throws:
java.io.IOException - Thrown if an I/O error occurs while displaying the string.

flush

public void flush()
           throws java.io.IOException
Flush the internal output stream.
Specified by:
flush in interface StreamOutputActor
Throws:
java.io.IOException - Thrown if an I/O error occurs while flushing the input stream.

close

public void close()
           throws java.io.IOException
Close the internal output stream.
Specified by:
close in interface StreamOutputActor
Throws:
java.io.IOException - Thrown if an I/O error occurs while attempting to close the stream.

run

public void run()
The main run loop for this implementation. All messages are processed within this loop and replies are generated and sent as necessary.
Overrides:
run in class java.lang.Thread