it.gotoandplay.smartfoxserver.data.buddylist
Class BuddyListManager

java.lang.Object
  extended by it.gotoandplay.smartfoxserver.data.buddylist.BuddyListManager
All Implemented Interfaces:
it.gotoandplay.smartfoxserver.lib.IService

public class BuddyListManager
extends java.lang.Object
implements it.gotoandplay.smartfoxserver.lib.IService

The BuddyManager class is responsible for managing the buddy lists inside its Zone.

Methods such as addBuddy, removeBuddy etc... will perform the change on the server side but won't dispatch any event back to the clients. When you have done all the changes to one or more buddy lists you can broadcast the changes by calling the sendBuddyListUpdate() method.


Field Summary
static java.lang.String DEFAULT_ADVANCED_PERSISTER_CLASS
           
static int DEFAULT_MAX_BUDDY_VARS
           
static int DEFAULT_MAX_BUDDY_VARS_LEN
           
static int DEFAULT_MAX_BUDDY_VARS_NAME
           
static java.lang.String DEFAULT_MUTUAL_SETTINGS
           
static java.lang.String DEFAULT_PERMISSION_TIMEOUT
           
static java.lang.String DEFAULT_PERSISTER_CLASS
           
static java.lang.String DEFAULT_SECURITY_MODE
           
static int DEFAULT_SIZE
           
static java.lang.String DEFAULT_USE_OFFLINE_VARIABLES
           
static java.lang.String DEFAULT_USE_PERMISSION
           
static java.lang.String OFFLINE_VARS_PREFIX
           
static int SECURITY_MODE_ADVANCED
           
static int SECURITY_MODE_BASIC
           
 
Constructor Summary
BuddyListManager(java.lang.String zoneName, int maxLength)
           
BuddyListManager(java.lang.String zoneName, int maxLength, IBuddyListPersister persister)
           
 
Method Summary
 void addBuddy(java.lang.String owner, java.lang.String buddyName)
           
 void addPermissionRequest(java.lang.String sender, java.lang.String target)
          Manages the addition of a permissione request in the local cache.
 boolean checkBuddyListSize(java.lang.String name)
           
 void checkValidAddRequest(User sender, java.lang.String target)
           
 void clearBuddyList(java.lang.String owner)
          Clear the buddy list of the specified user
 void clearExpiredPermissionRequests()
           
 void destroy(java.lang.Object param)
           
 StorableBuddyList getBuddyList(java.lang.String name)
           
 java.util.Map<java.lang.String,StorableBuddyList> getBuddyLists()
           
 int getBuddyPermissionTimeout()
           
 java.util.Map<java.lang.String,java.lang.String> getBuddyVariables(it.gotoandplay.smartfoxserver.data.buddylist.LoadableBuddyItem buddy)
          Return the variables map of a buddy
 java.util.Map<java.lang.String,java.lang.String> getBuddyVariables(java.lang.String buddyName)
          Return the variables map of a buddy
 java.util.LinkedList getClientsToUpdate(java.lang.String buddyName)
           
 int getMaxBuddyVarLen()
          Get the max length of a buddy variable, expressed in number of characters.
 int getMaxBuddyVars()
          Get the max amount of buddy variables allowed
 java.util.Map<java.lang.String,java.lang.String> getOfflineBuddyVariables(java.lang.String ownerName)
           
 java.lang.String getOwnerListFullErrorMessage()
          Get the "Owner Buddy List Full" custom error message
 java.util.Map<it.gotoandplay.smartfoxserver.data.buddylist.PermissionRequestKey,it.gotoandplay.smartfoxserver.data.buddylist.PermissionRequest> getPendingRequests()
           
 java.util.Map<it.gotoandplay.smartfoxserver.data.buddylist.PermissionRequestKey,it.gotoandplay.smartfoxserver.data.buddylist.PermissionRequest> getPermissionRequests()
           
 IBuddyListPersister getPersister()
          Get the IBuddyListPersister
 int getSecurityMode()
           
 java.lang.String getTargetListFullErrorMessage()
          Get the "Target Buddy List Full" custom error message
 boolean getUseOfflineVariables()
           
 java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> getVarCache()
           
 void init(java.lang.Object param)
           
 boolean isAddBuddyPermission()
           
 boolean isAdvancedMode()
           
 boolean isBuddyOnline(java.lang.String userName)
          Return the current online status of a buddy / user
 boolean isMutualAddBuddy()
           
 boolean isMutualRemoveBuddy()
           
 it.gotoandplay.smartfoxserver.data.buddylist.LoadableBuddyList loadBuddyList(java.lang.String userName)
          Load a buddy list
 boolean removeBuddy(java.lang.String owner, java.lang.String buddyName)
           
 void removeBuddyList(java.lang.String owner)
          Remove a buddy list
 void saveAllBuddyLists()
          Saves all buddy lists in memory.
 void saveAndRemove(java.lang.String owner)
          Save a buddy list item and removes it
 boolean saveBuddyList(java.lang.String userName)
          Save the buddy list of a specific user.
 void sendBuddyListUpdate(User user)
          Send an update about the specified User to all clients that have him/her in their buddy list
 void setAddBuddyPermission(boolean addBuddyPermission)
           
 void setBuddyBlockStatus(User owner, java.lang.String buddyName, boolean status)
          Set buddy block status
 void setBuddyPermissionTimeout(int buddyPermissionTimeout)
           
 void setBuddyVariables(java.lang.String ownerName, java.util.Map<java.lang.String,java.lang.String> variables)
          Set the buddyVariables of User
 java.util.List<java.lang.String> setBuddyVariables(User user, java.util.Map<java.lang.String,java.lang.String> variables)
          Set one or more buddy variables
 void setMaxBuddyVars(int maxBuddyVars)
          Set the max amount of buddy variables allowed
 void setMaxBuddyVarsLen(int value)
          Set the max length of a buddy variable, expressed in number of characters.
 void setMutualAddBuddy(boolean mutualAddBuddy)
           
 void setMutualRemoveBuddy(boolean mutualRemoveBuddy)
           
 void setOwnerListFullErrorMessage(java.lang.String message)
          Set a custom message for the "Owner Buddy List Full" error.
 boolean setPermissionStatus(java.lang.String sender, java.lang.String target, it.gotoandplay.smartfoxserver.data.buddylist.PermissionStatus status)
          Set the status of the permission request
 void setPersister(IBuddyListPersister persister)
          Set the buddy list persister
 void setSecurityMode(int securityMode)
           
 void setTargetListFullErrorMessage(java.lang.String message)
          Set a custom message for the "Target Buddy List Full" error.
 void setUseOfflineVariables(boolean useOfflineVariables)
           
 boolean validateRecipient(User sender, User recipient)
          Check a sender/receiver pair for a private message from BuddyList
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SECURITY_MODE_BASIC

