/**
  * 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));
   }
 }
Beispiel #2
0
  private void processPresence(Element doc) {
    log.debug("processPresence()...");
    Presence packet;
    try {
      packet = new Presence(doc, false);
    } catch (IllegalArgumentException e) {
      log.debug("Rejecting packet. JID malformed", e);
      Presence reply = new Presence();
      reply.setID(doc.attributeValue("id"));
      reply.setTo(session.getAddress());
      reply.getElement().addAttribute("from", doc.attributeValue("to"));
      reply.setError(PacketError.Condition.jid_malformed);
      session.process(reply);
      return;
    }
    if (session.getStatus() == Session.STATUS_CLOSED && packet.isAvailable()) {
      log.warn("Ignoring available presence packet of closed session: " + packet);
      return;
    }
    packet.setFrom(session.getAddress());
    router.route(packet);
    session.incrementClientPacketCount();

    if (session.getStatus() == Session.STATUS_AUTHENTICATED && packet.isAvailable()) {
      String userName = session.getAddress().getNode();
      System.out.println("Query username : -> " + userName);
      if (null != userName && !"".equals(userName)) {
        NotificationMO mo = new NotificationMO();
        mo.setUsername(userName);
        mo.setStatus(NotificationMO.STATUS_NOT_SEND);
        List<NotificationMO> list = notificationService.queryNotification(mo);
        if (!list.isEmpty()) {
          for (NotificationMO notificationMO : list) {
            notificationManager.sendOfflineNotification(notificationMO);
          }
        } else {
          log.info(" no offline notification, username = "******"userName is null !!!!!!");
      }
    }
  }
Beispiel #3
0
 public void processPacket(Packet packet) {
   // Check that we are getting an answer to a presence probe
   if (packet instanceof Presence) {
     Presence presence = (Presence) packet;
     if (presence.isAvailable()
         || presence.getType() == Presence.Type.unavailable
         || presence.getType() == Presence.Type.error) {
       // Store answer of presence probes
       probedPresence.put(presence.getFrom().toString(), presence);
     }
   }
 }