User.v1_1
Class UserAgent

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

public class UserAgent
extends ApplicationActor

A UserAgent is the actor working on behalf of a user that has logged into a PaP domain. The UserAgent receives a Session object from the Director that contains stored information from the user's last saved session. If the user has specified that he wants to resume a stored session, the UserAgent will attemt to plugin all the actors that were plugged in when the user suspended his session, set the actors' state to the saved state and plugin all the RoleFigures that were plugged in.

Every UserAgent has an reference to a UserWindow which is the Graphical User Interface (GUI) of the UserAgent. The UserWindow contains to tables; the plugin table and the plugout table. The UserAgent reads the file RoleList_User.xml for a list of plays and roles that the user can select to plugin and this list is shown in the plugin table. Everytime a user plugs in an actor to play the specified role, the GAI of the actor is added to the plugout table. This table contains a list of actors that the user can select to plugout.

Version:
1.0
Author:
Lars Erik Liljebäck
See Also:
Session, UserWindow, Serialized Form

Inner Class Summary
 class UserAgent.CloseWindowThread
          This thread is started when an ActorPlugOut request is received.
 class UserAgent.ResumeSessionThread
          This thread is started when a SessionResume request is received.
 
Field Summary
private  java.lang.String codebase
          URL used as codebase when actors are plugged in.
private  boolean initiated
          Indicates wether initial ActorPlugIn has been performed or not
private  java.util.Hashtable pluggedInActors
          Hashtable containing plugged in actors
private  Session session
          The session object of the user of this UserAgent
private  int unique
          Increasing number used for naming of actors
private  UserWindow window
          The reference to the UserWindow, the GUI of the UserAgent.
private  XMLFileUtil xfu
          Reference to the XMLFileUtil used for reading the file ActorList_User.xml.
 
Fields inherited from class PaP.Actor
bf, context, fh
 
Constructor Summary
UserAgent()
          Creates a new UserAgent.
 
Method Summary
 RequestResult applicationActorEntry(RequestPars rpars)
          This method is the common entry point for all external requests to this actor.
 void closeApplication()
          This method is used by the GUI to notify 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 getCodebase()
          Returns the current URL used as codebase.
 java.lang.String[] getPluggedInActors()
          Returns a string array with the GAI of all the actors that have been plugged in by this UserAgent.
private  int getUnique()
          Returns a unigue number that is used to name the actors being plugged in by the UserAgent.
static void main(java.lang.String[] args)
          Used for debugging.
 void plugInActor(java.lang.String playName, java.lang.String version, java.lang.String roleName, java.lang.String plugInLocation)
          Plugs in an actor with the specified role.
 void plugOutActor(java.lang.String gai)
          Plugs out the actor with the specified GAI.
 void plugOutAllActors()
          Pluggs out all the actors plugged in by this UserAgent.
private  void resumeSession()
          Resumes the user's session based on the information contained in the Session-object received in a SessionResume request.
 void setCodebase(java.lang.String url)
          Sets the URL to use as codebase when actors are plugged in.
 void suspendSession()
          Suspends the user's session.Gathers the actor's state information by sending them a SessionSuspend request.
 void windowDebug(java.lang.String dbg)
          Sends debug information to this actor's BaseFrame window, which is an interactive debug client window for several entities.
 
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, subscribeReport, 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

initiated

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

window

private UserWindow window
The reference to the UserWindow, the GUI of the UserAgent.

xfu

private XMLFileUtil xfu
Reference to the XMLFileUtil used for reading the file ActorList_User.xml.

codebase

private java.lang.String codebase
URL used as codebase when actors are plugged in.

unique

private int unique
Increasing number used for naming of actors

pluggedInActors

private java.util.Hashtable pluggedInActors
Hashtable containing plugged in actors

session

private Session session
The session object of the user of this UserAgent
Constructor Detail

UserAgent

