use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.
the class Roster method broadcastPresence.
/**
* <p>Broadcast the presence update to all subscribers of the roter.</p>
* <p>Any presence change typically results in a broadcast to the roster members.</p>
*
* @param packet The presence packet to broadcast
*/
public void broadcastPresence(Presence packet) {
if (routingTable == null) {
return;
}
// Get the privacy list of this user
PrivacyList list = null;
JID from = packet.getFrom();
if (from != null) {
// Try to use the active list of the session. If none was found then try to use
// the default privacy list of the session
ClientSession session = sessionManager.getSession(from);
if (session != null) {
list = session.getActiveList();
list = list == null ? session.getDefaultList() : list;
}
}
if (list == null) {
// No privacy list was found (based on the session) so check if there is a default list
list = PrivacyListManager.getInstance().getDefaultPrivacyList(username);
}
// Broadcast presence to subscribed entities
for (RosterItem item : rosterItems.values()) {
if (item.getSubStatus() == RosterItem.SUB_BOTH || item.getSubStatus() == RosterItem.SUB_FROM) {
packet.setTo(item.getJid());
if (list != null && list.shouldBlockPacket(packet)) {
// Outgoing presence notifications are blocked for this contact
continue;
}
JID searchNode = new JID(item.getJid().getNode(), item.getJid().getDomain(), null, true);
for (JID jid : routingTable.getRoutes(searchNode, null)) {
try {
routingTable.routePacket(jid, packet, false);
} catch (Exception e) {
// Theoretically only happens if session has been closed.
Log.debug(e.getMessage(), e);
}
}
}
}
// Broadcast presence to shared contacts whose subscription status is FROM
for (String contact : implicitFrom.keySet()) {
if (contact.contains("@")) {
String node = contact.substring(0, contact.lastIndexOf("@"));
String domain = contact.substring(contact.lastIndexOf("@") + 1);
node = JID.escapeNode(node);
contact = new JID(node, domain, null).toBareJID();
}
packet.setTo(contact);
if (list != null && list.shouldBlockPacket(packet)) {
// Outgoing presence notifications are blocked for this contact
continue;
}
for (JID jid : routingTable.getRoutes(new JID(contact), null)) {
try {
routingTable.routePacket(jid, packet, false);
} catch (Exception e) {
// Theoretically only happens if session has been closed.
Log.debug(e.getMessage(), e);
}
}
}
if (from != null) {
// Broadcast presence to other user's resources
sessionManager.broadcastPresenceToOtherResources(from, packet);
}
}
use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.
the class PresenceManagerImpl method getPresence.
@Override
public Presence getPresence(User user) {
if (user == null) {
return null;
}
Presence presence = null;
for (ClientSession session : sessionManager.getSessions(user.getUsername())) {
if (presence == null) {
presence = session.getPresence();
} else {
// Get the ordinals of the presences to compare. If no ordinal is available then
// assume a value of -1
int o1 = presence.getShow() != null ? presence.getShow().ordinal() : -1;
int o2 = session.getPresence().getShow() != null ? session.getPresence().getShow().ordinal() : -1;
// Compare the presences' show ordinals
if (o1 > o2) {
presence = session.getPresence();
}
}
}
return presence;
}
use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.
the class BaseTransport method start.
/**
* Handles startup of the transport.
*/
public void start() {
RosterEventDispatcher.addListener(this);
UserEventDispatcher.addListener(this);
SessionEventDispatcher.addListener(this);
VCardEventDispatcher.addListener(this);
InterceptorManager.getInstance().addInterceptor(this);
if (!JiveGlobals.getBooleanProperty("plugin.gateway.tweak.noprobeonstart", false)) {
// TODO: Do we need to account for local vs other node sessions?
for (ClientSession session : SessionManager.getInstance().getSessions()) {
try {
JID jid = XMPPServer.getInstance().createJID(session.getUsername(), null);
if (RegistrationManager.getInstance().isRegistered(jid, getType())) {
Presence p = new Presence(Presence.Type.probe);
p.setFrom(this.getJID());
p.setTo(jid);
sendPacket(p);
}
} catch (UserNotFoundException e) {
// Not a valid user for the gateway then
}
}
}
}
use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.
the class ClientSessionTask method run.
public void run() {
if (getSession() == null || getSession().isClosed()) {
logger.error("Session not found for JID: " + address);
return;
}
super.run();
ClientSession session = (ClientSession) getSession();
if (session instanceof RemoteClientSession) {
// The session is being hosted by other cluster node so log this unexpected case
Cache<String, ClientRoute> usersCache = CacheFactory.createCache(RoutingTableImpl.C2S_CACHE_NAME);
ClientRoute route = usersCache.get(address.toString());
NodeID nodeID = route.getNodeID();
logger.warn("Found remote session instead of local session. JID: " + address + " found in Node: " + nodeID.toByteArray() + " and local node is: " + XMPPServer.getInstance().getNodeID().toByteArray());
}
if (operation == Operation.isInitialized) {
if (session instanceof RemoteClientSession) {
// Something is wrong since the session shoud be local instead of remote
// Assume some default value
result = true;
} else {
result = session.isInitialized();
}
} else if (operation == Operation.incrementConflictCount) {
if (session instanceof RemoteClientSession) {
// Something is wrong since the session shoud be local instead of remote
// Assume some default value
result = 2;
} else {
result = session.incrementConflictCount();
}
}
}
use of org.jivesoftware.openfire.session.ClientSession in project Openfire by igniterealtime.
the class RemoteSession method doSynchronousClusterTask.
/**
* Invokes a task on the remote cluster member synchronously and returns the result of
* the remote operation.
*
* @param task the ClusterTask object to be invoked on a given cluster member.
* @return result of remote operation.
*/
protected Object doSynchronousClusterTask(ClusterTask task) {
ClusterNodeInfo info = CacheFactory.getClusterNodeInfo(nodeID);
Object result = null;
if (info == null && task instanceof RemoteSessionTask) {
// clean up invalid session
Session remoteSession = ((RemoteSessionTask) task).getSession();
if (remoteSession instanceof ClientSession) {
SessionManager.getInstance().removeSession(null, remoteSession.getAddress(), false, false);
}
} else {
result = (info == null) ? null : CacheFactory.doSynchronousClusterTask(task, nodeID);
}
return result;
}
Aggregations