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);
}
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;
}
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);
}
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);
}
}
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;
}
Aggregations