public static final int SECURITY_MODE_BASIC
See Also:
Constant Field Values

SECURITY_MODE_ADVANCED

public static final int SECURITY_MODE_ADVANCED
See Also:
Constant Field Values

DEFAULT_PERSISTER_CLASS

public static final java.lang.String DEFAULT_PERSISTER_CLASS
See Also:
Constant Field Values

DEFAULT_ADVANCED_PERSISTER_CLASS

public static final java.lang.String DEFAULT_ADVANCED_PERSISTER_CLASS
See Also:
Constant Field Values

DEFAULT_SIZE

public static final int DEFAULT_SIZE
See Also:
Constant Field Values

DEFAULT_MAX_BUDDY_VARS

public static final int DEFAULT_MAX_BUDDY_VARS
See Also:
Constant Field Values

DEFAULT_USE_OFFLINE_VARIABLES

public static final java.lang.String DEFAULT_USE_OFFLINE_VARIABLES
See Also:
Constant Field Values

DEFAULT_SECURITY_MODE

public static final java.lang.String DEFAULT_SECURITY_MODE
See Also:
Constant Field Values

OFFLINE_VARS_PREFIX

public static java.lang.String OFFLINE_VARS_PREFIX

DEFAULT_MUTUAL_SETTINGS

public static final java.lang.String DEFAULT_MUTUAL_SETTINGS
See Also:
Constant Field Values

DEFAULT_USE_PERMISSION

public static final java.lang.String DEFAULT_USE_PERMISSION
See Also:
Constant Field Values

DEFAULT_PERMISSION_TIMEOUT

public static final java.lang.String DEFAULT_PERMISSION_TIMEOUT
See Also:
Constant Field Values

DEFAULT_MAX_BUDDY_VARS_NAME

public static final int DEFAULT_MAX_BUDDY_VARS_NAME
See Also:
Constant Field Values

DEFAULT_MAX_BUDDY_VARS_LEN

public static final int DEFAULT_MAX_BUDDY_VARS_LEN
See Also:
Constant Field Values
Constructor Detail