public UserAgent()
Creates a new UserAgent.
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. Checks which type of request was received and performs the appropriate actions based on the type.
Overrides:
applicationActorEntry in class ApplicationActor
Parameters:
rpars - Instance of RequestPars which specifies type of request and additional parametres to the request.
Returns:
An instance of RequestResult which indicates success or failure in treatment of the request.
Throws:
java.lang.Exception -  

closeApplication

public void closeApplication()
                      throws java.lang.Exception
This method is used by the GUI to notify that the user wants to close the application. It tries to plug out the actor.

getCodebase

public java.lang.String getCodebase()
Returns the current URL used as codebase.
Returns:
The current codebase.

getPluggedInActors

public java.lang.String[] getPluggedInActors()
Returns a string array with the GAI of all the actors that have been plugged in by this UserAgent.
Returns:
String array with the GAI of the plugged in actors.

plugInActor

public void plugInActor(java.lang.String playName,
                        java.lang.String version,
                        java.lang.String roleName,
                        java.lang.String plugInLocation)
                 throws java.lang.Exception
Plugs in an actor with the specified role. It first tries to plugin the specified Version of the specified Play. If it was already plugged in, it disregards the result indicating FAIL. Then it sends an ActorPlugIn request of plugging in an actor with the specified role. The node where the actor is plugged in is specified by plugInLocation. If it equals Local is is plugged in on the user's node. If it equals Director it is plugged in on the Director's node.
Parameters:
playname - The name of the Play the specified role belongs to.
version - The version of the Play wanted.
role - The name of the role of the actor to be plugged in.
plugInLocation - Specifies the node where the actor is plugged in.
Throws:
java.lang.Exception - if something goes wrong.

plugOutActor

public void plugOutActor(java.lang.String gai)
                  throws java.lang.Exception
Plugs out the actor with the specified GAI. Gets the RoleSession from the hashtable with a key equal to the specified GAI. Then sends a request to the Director to plugout the specified RoleSession, meaning the cooperator of the RoleSession. If the request succeeds the RoleSession is removed from the hashtable, else an Exception is thrown to notify the UserWindow that the request failed.
Parameters:
gai - Specifies which RoleSession in the hashtable to plugout.
Throws:
An - Exception is thrown if something goes wrong or if the request fails.

plugOutAllActors

public void plugOutAllActors()
Pluggs out all the actors plugged in by this UserAgent. This method is called when the user chooses to logout without first suspending his session. Repeatedly follows the same procedure used in plugOutActor().
See Also:
plugOutActor(java.lang.String)

setCodebase

public void setCodebase(java.lang.String url)
Sets the URL to use as codebase when actors are plugged in. The codebase indicates the location of the class files to load.
Parameters:
url - The new codebase.

windowDebug

public void windowDebug(java.lang.String dbg)
Sends debug information to this actor's BaseFrame window, which is an interactive debug client window for several entities. This method is used by the UserWindow.
Parameters:
dbg - The debug information to be sent.

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.

getUnique

private int getUnique()
Returns a unigue number that is used to name the actors being plugged in by the UserAgent. The number is a counter that is incremented every time this method is called.
Returns:
The current value of the unique variable.

resumeSession

private void resumeSession()
Resumes the user's session based on the information contained in the Session-object received in a SessionResume request. First the user's UserProfile is extracted from the Session and the properties specified are set in the UserWindow. Then each of the actorinstances are recreated. The play and version that the role of the actor belongs to are first plugged in. Then the actor himself is plugged in. Further, the rolesessions of the actor is recreated and finally the actor's state is resumed by sending him a SessionResume request.

suspendSession

public void suspendSession()
Suspends the user's session.Gathers the actor's state information by sending them a SessionSuspend request. The returned information is added, together with the information stored in the hashtable, to an ArrayList to create a so called actorinstance. The set of actorinstances are added to the user's Session-object. Further, the actor's are plugged out. Finally, some information are retrieved from the UserWindow and added to the user's UserProfile-object. The SessionBase is then updated by sending the Director a SessionUpdate request with the user's Session-object added.

main

public static void main(java.lang.String[] args)
Used for debugging.