use of com.iplanet.dpro.session.service.PermutationGenerator in project OpenAM by OpenRock.
the class MultiServerClusterMonitor method locateCurrentHostServer.
/**
* Determines current hosting server instance for internal request routing
* mode.
*
* @param sid session id
* @return server id for the server instance determined to be the current
* host
* @throws com.iplanet.dpro.session.SessionException
*/
String locateCurrentHostServer(SessionID sid) throws SessionException {
String primaryID = sid.getExtension().getPrimaryID();
String serverID = sid.getSessionServerID();
// if this is our local Server
if (serverConfig.isLocalServer(serverID)) {
return serverID;
}
// if session is from remote site
if (!serverConfig.isPrimaryServer(serverID)) {
return serverID;
}
// Ensure we have a Cluster State Service Available.
synchronized (this) {
if (clusterStateService == null) {
try {
initializeClusterService();
} catch (Exception e) {
sessionDebug.error("Unable to Initialize the Cluster Service, please review Configuration settings.", e);
throw new SessionException(e);
}
}
}
// Check for Service Available.
if (clusterStateService.isUp(primaryID)) {
return primaryID;
} else {
int selectionListSize = clusterStateService.getServerSelectionListSize();
String sKey = sid.getExtension().getStorageKey();
if (sKey == null) {
throw new SessionException("SessionService.locateCurrentHostServer: StorageKey is null");
}
PermutationGenerator perm = new PermutationGenerator(sKey.hashCode(), selectionListSize);
String selectedServerId = null;
for (int i = 0; i < selectionListSize; ++i) {
selectedServerId = clusterStateService.getServerSelection(perm.itemAt(i));
if (selectedServerId == null) {
continue;
}
if (clusterStateService.isUp(selectedServerId)) {
break;
}
}
// selection process is guaranteed to succeed
return selectedServerId;
}
}
Aggregations