import java.rmi.*; import java.rmi.server.*; import java.util.Vector; /** * Remote Class for the chat server for ex6 */ public class ChatServer extends UnicastRemoteObject implements ChatInterface { private int messId = 0; private Vector messages; private int sleepTime = 10; // ms sleep if no message was replied public ChatServer(int sleep) throws RemoteException { messId = 0; messages = new Vector(); sleepTime = 10; } /** * Method to find out what message to poll * @return the next (expected) message-id * @exception RemoteException if the remote invocation fails. */ public int getMessId() throws RemoteException { /* clip */ } /** * Method to join a chat * @param username your username string for chat * @return the next (expected) message-id, -1 if not success * @exception RemoteException if the remote invocation fails. */ public int join(String username) throws RemoteException { /* clip */ } /** * Poll for a new message * @param messageid the message id requested * @return A string containing the username and the message, null * if no such message is available. Username of the message sender * is the first word (space separated) of the message. * @exception RemoteException if the remote invocation fails. */ public String pollMessage(int messageid) throws RemoteException { if (messageid < messId) { /* clip */ } else { try { Thread.sleep(sleepTime); } catch (InterruptedException e) { }; return null; } } /** * Post a new message * @param username sender's username * @param message the message * @return the message id * @exception RemoteException if the remote invocation fails. */ public int postMessage(String username, String message) throws RemoteException { /* clip */ } /** * Disconnect a chat (actually, we could have done without this) * @param username your username * @exception RemoteException if the remote invocation fails. */ public void disconnect(String username) throws RemoteException { /* clip */ } } // class ChatServer