/**
  * Set the presence of this session
  *
  * @param presence The presence for the session
  */
 public void setPresence(Presence presence) {
   Presence oldPresence = this.presence;
   this.presence = presence;
   if (oldPresence.isAvailable() && !this.presence.isAvailable()) {
     // The client is no longer available
     sessionManager.sessionUnavailable(this);
     // Mark that the session is no longer initialized. This means that if the user sends
     // an available presence again the session will be initialized again thus receiving
     // offline messages and offline presence subscription requests
     setInitialized(false);
     // Notify listeners that the session is no longer available
     PresenceEventDispatcher.unavailableSession(this, presence);
   } else if (!oldPresence.isAvailable() && this.presence.isAvailable()) {
     // The client is available
     sessionManager.sessionAvailable(this, presence);
     wasAvailable = true;
     // Notify listeners that the session is now available
     PresenceEventDispatcher.availableSession(this, presence);
   } else if (this.presence.isAvailable()
       && oldPresence.getPriority() != this.presence.getPriority()) {
     // The client has changed the priority of his presence
     sessionManager.changePriority(this, oldPresence.getPriority());
     // Notify listeners that the priority of the session/resource has changed
     PresenceEventDispatcher.presenceChanged(this, presence);
   } else if (this.presence.isAvailable()) {
     // Notify listeners that the show or status value of the presence has changed
     PresenceEventDispatcher.presenceChanged(this, presence);
   }
   if (ClusterManager.isClusteringStarted()) {
     // Track information about the session and share it with other cluster nodes
     Cache<String, ClientSessionInfo> cache = SessionManager.getInstance().getSessionInfoCache();
     cache.put(getAddress().toString(), new ClientSessionInfo(this));
   }
 }
 /**
  * Sets if the user requested to not receive offline messages when sending an available presence.
  * The user may send a disco request with node "http://jabber.org/protocol/offline" so that no
  * offline messages are sent to the user when he becomes online. If the user is connected from
  * many resources then if one of the sessions stopped the flooding then no session should flood
  * the user.
  *
  * @param offlineFloodStopped if the user requested to not receive offline messages when sending
  *     an available presence.
  */
 public void setOfflineFloodStopped(boolean offlineFloodStopped) {
   this.offlineFloodStopped = offlineFloodStopped;
   if (ClusterManager.isClusteringStarted()) {
     // Track information about the session and share it with other cluster nodes
     Cache<String, ClientSessionInfo> cache = SessionManager.getInstance().getSessionInfoCache();
     cache.put(getAddress().toString(), new ClientSessionInfo(this));
   }
 }
 /**
  * Sets the Privacy list that overrides the default privacy list. This list affects only this
  * session and only for the duration of the session.
  *
  * @param activeList the Privacy list that overrides the default privacy list.
  */
 public void setActiveList(PrivacyList activeList) {
   this.activeList = activeList != null ? activeList.getName() : null;
   if (ClusterManager.isClusteringStarted()) {
     // Track information about the session and share it with other cluster nodes
     Cache<String, ClientSessionInfo> cache = SessionManager.getInstance().getSessionInfoCache();
     cache.put(getAddress().toString(), new ClientSessionInfo(this));
   }
 }
 /**
  * Sets the default Privacy list used for the session's user. This list is processed if there is
  * no active list set for the session.
  *
  * @param defaultList the default Privacy list used for the session's user.
  */
 public void setDefaultList(PrivacyList defaultList) {
   // Do nothing if nothing has changed
   if ((this.defaultList == null && defaultList == null)
       || (defaultList != null && defaultList.getName().equals(this.defaultList))) {
     return;
   }
   this.defaultList = defaultList != null ? defaultList.getName() : null;
   if (ClusterManager.isClusteringStarted()) {
     // Track information about the session and share it with other cluster nodes
     Cache<String, ClientSessionInfo> cache = SessionManager.getInstance().getSessionInfoCache();
     cache.put(getAddress().toString(), new ClientSessionInfo(this));
   }
 }
Esempio n. 5
0
 /**
  * Executes the requested task considering that this JVM may still be joining the cluster. This
  * means that events regarding rooms that were not loaded yet will be stored for later processing.
  * Once the JVM is done joining the cluster queued tasks will be processed.
  *
  * @param runnable the task to execute.
  */
 protected void execute(Runnable runnable) {
   // Check if we are joining a cluster
   boolean clusterStarting = ClusterManager.isClusteringStarting();
   try {
     // Check that the room exists
     getRoom();
     // Room was found so now execute the task
     runnable.run();
   } catch (IllegalArgumentException e) {
     // Room not found so check if we are still joining the cluster
     if (clusterStarting) {
       // Queue task in case the cluster
       QueuedTasksManager.getInstance().addTask(this);
     } else {
       // Task failed since room was not found
       Log.error(e.getMessage(), e);
     }
   }
 }