Chat.v1_1
Class ChatClient

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

public class ChatClient
extends ApplicationActor

A ChatClient is an Actor that can connect to and disconnect from a ChatServer. Each ChatClient has an instance of ChatClientWindow which is the Graphical User Interface (GUI). A ChatClient connects to a ChatServer by sending a RoleFigurePlugIn request to the Director. He then creates a RoleSession between the ChatClient and the specified ChatServer. Once a RoleSession is created the ChatClient can send ApplicationMessages of one of the predefined types to the ChatServer.

Each ChatClient has a username used by the user. This can be set through the GUI. chatServerGAI is the GAI of the ChatServer this ChatClient last connected to. Both the usernam and the chatServerGAI is stored in the actor's state when he is suspended.

Version:
1.0 - 03.05.02
Author:
Lars Erik Liljebäck
See Also:
Serialized Form

Inner Class Summary
 class ChatClient.CloseWindowThread
          This thread is started when an ActorPlugOut request is received.
 
Field Summary
private  java.lang.String CHAT_MESSAGE
          Used when a ChatClient wants to send a message to the ChatServer.
private  java.lang.String chatServerGAI
          The GAI of the last used ChatServer
private  RoleSession chatServerRoleSession
          RoleSession to the ChatServer.
private  java.lang.String CONNECT_USER
          Used when a ChatClient wants to connect to a ChatServer.
private  java.lang.String DISCONNECT_USER
          Used when a ChatClient wants to disconnect to a ChatServer.
private  java.lang.String GET_USERLIST
          Used when a ChatClient wants a list of all the ChatClients currently connected to the ChatServer.
private  boolean initiated
          Indicates wether initial ActorPlugIn has been performed or not
private  java.lang.String username
          The username of this ChatClient.
private  ChatClientWindow window
          Reference to the GUI.
 
Fields inherited from class PaP.Actor
bf, context, fh
 
Constructor Summary
ChatClient()
          Creates a new ChatClient.
 
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 ChatClientWindow to notify that the user wants to close the application.
 void connect(java.lang.String serverGAI)
          Sends a RoleFigurePlugIn request to the Director to plugin a RoleSession between this ChatClient and the specified ChatServer.
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.
 void disconnect()
          Sends a request to the ChatServer to disconnect this ChatClient from the ChatServer.
 java.lang.String getChatServerGAI()
          Returns the value of ChatServerGAI which is the GAI of the last ChatServer this ChatClient connected to.
 void getUserlist()
          Sends the a request to the ChatServer for a list of all the ChatClients currently connected to the ChatServer.
 java.lang.String getUsername()
          Returns the username.
 void sendMessage(java.lang.String message)
          Sends the specified message to the ChatServer as a RoleSessionAction request of type CHAT_MESSAGE.
 void setChatServerGAI(java.lang.String gai)
          Sets the value of chatServerGAI which is the GAI of the last ChatServer this ChatClient connected to.
 void setUsername(java.lang.String newUsername)
          Sets the username that the user will use to logg into a ChatServer.
 
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

CHAT_MESSAGE

private final java.lang.String CHAT_MESSAGE
Used when a ChatClient wants to send a message to the ChatServer.

CONNECT_USER

private final java.lang.String CONNECT_USER
Used when a ChatClient wants to connect to a ChatServer.

DISCONNECT_USER

private final java.lang.String DISCONNECT_USER
Used when a ChatClient wants to disconnect to a ChatServer.

GET_USERLIST

private final java.lang.String GET_USERLIST
Used when a ChatClient wants a list of all the ChatClients currently connected to the ChatServer.

window

private ChatClientWindow window
Reference to the GUI.

chatServerRoleSession

private RoleSession chatServerRoleSession
RoleSession to the ChatServer. If this is null it indicates that the ChatClient is not connected.

username

private java.lang.String username
The username of this ChatClient.

chatServerGAI

private java.lang.String chatServerGAI
The GAI of the last used ChatServer

initiated

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

ChatClient

public ChatClient()
Creates a new ChatClient.
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. It 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()
This method is used by the ChatClientWindow to notify that the user wants to close the application. It checks if the chatServerRoleSession is null to check if the ChatClient is connected to a ChatServer or not. If it is connected it calls disconnect() to disconnect it from the ChatServer. If an Exception is caught it is added to the chatlog and nothing happens. After an eventual successful disconnection, the actor is plugged out.

connect

public void connect(java.lang.String serverGAI)
             throws java.lang.Exception
Sends a RoleFigurePlugIn request to the Director to plugin a RoleSession between this ChatClient and the specified ChatServer. If it is plugged in successfully, it sends a request to the ChatServer to connect this ChatClient with the current username. This is done by sending a RoleSessionAction request of type CONNECT_USER.
Parameters:
serverGAI - String form of the ChatServer's GAI.
Throws:
java.lang.Exception - if something goes wrong.

disconnect

public void disconnect()
                throws java.lang.Exception
Sends a request to the ChatServer to disconnect this ChatClient from the ChatServer. This is done by sending a RoleSessionAction request of type DISCONNECT_USER. If it is disconnected successfully, it sends a RoleFigurePlugOut request to the Director to plug out the RoleSession between this ChatClient and the ChatServer.
Throws:
java.lang.Exception - if something goes wrong.

getChatServerGAI

public java.lang.String getChatServerGAI()
Returns the value of ChatServerGAI which is the GAI of the last ChatServer this ChatClient connected to.
Returns:
The value of ChatServerGAI.

getUserlist

public void getUserlist()
                 throws java.lang.Exception
Sends the a request to the ChatServer for a list of all the ChatClients currently connected to the ChatServer. The request is sent as a RoleSessionAction request of type GET_USERLIST.
Throws:
java.lang.Exception - if something goes wrong.

getUsername

public java.lang.String getUsername()
Returns the username.
Returns:
The username.

sendMessage

public void sendMessage(java.lang.String message)
                 throws java.lang.Exception
Sends the specified message to the ChatServer as a RoleSessionAction request of type CHAT_MESSAGE. The ChatServer will then distribute it to the other connected ChatClients.
Parameters:
message - The message to be sent.
Throws:
java.lang.Exception - if something goes wrong.

setChatServerGAI

public void setChatServerGAI(java.lang.String gai)
Sets the value of chatServerGAI which is the GAI of the last ChatServer this ChatClient connected to.
Parameters:
gai - The new chatServerGAI.

setUsername

public void setUsername(java.lang.String newUsername)
Sets the username that the user will use to logg into a ChatServer. The user should not be able to change his username while he is connected to a ChatServer since it is his identifier.
Parameters:
newUsername - The new username.

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.