Chat.v1_1
Class ChatServer

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

public class ChatServer
extends ApplicationActor

A ChatServer is an Actor that lets one or more ChatClients connect to and disconnect from it. When a ChatClient wants to send a message to all the other connected ChatClients, it sends the message to the ChatServer which then distributes it to all the other ChatClients.

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.

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

Field Summary
private  java.lang.String CHAT_MESSAGE
          Used when a ChatClient wants to send a message 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 from 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  java.util.Hashtable ht
          Hashtable where all the ChatClient's GAI are stored with their username as keys.
private  boolean initiated
          Indicates wether initial ActorPlugIn has been performed or not
 
Fields inherited from class PaP.Actor
bf, context, fh
 
Constructor Summary
ChatServer()
          Creates a new ChatServer.
 
Method Summary
 RequestResult applicationActorEntry(RequestPars rpars)
          This method is the common entry point for all external requests to this actor.
private  void connectUser(java.lang.String username, RoleSession rs)
          Adds the user with the specified username to the the hashtable of users connected to this 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.
private  void disconnectUser(java.lang.String username)
          Removes the user with the specified username from the hashtable of users connected to this ChatServer.
private  void distributeMessage(java.lang.String fromUser, java.lang.String message)
          Sends the specified message to all connected ChatClients except the user with the specified username.
private  java.lang.String[] getConnectedUsers()
          Returns a string array with a list of the usernames and the GAI of all the ChatClients currently connected to this ChatServer.
private  boolean isUserConnected(java.lang.String username)
          Checks all the usernames of the users connected (all the keys in the hashtable) to see if the user with the specified username is connected.
 
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 from 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.

ht

private java.util.Hashtable ht
Hashtable where all the ChatClient's GAI are stored with their username as keys.

initiated

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

ChatServer

public ChatServer()
Creates a new ChatServer.
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 -  

connectUser

private void connectUser(java.lang.String username,
                         RoleSession rs)
Adds the user with the specified username to the the hashtable of users connected to this ChatServer.
Parameters:
username - The username of the user connecting.
rs - The rolesession the user is connected via.

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.

disconnectUser

private void disconnectUser(java.lang.String username)
Removes the user with the specified username from the hashtable of users connected to this ChatServer.
Parameters:
username - The username of the user disconnecting.

distributeMessage

private void distributeMessage(java.lang.String fromUser,
                               java.lang.String message)
Sends the specified message to all connected ChatClients except the user with the specified username. This is the username of the user sending the message.
Parameters:
fromUser - The username of the user sending the message.
message - The message to distribute.

getConnectedUsers

private java.lang.String[] getConnectedUsers()
Returns a string array with a list of the usernames and the GAI of all the ChatClients currently connected to this ChatServer.
Returns:
String array of all the ChatClients connected.

isUserConnected

private boolean isUserConnected(java.lang.String username)
Checks all the usernames of the users connected (all the keys in the hashtable) to see if the user with the specified username is connected.
Parameters:
username - The username of the user to search for.
Returns:
Returns true if the specified username was found in the hashtable. This would indicate that the user is connected. Else it returns false.