common.interfaces
Interface MSForServletInterface

All Superinterfaces:
java.rmi.Remote
All Known Implementing Classes:
Communication

public interface MSForServletInterface
extends java.rmi.Remote

This class represents the methods that the object exported by the Gossip Message Server must implement to let a Gossip Servlet use it.

Author:
Marco Cornolti and Alessandro Franchini

Method Summary
 void addToFriends(User user, java.lang.String pw, User userToAdd)
          Used by a servlet to tell the message server to add another user in his contact list as friend.
 void blockContact(User user, java.lang.String pw, User userToBlock)
          Marks userToBlock in the user's contact list as blocked, so that no more messages from that user are accepted.
 void changePassword(User user, java.lang.String oldPw, java.lang.String newPw)
          Changes the user password.
 void deleteDownloadedMsgs(User user, java.lang.String pw)
          Deletes the messages that are already downloaded by a User.
 java.util.Vector<Message> downloadMsgs(User user, java.lang.String pw)
          Downloads the messages stored in the Message server for a user.
 void forwardMessage(Message msg)
          Forwards a message.
 ContactList getContactList(User user, java.lang.String pw)
          Returns user list of contacts.
 User getUserContact(User user)
          Gets a User IP address and TCP port to directely connect to its servlet.
 void removeContact(User user, java.lang.String pw, User userToRemove)
          Removes userToRemove from user's contact list, so that no more messages from that user are accepted.
 void setState(User user, java.lang.String pw, boolean state)
          Sets a user state.
 boolean testPorts(int port, java.net.InetAddress ip)
          Tests the servlet port trying to connect to them.
 

Method Detail

addToFriends

void addToFriends(User user,
                  java.lang.String pw,
                  User userToAdd)
                  throws java.rmi.RemoteException,
                         UserNotManagedException,
                         WrongPasswordException,
                         UserBlockedException,
                         UserAlreadyInsertedException
Used by a servlet to tell the message server to add another user in his contact list as friend.

Parameters:
user - the invoking user.
pw - the invoking user password.
userToAdd - the user to add.
Throws:
UserNotManagedException - if the user is not managed by the local MS.
UserBlockedException - if the user is blocked.
WrongPasswordException - if the password is not right.
UserAlreadyInsertedException - if the user is already contained in the incoming list.
java.rmi.RemoteException - if a communication problem ocurred.

getUserContact

User getUserContact(User user)
                    throws java.rmi.RemoteException,
                           UserNotExistsException,
                           GenericErrorException,
                           UserBlockedException
Gets a User IP address and TCP port to directely connect to its servlet.

Parameters:
user - the user whose connection datas is wanted. Only the nickname is considered.
Returns:
the user with the correctly obtained IP address and TCP port.
Throws:
java.rmi.RemoteException - if a communication problem occurs.
UserNotExistsException - if the specificed user nickname does not exists.
GenericErrorException - if another error occurred (i.e. a communication problem with another message server).
UserBlockedException - if the user is blocked.

blockContact

void blockContact(User user,
                  java.lang.String pw,
                  User userToBlock)
                  throws java.rmi.RemoteException,
                         UserNotManagedException,
                         UserNotExistsException,
                         WrongPasswordException,
                         UserBlockedException
Marks userToBlock in the user's contact list as blocked, so that no more messages from that user are accepted.

Parameters:
user - the user.
pw - the user's password.
userToBlock - the user to block.
Throws:
UserNotManagedException - if user is not managed by this message server.
UserNotExistsException - if the userToBlock is not present in the contact list.
WrongPasswordException - if the user's password is wrong.
UserBlockedException - if the user is blocked
java.rmi.RemoteException

removeContact

void removeContact(User user,
                   java.lang.String pw,
                   User userToRemove)
                   throws java.rmi.RemoteException,
                          UserNotManagedException,
                          UserNotExistsException,
                          WrongPasswordException,
                          UserBlockedException
Removes userToRemove from user's contact list, so that no more messages from that user are accepted.

Parameters:
user - the user.
pw - the user's password.
userToRemove - the user to remove.
Throws:
UserNotManagedException - if user is not managed by this message server.
UserNotExistsException - if the userToRemove is not present in the contact list.
WrongPasswordException - if the user's password is wrong.
UserBlockedException - if the user is currently blocked.
java.rmi.RemoteException

