rmi
Class ChatServer

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
                  extended by rmi.ChatServer
All Implemented Interfaces:
java.io.Serializable, java.rmi.Remote, ChatParticipantInterface, ChatServerInterface

public class ChatServer
extends ChatParticipant
implements ChatServerInterface

Class for server for simple chat program (with instructions for running the application). An object of this class functions as a server for the application.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class rmi.ChatParticipant
clients, errorPrefix, serverPrefix
 
Fields inherited from class java.rmi.server.RemoteObject
ref
 
Constructor Summary
ChatServer()
          Constructs server object.
 
Method Summary
 void addClient(ChatClientInterface c)
          Adds client, printing some info to standard output and telling all previous clients to add this one.
 void broadcast(java.lang.String message)
          Sends message to all clients.
 void display(java.lang.String message)
          Displays message.
 java.util.List<ChatClientInterface> getClients()
          Gets a list of clients.
 java.lang.String getMessagePrefix()
          Gets prefix for messages broadcast by this object.
static void main(java.lang.String[] args)
          Main program -- creates a server object and registers it.
 void removeClient(ChatClientInterface c)
          Removes client, printing some info to standard output and telling all other clients to remove this one.
 
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
 

Constructor Detail

ChatServer

public ChatServer()
           throws java.rmi.RemoteException
Constructs server object.

Throws:
java.rmi.RemoteException
Method Detail

addClient

public void addClient(ChatClientInterface c)
               throws java.rmi.RemoteException
Adds client, printing some info to standard output and telling all previous clients to add this one.

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

removeClient

public void removeClient(ChatClientInterface c)
                  throws java.rmi.RemoteException
Removes client, printing some info to standard output and telling all other clients to remove this one.

Specified by:
removeClient in interface ChatParticipantInterface
Overrides:
removeClient in class ChatParticipant
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
Overrides:
broadcast in class ChatParticipant
Parameters:
message - message to send to all
Throws:
java.rmi.RemoteException

display

public void display(java.lang.String message)
             throws java.rmi.RemoteException
Displays message. Prints to standard output.

Specified by:
display in interface ChatParticipantInterface
Parameters:
message - message to display
Throws:
java.rmi.RemoteException

getClients

public java.util.List<ChatClientInterface> getClients()
                                               throws java.rmi.RemoteException
Gets a list of clients.

Specified by:
getClients in interface ChatServerInterface
Returns:
list of clients currently participating
Throws:
java.rmi.RemoteException

getMessagePrefix

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

Specified by:
getMessagePrefix in class ChatParticipant
Returns:
prefix for messages (server's prefix)

main

public static void main(java.lang.String[] args)
Main program -- creates a server object and registers it.

Parameters:
args - command-line arguments -- not used