Search in sources :

Example 56 with Presence

use of org.xmpp.packet.Presence in project Openfire by igniterealtime.

the class ClusterListener method cleanupPresences.

/**
     * Simulate an unavailable presence for sessions that were being hosted in other
     * cluster nodes. This method should be used ONLY when this JVM left the cluster.
     *
     * @param key the key that identifies the node that is no longer available.
     */
private void cleanupPresences(NodeID key) {
    Set<String> registeredUsers = lookupJIDList(key, C2SCache.getName());
    if (!registeredUsers.isEmpty()) {
        for (String fullJID : new ArrayList<String>(registeredUsers)) {
            JID offlineJID = new JID(fullJID);
            try {
                Presence presence = new Presence(Presence.Type.unavailable);
                presence.setFrom(offlineJID);
                XMPPServer.getInstance().getPresenceRouter().route(presence);
            } catch (PacketException e) {
                logger.error("Failed to cleanup user presence", e);
            }
        }
    }
    Set<String> anonymousUsers = lookupJIDList(key, anonymousC2SCache.getName());
    if (!anonymousUsers.isEmpty()) {
        for (String fullJID : new ArrayList<String>(anonymousUsers)) {
            JID offlineJID = new JID(fullJID);
            try {
                Presence presence = new Presence(Presence.Type.unavailable);
                presence.setFrom(offlineJID);
                XMPPServer.getInstance().getPresenceRouter().route(presence);
            } catch (PacketException e) {
                logger.error("Failed to cleanp anonymous presence", e);
            }
        }
    }
    nodeSessions.remove(key);
}
Also used : JID(org.xmpp.packet.JID) ArrayList(java.util.ArrayList) Presence(org.xmpp.packet.Presence) DirectedPresence(org.jivesoftware.openfire.handler.DirectedPresence)

Example 57 with Presence

use of org.xmpp.packet.Presence in project Openfire by igniterealtime.

the class RemoteClientSession method isInitialized.

public boolean isInitialized() {
    if (initialized == -1) {
        Presence presence = getPresence();
        if (presence != null && presence.isAvailable()) {
            // Optimization to avoid making a remote call
            initialized = 1;
        } else {
            ClusterTask task = getRemoteSessionTask(RemoteSessionTask.Operation.isInitialized);
            Object result = doSynchronousClusterTask(task);
            initialized = result != null && (Boolean) result ? 1 : 0;
        }
    }
    return initialized == 1;
}
Also used : ClusterTask(org.jivesoftware.util.cache.ClusterTask) Presence(org.xmpp.packet.Presence)

Example 58 with Presence

use of org.xmpp.packet.Presence in project Openfire by igniterealtime.

the class RemoteClientSession method getPresence.

public Presence getPresence() {
    Cache<String, ClientSessionInfo> cache = SessionManager.getInstance().getSessionInfoCache();
    ClientSessionInfo sessionInfo = cache.get(getAddress().toString());
    if (sessionInfo != null) {
        return sessionInfo.getPresence();
    }
    // this can happen if a cluster node becomes unreachable
    return new Presence(Presence.Type.unavailable);
}
Also used : Presence(org.xmpp.packet.Presence) ClientSessionInfo(org.jivesoftware.openfire.session.ClientSessionInfo)

Example 59 with Presence

use of org.xmpp.packet.Presence in project Openfire by igniterealtime.

the class MUCRoomController method deleteAffiliation.

/**
	 * Delete affiliation.
	 *
	 * @param serviceName
	 *            the service name
	 * @param roomName
	 *            the room name
	 * @param jid
	 *            the jid
	 * @throws ServiceException
	 *             the service exception
	 */
public void deleteAffiliation(String serviceName, String roomName, String jid) throws ServiceException {
    MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(serviceName).getChatRoom(roomName.toLowerCase());
    try {
        JID userJid = UserUtils.checkAndGetJID(jid);
        // Send a presence to other room members
        List<Presence> addNonePresence = room.addNone(userJid, room.getRole());
        for (Presence presence : addNonePresence) {
            room.send(presence);
        }
    } catch (ForbiddenException e) {
        throw new ServiceException("Could not delete affiliation", jid, ExceptionType.NOT_ALLOWED, Response.Status.FORBIDDEN, e);
    } catch (ConflictException e) {
        throw new ServiceException("Could not delete affiliation", jid, ExceptionType.NOT_ALLOWED, Response.Status.CONFLICT, e);
    }
}
Also used : ForbiddenException(org.jivesoftware.openfire.muc.ForbiddenException) LocalMUCRoom(org.jivesoftware.openfire.muc.spi.LocalMUCRoom) MUCRoom(org.jivesoftware.openfire.muc.MUCRoom) JID(org.xmpp.packet.JID) ServiceException(org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException) ConflictException(org.jivesoftware.openfire.muc.ConflictException) Presence(org.xmpp.packet.Presence)

Example 60 with Presence

use of org.xmpp.packet.Presence in project Openfire by igniterealtime.

the class PresenceUpdateHandler method createSubscribePresence.

public Presence createSubscribePresence(JID senderAddress, JID targetJID, boolean isSubscribe) {
    Presence presence = new Presence();
    presence.setFrom(senderAddress);
    presence.setTo(targetJID);
    if (isSubscribe) {
        presence.setType(Presence.Type.subscribe);
    } else {
        presence.setType(Presence.Type.unsubscribe);
    }
    return presence;
}
Also used : Presence(org.xmpp.packet.Presence)

Aggregations

Presence (org.xmpp.packet.Presence)109 JID (org.xmpp.packet.JID)38 Element (org.dom4j.Element)34 UserNotFoundException (org.jivesoftware.openfire.user.UserNotFoundException)20 Message (org.xmpp.packet.Message)17 IQ (org.xmpp.packet.IQ)16 UpdatePresence (org.jivesoftware.openfire.muc.cluster.UpdatePresence)14 NotFoundException (org.jivesoftware.util.NotFoundException)12 ArrayList (java.util.ArrayList)11 MUCRole (org.jivesoftware.openfire.muc.MUCRole)10 GroupNotFoundException (org.jivesoftware.openfire.group.GroupNotFoundException)9 DefaultElement (org.dom4j.tree.DefaultElement)8 IOException (java.io.IOException)7 SQLException (java.sql.SQLException)7 GroupJID (org.jivesoftware.openfire.group.GroupJID)7 NotAllowedException (org.jivesoftware.openfire.muc.NotAllowedException)7 Date (java.util.Date)6 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)6 ConflictException (org.jivesoftware.openfire.muc.ConflictException)6 ForbiddenException (org.jivesoftware.openfire.muc.ForbiddenException)6