ks.server.communicator
Class Communicator

java.lang.Object
  |
  +--ks.server.communicator.Communicator

public class Communicator
extends java.lang.Object

Responsible for all communication from the server to its clients.

Communicator will need access to an IUserManager object to be able to identify the set of active uers during a broadcast. Note that we read Commands from the client and write messages to the client.


Field Summary
protected  java.util.Vector provided
          provided set of interfaces.
protected  java.util.Vector required
          required set of interfaces.
protected  IReadonlyUserManager userManagerRO
          The readonly access to the user manager.
 
Constructor Summary
Communicator()
          Communicator constructor comment.
 
Method Summary
 boolean activate()
          Nothing to do here, really.
 void broadcast(java.util.Enumeration users, Message m)
          Broadcast command to all users in given Enumeration EXCEPT self.
 void broadcast(Message m)
          Broadcast command to all users EXCEPT self.
 boolean connect(IBlock block, java.lang.String interfaceName)
           
 void connectUser(java.lang.String userName, ICommunicator agent)
          Register with the communicator the means to interact with given userName.
 void deactivate()
          Nothing to do here.
 java.util.Enumeration getProvided()
          We expose ProcessCommand interface.
 java.util.Enumeration getRequired()
          We expose ProcessCommand and IOutput required interfaces.
 void output(Message m)
          Delivers message to intended receiver.
 boolean process(java.lang.String userName, Command com)
          Communicator handles some common communication commands TellCommand ShoutCommand
protected  boolean processShout(java.lang.String userName, ShoutCommand sc)
          Process a ShoutCommand.
protected  boolean processTell(java.lang.String userName, TellCommand tc)
          Process a TellCommand.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

userManagerRO

protected IReadonlyUserManager userManagerRO
The readonly access to the user manager.


provided

protected java.util.Vector provided
provided set of interfaces.


required

protected java.util.Vector required
required set of interfaces.

Constructor Detail

Communicator

public Communicator()
Communicator constructor comment.

Method Detail

broadcast

public void broadcast(Message m)
Broadcast command to all users EXCEPT self.

Note: attributes for Message m are modified within this method to ensure efficient delivery. In particular, after this method is invoked, the value of m.getTargetUser() may have been changed.

Parameters:
m - Message to be delivered to all active users

broadcast

public void broadcast(java.util.Enumeration users,
                      Message m)
Broadcast command to all users in given Enumeration EXCEPT self.

Note: attributes for Message m are modified within this method to ensure efficient delivery. In particular, after this method is invoked, the value of m.getTargetUser() may have been changed.

Parameters:
users - Enumeration (of String) of users
m - Message to be delivered to all active users

connectUser

public void connectUser(java.lang.String userName,
                        ICommunicator agent)
Register with the communicator the means to interact with given userName.

Parameters:
userName - String representing user connecting to server
agent - ICommunicator object managing our communication.

output

public void output(Message m)
Delivers message to intended receiver.

The routing of the message is determined by the message's attributes, including its scope, from, and to user. The Protocol class contains all the specific details of specific Protocols.

Parameters:
m - Message object containing all information

activate

public boolean activate()
                 throws java.lang.Exception
Nothing to do here, really.

java.lang.Exception
See Also:
edu.wpi.cs.cs509.cmi.interfaces.IBlock#activate()

connect

public boolean connect(IBlock block,
                       java.lang.String interfaceName)
                throws java.lang.Exception
java.lang.Exception

deactivate

public void deactivate()
                throws java.lang.Exception
Nothing to do here.

java.lang.Exception
See Also:
edu.wpi.cs.cs509.cmi.interfaces.IBlock#deactivate()

getProvided

public java.util.Enumeration getProvided()
We expose ProcessCommand interface.

See Also:
edu.wpi.cs.cs509.cmi.interfaces.IBlock#getProvided()

getRequired

public java.util.Enumeration getRequired()
We expose ProcessCommand and IOutput required interfaces.

See Also:
edu.wpi.cs.cs509.cmi.interfaces.IBlock#getRequired()

process

public boolean process(java.lang.String userName,
                       Command com)
Communicator handles some common communication commands TellCommand ShoutCommand

See Also:
ks.server.interfaces.IProcessCommand#process(java.lang.String, ks.common.command.Command)

processTell

protected boolean processTell(java.lang.String userName,
                              TellCommand tc)
Process a TellCommand.

Known messages generated from this method are:

  1. outputMSG


processShout

protected boolean processShout(java.lang.String userName,
                               ShoutCommand sc)
Process a ShoutCommand.

Known messages generated from this method are:

  1. outputMessage

Parameters:
sc - the shout command to process
userName - the user requesting the command.