Class SetBuddyVariablesRequest

  • All Implemented Interfaces:
    sfs2x.client.requests.IRequest

    public class SetBuddyVariablesRequest
    extends BaseRequest
    Sets one or more Buddy Variables for the current user.

    This operation updates the Buddy object representing the user in all the buddies lists in which the user was added as a buddy. If the operation is successful, a buddyVariablesUpdate event is dispatched to all the owners of those buddies lists and to the user who updated his variables too.

    NOTE: this request can be sent if the Buddy List system was previously initialized only (see the InitBuddyListRequest request description) and the current user state in the system is "online".

    Example
    The following example sets some Buddy Variables for the current user, one of which is persistent; the example also handles changes made by the user or by his buddies:

     private void someMethod() {
         sfs.addEventListener(SFSBuddyEvent.BUDDY_VARIABLES_UPDATE, new IEventListener() {
             public void dispatch(BaseEvent evt) throws SFSException {
                 // As the update event is dispatched to me too,
                 // I have to check if I am the one who changed his Buddy Variables
                 boolean isItMe = (Boolean) evt.getArguments().get("isItMe");
                 
                 if (isItMe) {
                     System.out.println("I've updated the following Buddy Variables:");
                     
                     for (String bVarName : (List) evt.getArguments().get("changedVars")) {
                         System.out.println(bVarName + "-->" + sfs.getBuddyManager().getMyVariable(bVarName).getValue());
                     }
                 }
                 else
                 {
                     String buddyName = ((Buddy) evt.getArguments().get("buddy")).getName();
                     System.out.println("My buddy " + buddyName + " updated the following Buddy Variables:");
                     
                     for (String bVarName : (List) evt.getArguments().get("changedVars")) {
                         System.out.println(bVarName + "-->" + sfs.getBuddyManager().getBuddyByName(buddyName).getVariable(bVarName).getValue());
                     }
                 }
             }
         });
         
         // Create two Buddy Variables containing the title and artist of the song I'm listening to
         BuddyVariable songTitle = new SFSBuddyVariable("songTitle", "Ascension");
         BuddyVariable songAuthor = new SFSBuddyVariable("songAuthor", "Mike Oldfield");
         
         // Create a persistent Buddy Variable containing my mood message
         BuddyVariable mood = new SFSBuddyVariable(SFSBuddyVariable.OFFLINE_PREFIX + "mood", "I Need SmartFoxServer 2X desperately!");
         
         // Set my Buddy Variables
         List vars = new ArrayList();
         vars.add(songTitle);
         vars.add(songAuthor);
         vars.add(mood);
         sfs.send(new SetBuddyVariablesRequest(vars));
     }
     
    See Also:
    BuddyVariable, SFSBuddyEvent.BUDDY_VARIABLES_UPDATE, InitBuddyListRequest
    • Field Detail

      • KEY_BUDDY_NAME

        public static final java.lang.String KEY_BUDDY_NAME
        * API internal usage only *
        See Also:
        Constant Field Values
      • KEY_BUDDY_VARS

        public static final java.lang.String KEY_BUDDY_VARS
        * API internal usage only *
        See Also:
        Constant Field Values
    • Constructor Detail

      • SetBuddyVariablesRequest

        public SetBuddyVariablesRequest​(java.util.List<BuddyVariable> buddyVariables)
        Creates a new SetBuddyVariablesRequest instance. The instance must be passed to the SmartFox.send() method for the request to be performed.
        Parameters:
        buddyVariables - A list of BuddyVariable objects representing the Buddy Variables to be set.
        See Also:
        SmartFox.send(sfs2x.client.requests.IRequest), BuddyVariable
    • Method Detail

      • validate

        public void validate​(ISmartFox sfs)
                      throws sfs2x.client.exceptions.SFSValidationException
        * API internal usage only *
        Throws:
        sfs2x.client.exceptions.SFSValidationException
      • execute

        public void execute​(ISmartFox sfs)
        * API internal usage only *