messageServerP
Class ManagedUser

java.lang.Object
  extended by common.User
      extended by messageServerP.ManagedUser
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<java.lang.Object>

public class ManagedUser
extends User
implements java.lang.Cloneable

A representation of a user managed by the Message Server. Any affection of a user data is backupped on the main backupper.

Author:
Marco Cornolti
See Also:
Serialized Form

Field Summary
private  boolean blocked
           
private  int downloadedMessages
           
private  ContactList list
           
private  java.util.Vector<Message> msgsQueue
           
private  java.lang.String password
           
private static long serialVersionUID
           
 
Constructor Summary
ManagedUser(java.lang.String nick, java.net.InetAddress ip, int port, java.lang.String password)
          Creates a Managed User.
 
Method Summary
 void addFriend(User user)
          Adds a friend to the incoming contact list of this user.
 void addMsgToQueue(Message ms)
          Adds a message to the incoming queue of the user
 void block(boolean blocked)
          Blocks the user to not let it perform any action.
 void blockFriend(User user)
          Sets a contact as blocked (no more messages by this user are accepted).
 boolean changePassword(java.lang.String oldPw, java.lang.String newPw)
          Changes this user password.
 boolean checkPassword(java.lang.String pw)
          Checks the password
 ManagedUser clone()
           
 User copyContactTo(User user)
          Copies IP and port of this user to the user passed by argument.
 void deleteDownloadedQueue()
          Deletes the already downloaded messages.
 boolean equals(ManagedUser us2)
          Tests if a user given as argument has the same nickname of this one.
 ContactList getContactList()
          Gets the user's Contact List.
 java.util.Vector<Message> getQueue()
          Returns the messagges in the queue and marks it as downloaded, ready to be deleted.
 boolean isBlocked()
          Check if a user can perform any action.
 boolean isFriendOf(User user)
          Checks if a user given by argument accepts messages from this managed user.
 void refreshBackup()
          Refreshes the main backup updating it with the state of this user.
 void removeContact(User user)
          Removes a user from this user contact list.
 
Methods inherited from class common.User
compareTo, equals, getConn, getIP, getNick, getPort, isFriend, isOnline, setConn, setFriend, setIp, setName, setOnline, setPort
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

password

private java.lang.String password

blocked

private boolean blocked

msgsQueue

private java.util.Vector<Message> msgsQueue

downloadedMessages

private int downloadedMessages

list

private ContactList list
Constructor Detail

ManagedUser

public ManagedUser(java.lang.String nick,
                   java.net.InetAddress ip,
                   int port,
                   java.lang.String password)
Creates a Managed User.

Parameters:
password - the managed user password.
nick - the user nickname.
ip - the user ip address.
port - the user port.
Method Detail

checkPassword

public boolean checkPassword(java.lang.String pw)
Checks the password

Parameters:
pw - the password to check
Returns:
true if and only if the password given by argument corresponds to the user password.

addMsgToQueue

public void addMsgToQueue(Message ms)
Adds a message to the incoming queue of the user

Parameters:
ms - the message to add

getQueue

public java.util.Vector<Message> getQueue()
Returns the messagges in the queue and marks it as downloaded, ready to be deleted.

Returns:
the queued messages.

deleteDownloadedQueue

public void deleteDownloadedQueue()
Deletes the already downloaded messages.


isBlocked

public boolean isBlocked()
Check if a user can perform any action.

Returns:
true if the user il blocked

block

public void block(boolean blocked)
Blocks the user to not let it perform any action.

Parameters:
blocked - true if the user must be set to blocked, false otherwise.

addFriend

public void addFriend(User user)
               throws UserAlreadyInsertedException
Adds a friend to the incoming contact list of this user.

Parameters:
user - the user to add
Throws:
UserAlreadyInsertedException

blockFriend

public void blockFriend(User user)
Sets a contact as blocked (no more messages by this user are accepted).

Parameters:
user - the user to block

removeContact

public void removeContact(User user)
Removes a user from this user contact list.

Parameters:
user - the user to remove.

isFriendOf

public boolean isFriendOf(User user)
Checks if a user given by argument accepts messages from this managed user.

Parameters:
user - the user.
Returns:
true if and only if the Managed User accepts messages from the User given by argument

changePassword

public boolean changePassword(java.lang.String oldPw,
                              java.lang.String newPw)
Changes this user password.

Parameters:
oldPw - the old password.
newPw - the new password.
Returns:
true only if the old password is right and the new password has been set.

getContactList

public ContactList getContactList()
Gets the user's Contact List.

Returns:
the user's Contact List

copyContactTo

public User copyContactTo(User user)
Copies IP and port of this user to the user passed by argument.

Parameters:
user - the user to copy the IP and port to.
Returns:
the user passed by argument with the new cloned IP and port.

refreshBackup

public void refreshBackup()
Refreshes the main backup updating it with the state of this user.


equals

public boolean equals(ManagedUser us2)
Tests if a user given as argument has the same nickname of this one.

Parameters:
us2 - the user whose nickname must be checked.
Returns:
true if the two users nicknames are equal.

clone

public ManagedUser clone()
Overrides:
clone in class User