BuddyListManager

public BuddyListManager(java.lang.String zoneName,
                        int maxLength)

BuddyListManager

public BuddyListManager(java.lang.String zoneName,
                        int maxLength,
                        IBuddyListPersister persister)
Method Detail

init

public void init(java.lang.Object param)
Specified by:
init in interface it.gotoandplay.smartfoxserver.lib.IService

destroy

public void destroy(java.lang.Object param)
Specified by:
destroy in interface it.gotoandplay.smartfoxserver.lib.IService

getPersister

public IBuddyListPersister getPersister()
Get the IBuddyListPersister

Returns:
the persister for this buddy manager

setPersister

public void setPersister(IBuddyListPersister persister)
Set the buddy list persister

Parameters:
persister - a valid persister object

addBuddy

public void addBuddy(java.lang.String owner,
                     java.lang.String buddyName)
              throws it.gotoandplay.smartfoxserver.exceptions.BuddyListException
Throws:
it.gotoandplay.smartfoxserver.exceptions.BuddyListException

removeBuddy

public boolean removeBuddy(java.lang.String owner,
                           java.lang.String buddyName)

getBuddyList

public StorableBuddyList getBuddyList(java.lang.String name)

saveBuddyList

public boolean saveBuddyList(java.lang.String userName)
Save the buddy list of a specific user.
This method should not be called as SmartFoxServer already takes care of calling it when needed.

Parameters:
userName - the user name
Returns:
true if the operation was successful

removeBuddyList

public void removeBuddyList(java.lang.String owner)
Remove a buddy list

Parameters:
owner - the owner name

saveAndRemove

public void saveAndRemove(java.lang.String owner)
Save a buddy list item and removes it

Parameters:
owner - the owner name

saveAllBuddyLists

public void saveAllBuddyLists()
Saves all buddy lists in memory.
This method should not be called as SmartFoxServer already takes care of calling it when needed.


loadBuddyList

public it.gotoandplay.smartfoxserver.data.buddylist.LoadableBuddyList loadBuddyList(java.lang.String userName)
Load a buddy list

Parameters:
userName - the name of the user
Returns:
the list of buddies for the specified user

setBuddyVariables

public java.util.List<java.lang.String> setBuddyVariables(User user,
                                                          java.util.Map<java.lang.String,java.lang.String> variables)
Set one or more buddy variables

Parameters:
user - the variable owner
variables - a map of variables (key, value)
Returns:
a list of variables that were changed

getClientsToUpdate

public java.util.LinkedList getClientsToUpdate(java.lang.String buddyName)

clearExpiredPermissionRequests

public void clearExpiredPermissionRequests()

clearBuddyList

public void clearBuddyList(java.lang.String owner)
Clear the buddy list of the specified user

Parameters:
owner - name of the user whose buddy list should be cleared.

getMaxBuddyVars

public int getMaxBuddyVars()
Get the max amount of buddy variables allowed

Returns:
the max number of buddy variables

setMaxBuddyVars

public void setMaxBuddyVars(int maxBuddyVars)
Set the max amount of buddy variables allowed

Parameters:
maxBuddyVars - the max number of buddy variables
Since:
1.6.9

getMaxBuddyVarLen

public int getMaxBuddyVarLen()
Get the max length of a buddy variable, expressed in number of characters.

Returns:
the max length of a buddy variable
Since:
1.6.9

setMaxBuddyVarsLen

public void setMaxBuddyVarsLen(int value)
Set the max length of a buddy variable, expressed in number of characters.

Parameters:
value - the max length of a buddy variable, expressed in number of characters.

isBuddyOnline

public boolean isBuddyOnline(java.lang.String userName)
Return the current online status of a buddy / user

Parameters:
userName - the name of the buddy
Returns:
true if the user is online

getBuddyVariables

public java.util.Map<java.lang.String,java.lang.String> getBuddyVariables(java.lang.String buddyName)
Return the variables map of a buddy

Parameters:
buddyName - name of the buddy
Returns:
the buddy variables
Since:
1.6.0

getBuddyVariables

public java.util.Map<java.lang.String,java.lang.String> getBuddyVariables(it.gotoandplay.smartfoxserver.data.buddylist.LoadableBuddyItem buddy)
Return the variables map of a buddy

Parameters:
buddy - the buddy
Returns:
the buddy variables
Since:
1.6.0

setBuddyVariables

