rmi
Class ChatParticipant

java.lang.Object
  extended by java.rmi.server.RemoteObject
      extended by java.rmi.server.RemoteServer
          extended by java.rmi.server.UnicastRemoteObject
              extended by rmi.ChatParticipant
All Implemented Interfaces:
java.io.Serializable, java.rmi.Remote, ChatParticipantInterface
Direct Known Subclasses:
ChatClient, ChatServer

public abstract class ChatParticipant
extends java.rmi.server.UnicastRemoteObject
implements ChatParticipantInterface

Class for participants in simple chat application. This class contains code common to server and clients. All parties maintain a list of clients.

See Also:
Serialized Form

Field Summary
protected  java.util.List<ChatClientInterface> clients
           
static java.lang.String errorPrefix
          Prefix for error messages.
static java.lang.String serverPrefix
          Prefix for messages from server.
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Constructor Summary
ChatParticipant()
          Constructs object.
 
Method Summary
 void addClient(ChatClientInterface c)
          Adds client.
 void broadcast(java.lang.String message)
          Sends message to all clients.
abstract  java.lang.String getMessagePrefix()
          Gets prefix for messages broadcast by this object.
 void removeClient(ChatClientInterface c)
          Removes client.
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
clone, exportObject, exportObject, exportObject, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface rmi.ChatParticipantInterface
display
 

Field Detail

clients

protected java.util.List<ChatClientInterface> clients

serverPrefix

public static final java.lang.String serverPrefix
Prefix for messages from server.

See Also:
Constant Field Values

errorPrefix

public static final java.lang.String errorPrefix
Prefix for error messages.

See Also:
Constant Field Values
Constructor Detail

ChatParticipant

public ChatParticipant()
                throws java.rmi.RemoteException
Constructs object.

Throws:
java.rmi.RemoteException
Method Detail

addClient

public void addClient(ChatClientInterface c)
               throws java.rmi.RemoteException
Adds client.

Specified by:
addClient in interface ChatParticipantInterface
Parameters:
c - client to add
Throws:
java.rmi.RemoteException

removeClient

public void removeClient(ChatClientInterface c)
                  throws java.rmi.RemoteException
Removes client.

Specified by:
removeClient in interface ChatParticipantInterface
Parameters:
c - client to remove
Throws:
java.rmi.RemoteException

broadcast

public void broadcast(java.lang.String message)
               throws java.rmi.RemoteException
Sends message to all clients.

Specified by:
broadcast in interface ChatParticipantInterface
Parameters:
message - message to send to all
Throws:
java.rmi.RemoteException

getMessagePrefix

public abstract java.lang.String getMessagePrefix()
Gets prefix for messages broadcast by this object.

Returns:
prefix for messages (screen name for clients, e.g.)