use of org.jivesoftware.openfire.spi.ClientRoute 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.spi.ClientRoute in project Openfire by igniterealtime.
the class ConsistencyChecks method generateReportForUserSessions.
public static Multimap<String, String> generateReportForUserSessions(@Nonnull final Cache<String, HashSet<String>> usersSessionsCache, @Nonnull final Cache<String, ClientRoute> usersCache, @Nonnull final Cache<String, ClientRoute> anonymousUsersCache) {
final Set<NodeID> clusterNodeIDs = ClusterManager.getNodesInfo().stream().map(ClusterNodeInfo::getNodeID).collect(Collectors.toSet());
// Take snapshots of all data structures at as much the same time as possible.
final ConcurrentMap<String, HashSet<String>> cache = new ConcurrentHashMap<>(usersSessionsCache);
final Set<String> usersCacheKeys = usersCache.keySet();
final Set<String> anonymousUsersCacheKeys = anonymousUsersCache.keySet();
final Set<String> userCacheKeysNotInSessionsCache = usersCacheKeys.stream().filter(fullJid -> {
HashSet<String> fullJids = cache.get(new JID(fullJid).toBareJID());
return fullJids == null || !fullJids.contains(fullJid);
}).collect(Collectors.toSet());
final Set<String> anonymousUserCacheKeysNotInSessionsCache = anonymousUsersCacheKeys.stream().filter(fullJid -> {
HashSet<String> fullJids = cache.get(new JID(fullJid).toBareJID());
return fullJids == null || !fullJids.contains(fullJid);
}).collect(Collectors.toSet());
final Set<String> sessionCacheItemsNotInUserCaches = cache.values().stream().flatMap(HashSet::stream).filter(fullJid -> !usersCacheKeys.contains(fullJid) && !anonymousUsersCacheKeys.contains(fullJid)).collect(Collectors.toSet());
final Set<String> duplicatesBetweenAnonAndNonAnonUsers = CollectionUtils.findDuplicates(usersCacheKeys, anonymousUsersCacheKeys);
// Generate report
final Multimap<String, String> result = HashMultimap.create();
result.put("info", String.format("The cache named %s is used to share data in the cluster, which contains %d session infos.", usersSessionsCache.getName(), cache.size()));
result.put("data", String.format("%s contains these entries (these are shared in the cluster):\n%s", usersSessionsCache.getName(), cache.entrySet().stream().map(e -> e.getKey() + " -> " + e.getValue()).sorted().collect(Collectors.joining("\n"))));
result.put("data", String.format("%s contains these entries (these are shared in the cluster):\n%s", usersCache.getName(), usersCacheKeys.stream().sorted().collect(Collectors.joining("\n"))));
result.put("data", String.format("%s contains these entries (these are shared in the cluster):\n%s", anonymousUsersCache.getName(), anonymousUsersCacheKeys.stream().sorted().collect(Collectors.joining("\n"))));
if (userCacheKeysNotInSessionsCache.isEmpty()) {
result.put("pass", "All user cache entries exist in the user sessions cache.");
} else {
result.put("fail", String.format("User sessions cache is missing entries that are present in the user cache. These %d entries are missing: %s", userCacheKeysNotInSessionsCache.size(), String.join(", ", userCacheKeysNotInSessionsCache)));
}
if (anonymousUserCacheKeysNotInSessionsCache.isEmpty()) {
result.put("pass", "All anonymous user cache entries exist in the user sessions cache.");
} else {
result.put("fail", String.format("User sessions cache is missing entries that are present in the anonymous user cache. These %d entries are missing: %s", anonymousUserCacheKeysNotInSessionsCache.size(), String.join(", ", anonymousUserCacheKeysNotInSessionsCache)));
}
if (sessionCacheItemsNotInUserCaches.isEmpty()) {
result.put("pass", "All user sessions cache entries exist in either the user cache or the anonymous user cache.");
} else {
result.put("fail", String.format("User cache and/or anonymous user cache is missing entries that are present in the user sessions cache. These %d entries are missing: %s", sessionCacheItemsNotInUserCaches.size(), String.join(", ", sessionCacheItemsNotInUserCaches)));
}
if (duplicatesBetweenAnonAndNonAnonUsers.isEmpty()) {
result.put("pass", "There are no duplicates between non-anonymous users cache and anonymous users cache.");
} else {
result.put("fail", String.format("There are users both present in non-anonymous users cache and anonymous users cache. These %d entries are duplicates: %s", duplicatesBetweenAnonAndNonAnonUsers.size(), String.join(", ", duplicatesBetweenAnonAndNonAnonUsers)));
}
return result;
}
use of org.jivesoftware.openfire.spi.ClientRoute in project Openfire by igniterealtime.
the class ClientSessionTask method run.
public void run() {
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();
Log.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.spi.ClientRoute 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());
byte[] nodeIDByte = route != null ? route.getNodeID().toByteArray() : new byte[0];
logger.warn("Found remote session instead of local session. JID: {} found in Node: {} and local node is: {}", address, nodeIDByte, XMPPServer.getInstance().getNodeID().toByteArray());
}
if (operation == Operation.isInitialized) {
if (session instanceof RemoteClientSession) {
// Something is wrong since the session should 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 should be local instead of remote
// Assume some default value
result = 2;
} else {
result = session.incrementConflictCount();
}
} else if (operation == Operation.hasRequestedBlocklist) {
if (session instanceof RemoteClientSession) {
// Something is wrong since the session should be local instead of remote
// Assume some default value
result = false;
} else {
result = session.hasRequestedBlocklist();
}
}
}
Aggregations