public void setBuddyVariables(java.lang.String ownerName,
                              java.util.Map<java.lang.String,java.lang.String> variables)
Set the buddyVariables of User

Parameters:
ownerName - name of the user
variables - a map of variables
Since:
1.6.0

getOfflineBuddyVariables

public java.util.Map<java.lang.String,java.lang.String> getOfflineBuddyVariables(java.lang.String ownerName)
Parameters:
ownerName -
Returns:
a map of off-line buddy variables

sendBuddyListUpdate

public void sendBuddyListUpdate(User user)
Send an update about the specified User to all clients that have him/her in their buddy list

Parameters:
user - A User
Since:
1.6.0

getUseOfflineVariables

public boolean getUseOfflineVariables()

setUseOfflineVariables

public void setUseOfflineVariables(boolean useOfflineVariables)

getSecurityMode

public int getSecurityMode()

setSecurityMode

public void setSecurityMode(int securityMode)

isAdvancedMode

public boolean isAdvancedMode()

getPermissionRequests

public java.util.Map<it.gotoandplay.smartfoxserver.data.buddylist.PermissionRequestKey,it.gotoandplay.smartfoxserver.data.buddylist.PermissionRequest> getPermissionRequests()

isMutualAddBuddy

public boolean isMutualAddBuddy()

setMutualAddBuddy

public void setMutualAddBuddy(boolean mutualAddBuddy)

isMutualRemoveBuddy

public boolean isMutualRemoveBuddy()

setMutualRemoveBuddy

public void setMutualRemoveBuddy(boolean mutualRemoveBuddy)

getBuddyPermissionTimeout

public int getBuddyPermissionTimeout()

setBuddyPermissionTimeout

public void setBuddyPermissionTimeout(int buddyPermissionTimeout)

setAddBuddyPermission

public void setAddBuddyPermission(boolean addBuddyPermission)

isAddBuddyPermission

public boolean isAddBuddyPermission()

setBuddyBlockStatus

public void setBuddyBlockStatus(User owner,
                                java.lang.String buddyName,
                                boolean status)
Set buddy block status

Parameters:
owner - the owner of the buddy list
buddyName - the name of the buddy
status - the block status (true = blocked, false = unblocked)

validateRecipient

public boolean validateRecipient(User sender,
                                 User recipient)
Check a sender/receiver pair for a private message from BuddyList

Parameters:
sender - the sender
recipient - the receiver
Returns:
a flag, true if users haven't blocked each other

checkValidAddRequest

public void checkValidAddRequest(User sender,
                                 java.lang.String target)
                          throws it.gotoandplay.smartfoxserver.exceptions.BuddyListException
Throws:
it.gotoandplay.smartfoxserver.exceptions.BuddyListException

checkBuddyListSize

public boolean checkBuddyListSize(java.lang.String name)

addPermissionRequest

public void addPermissionRequest(java.lang.String sender,
                                 java.lang.String target)
Manages the addition of a permissione request in the local cache.

Parameters:
sender - the sender user name
target - the target user name

setPermissionStatus

public boolean setPermissionStatus(java.lang.String sender,
                                   java.lang.String target,
                                   it.gotoandplay.smartfoxserver.data.buddylist.PermissionStatus status)
Set the status of the permission request

Parameters:
sender - the sender name
target - the target name
status - the status of the request
Returns:
true if request was granted

getOwnerListFullErrorMessage

public java.lang.String getOwnerListFullErrorMessage()
Get the "Owner Buddy List Full" custom error message

Returns:
the error message

setOwnerListFullErrorMessage

public void setOwnerListFullErrorMessage(java.lang.String message)
Set a custom message for the "Owner Buddy List Full" error.

Parameters:
message - the error message

getTargetListFullErrorMessage

public java.lang.String getTargetListFullErrorMessage()
Get the "Target Buddy List Full" custom error message

Returns:
the error message

setTargetListFullErrorMessage

public void setTargetListFullErrorMessage(java.lang.String message)
Set a custom message for the "Target Buddy List Full" error.

Parameters:
message - the error message

getBuddyLists

public java.util.Map<java.lang.String,StorableBuddyList> getBuddyLists()

getVarCache

public java.util.Map<java.lang.String,java.util.Map<java.lang.String,java.lang.String>> getVarCache()

getPendingRequests

public java.util.Map<it.gotoandplay.smartfoxserver.data.buddylist.PermissionRequestKey,it.gotoandplay.smartfoxserver.data.buddylist.PermissionRequest> getPendingRequests()