Watcher.v2_1
Class Watcher

java.lang.Object
  |
  +--PaP.Actor
        |
        +--PaP.ApplicationActor
              |
              +--Watcher.v2_1.Watcher
All Implemented Interfaces:
ActorInterface, ControlInterface, java.rmi.Remote, java.io.Serializable

public class Watcher
extends ApplicationActor

Watcher is the Plug-and-Play (PaP) specific class of the Watcher application. It extends ApplicationActor and therefore has access to functionality provided by the PaP system. Watcher has an internal state model with three states. The method stateTransition() defines the class' behavior in the different states when it receives a request through the method applicationActorEntry().

Watcher subscribes for reports on the events generated in the PaP system. Each time such an event occurs, the Director calls subscribeReport() with information regarding the event.

Version:
December 2001
Author:
Lars Erik Liljebäck
See Also:
Serialized Form

Field Summary
private  RoleSession initialRoleSession
          The initial RoleSession created when this Actor is created.
private  boolean initiated
          Indicates wether initial ActorPlugIn has been performed or not
private  int state
          Indicates which state the application is in
private  int STATE_INITIAL
           
private  int STATE_SERVER_ACTIVE
          State where it subscribes and shows the received reports
private  int STATE_SERVER_PASSIVE
          State where subscriptions are canceled and the Window are disposed
private  java.lang.String subscribeId
          The unique subscription id returned when SubscribeRequest is done
private  WatcherWindow window
          A reference to an instance of WatcherWindow
 
Fields inherited from class PaP.Actor
bf, context, fh
 
Constructor Summary
Watcher()
          Creates a new instance of Watcher and sets the initial state to STATE_INITIAL.
 
Method Summary
 RequestResult applicationActorEntry(RequestPars rpars)
          This method is the common entry point for all external requests to this actor.
 void changeSubscription(int interval)
          Switches between the defined subscription types; Immediate, 15 seconds intervals and 30 seconds intervals.
 void closeApplication()
          This method is used by WatcherWindow to tell Watcher that the user wants to close the application.
private  void dbg(java.lang.String dbg)
          Sends debug information to this actor's BaseFrame window, which is an interactive debug client window for several entities.
 java.lang.String getWatcherGAI()
          Returns the GAI of this ApplicationActor.
private  RequestResult stateTransition(GAI sender, GAI receiver, ApplicationMessage message)
          This method defines the main behaviour of this actor.
 RequestResult subscribeReport(java.lang.String[] report)
          This method is an overloading of the corresponding method in the super class ApplicationActor.
 
Methods inherited from class PaP.ApplicationActor
actorBehaviourPlugIn, actorBehaviourPlugOut, actorCapabilities, actorChangeBehaviour, actorEntry, actorPlay, actorPlugIn, actorPlugOut, anyOtherRequestType, callActorChangeBehaviour, control, init, loginUser, logoutUser, playChangesPlugIn, playPlugIn, playPlugOut, requestToActor, roleFigurePlugIn, roleFigurePlugOut, roleSessionAction, sessionResume, sessionSuspend, sessionUpdate, subscribeCancel, subscribeRequest
 
Methods inherited from class PaP.Actor
findRoleSession, getGAI, start, status, term
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

STATE_INITIAL

private final int STATE_INITIAL

STATE_SERVER_ACTIVE

private final int STATE_SERVER_ACTIVE
State where it subscribes and shows the received reports

STATE_SERVER_PASSIVE

private final int STATE_SERVER_PASSIVE
State where subscriptions are canceled and the Window are disposed

state

private int state
Indicates which state the application is in

initiated

private boolean initiated
Indicates wether initial ActorPlugIn has been performed or not

initialRoleSession

private RoleSession initialRoleSession
The initial RoleSession created when this Actor is created. Used when the Actor is terminated.

subscribeId

private java.lang.String subscribeId
The unique subscription id returned when SubscribeRequest is done

window

private WatcherWindow window
A reference to an instance of WatcherWindow
Constructor Detail

Watcher

public Watcher()
Creates a new instance of Watcher and sets the initial state to STATE_INITIAL.
Method Detail

applicationActorEntry

public RequestResult applicationActorEntry(RequestPars rpars)
                                    throws java.lang.Exception
This method is the common entry point for all external requests to this actor.
Overrides:
applicationActorEntry in class ApplicationActor
Parameters:
rpars - Instance of RequestPars which specifies type of request and additional parametres.
Returns:
An instance of RequestResult which indicates success or failure in treatment of the request.
Throws:
java.lang.Exception -  

changeSubscription

public void changeSubscription(int interval)
                        throws java.lang.Exception
Switches between the defined subscription types; Immediate, 15 seconds intervals and 30 seconds intervals. It first tries to cancel the current subscription before it sends a new Subscription request of the correct type. If something goes wrong it throws an Exception to notify WatcherWindow.
Parameters:
interval - Indicates the subscription type. If interval = 0 it means immediate subscription.
Throws:
java.lang.Exception -  

closeApplication

public void closeApplication()
This method is used by WatcherWindow to tell Watcher that the user wants to close the application. It tries to cancel its subscriptions and to plug out the actor before it returns.

getWatcherGAI

public java.lang.String getWatcherGAI()
Returns the GAI of this ApplicationActor.
Returns:
The GAI represented as a string.

stateTransition

private RequestResult stateTransition(GAI sender,
                                      GAI receiver,
                                      ApplicationMessage message)
                               throws java.lang.Exception
This method defines the main behaviour of this actor. It defines the way it responds to different messages sent from the actor's Director depending on which state the actor is in. The methods subscribeReport() and closeWatcherWindow() is also part of the actor's behaviour but they are executed asynchronous to the main behaviour defined in this method.
Parameters:
sender - The GAI to the source of the received request.
receiver - This actor's GAI.
message - The specification of the request.
Returns:
An instance of RequestResult which indicates success or failure in treatment of the ApplicationMessage.
Throws:
java.lang.Exception -  

subscribeReport

public RequestResult subscribeReport(java.lang.String[] report)
                              throws java.lang.Exception
This method is an overloading of the corresponding method in the super class ApplicationActor. It is called every time a new report is received from the DirectorActor for an event that Watcher is subscribing for. The subscriber receives a list of reported events where each event consist of four parametres:
a)  Event type - as defined in the class SubscribeRequest.
b)  Textual representation of the GAI address for the actor the report event concerns.
c)  Event type dependent information
d)  The point of time (in milliseconds since 1 Jan. 1970) where the event was reported to the DirectorActor.
Overrides:
subscribeReport in class ApplicationActor
Parameters:
report - A list of newly reported events.
Returns:
An instance of RequestResult which indicates success or failure in treatment of the results.
Throws:
java.lang.Exception -  

dbg

private void dbg(java.lang.String dbg)
Sends debug information to this actor's BaseFrame window, which is an interactive debug client window for several entities.
Overrides:
dbg in class ApplicationActor
Parameters:
dbg - The debug information to be sent.