downloadMsgs

java.util.Vector<Message> downloadMsgs(User user,
                                       java.lang.String pw)
                                       throws java.rmi.RemoteException,
                                              UserNotManagedException,
                                              UserBlockedException,
                                              WrongPasswordException
Downloads the messages stored in the Message server for a user. After calling this method, the servlet has to call deleteDownloadedMsgs to free the server deleting old messages.

Parameters:
user - the user whose messages are wanted.
pw - the user's password
Returns:
An empty Vector if the user has no messages. A vector containing the user's messages otherwise.
Throws:
java.rmi.RemoteException - if a communication problem occurs.
UserNotManagedException - if the user is not managed by this message server.
UserBlockedException - if the user is blocked (i.e. to be moved).
WrongPasswordException - if the given password is wrong.

deleteDownloadedMsgs

void deleteDownloadedMsgs(User user,
                          java.lang.String pw)
                          throws java.rmi.RemoteException,
                                 UserNotManagedException,
                                 WrongPasswordException,
                                 UserBlockedException
Deletes the messages that are already downloaded by a User.

Parameters:
user - the user.
pw - the user password.
Throws:
java.rmi.RemoteException - if a communication problem occurs.
UserNotManagedException - if the user is not managed by the MS.
WrongPasswordException - if the password is wrong.
UserBlockedException - is the user is blocked.

setState

void setState(User user,
              java.lang.String pw,
              boolean state)
              throws java.rmi.RemoteException,
                     UserNotManagedException,
                     WrongPasswordException,
                     GenericErrorException,
                     UserBlockedException
Sets a user state. Must be invoked whenever the user gets on-line or is about to go off-line.

Parameters:
user - the user
pw - the user password
state - true if the state is on-line, false if the state is off-line
Throws:
java.rmi.RemoteException - if a communication problem occurs.
UserNotManagedException - if the user is not managed by the MS.
WrongPasswordException - if the password is wrong.
GenericErrorException - if another error occurred, i.e. the server could not define the servlet ip address.
UserBlockedException - if the user is blocked.

forwardMessage

void forwardMessage(Message msg)
                    throws java.rmi.RemoteException,
                           NotAllowedException,
                           UserNotManagedException,
                           GenericErrorException,
                           UserNotExistsException,
                           SystemErrorException
Forwards a message. The message recipient or the message sender must be managed by the MS. If the recipient is managed by the MS, the message gets stored and is ready to be downloaded. If the recipient is not local but the sender is, the MS forwards the message to the correct MS.

Parameters:
msg - the message to forward.
Throws:
UserNotManagedException - if the MS does not manage the recipient nor the sender.
NotAllowedException - if the recipient user does have the sender in its blockedlist.
UserNotExistsException - if the recipient does not exist in the whole system.
GenericErrorException - if another error has occurred.
SystemErrorException - if a system error occurred.
java.rmi.RemoteException

getContactList

ContactList getContactList(User user,
                           java.lang.String pw)
                           throws java.rmi.RemoteException,
                                  UserNotManagedException,
                                  WrongPasswordException,
                                  UserBlockedException
Returns user list of contacts.

Parameters:
user - the user
pw - the user password
Returns:
the contact list.
Throws:
java.rmi.RemoteException - if a communication problem occurred.
UserNotManagedException - if the user is not managed by this message server.
WrongPasswordException - if the user's password is wrong.
UserBlockedException - if the user is blocked.

changePassword

void changePassword(User user,
                    java.lang.String oldPw,
                    java.lang.String newPw)
                    throws java.rmi.RemoteException,
                           UserNotManagedException,
                           WrongPasswordException,
                           UserBlockedException
Changes the user password.

Parameters:
user - the user
oldPw - the old password
newPw - the new password to set
Throws:
java.rmi.RemoteException - if a communication problem occurred.
UserNotManagedException - if the user is not managed by the MS.
WrongPasswordException - if the old password is wrong.
UserBlockedException - if the user is blocked.

testPorts

boolean testPorts(int port,
                  java.net.InetAddress ip)
                  throws java.rmi.RemoteException
Tests the servlet port trying to connect to them.

Parameters:
port - the port to test.
ip - the servlet ip.
Returns:
true if the test was correctly terminated, false otherwise.
Throws:
java.rmi.RemoteException - if a communication problem occurred while invoking this method.