ClusterStateService.java revision 56ed5bbb263838f338eb8afc978091c01a4f2a2b
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: ClusterStateService.java,v 1.3 2008/06/25 05:41:30 qcheng Exp $
*
*/
/*
* Portions Copyrighted 2010-2011 ForgeRock AS
*/
/**
* A <code>ClusterStateService </code> class implements monitoring the state of
* server instances that are participating in the cluster environment. It is
* used in making routing decisions in "internal request routing" mode
*/
public class ClusterStateService extends GeneralTaskRunnable {
// Inner Class definition of ServerInfo Object.
// Contains information about each Server.
private class ServerInfo implements Comparable {
boolean isUp;
boolean isLocal;
}
/**
* toString Override.
* @return String representation of this Inner Object Class.
*/
else
{
}
}
} //. End of Inner Class Definition.
/**
* Service Globals
*/
/**
* Servers in the cluster environment
*/
/**
* Servers are down in the cluster environment
*/
/**
* Server Information
*/
/**
* Last selected Server
*/
private static int lastSelected = -1;
/**
* individual server wait default time out 10 milliseconds
*/
public static final int DEFAULT_TIMEOUT = 1000;
private static boolean doRequest = true;
/**
* default ServerInfo check time 10 milliseconds
*/
public static final long DEFAULT_PERIOD = 1000;
// server instance id
// SessionService
// Static Initialization Stanza.
static {
if (doRequestFlag != null) {
doRequest = false;
}
}
}
} // End of Static Initialization Stanza
/**
* Get Servers within Cluster
* @return Map<String, ServerInfo>
*/
return servers;
}
/**
* Get Server IDs which are in a Down State.
* @return Set<String>
*/
return downServers;
}
/**
* Get the Server Selection List, common to all Servers
* in Cluster.
* @return ServerInfo[] Array of Servers in Selection list in
* proper order.
*/
protected ServerInfo[] getServerSelectionList() {
return serverSelectionList;
}
/**
* Get our Local Server Id
* @return String of Local Server Id.
*/
protected String getLocalServerId() {
return localServerId;
}
/**
* Is Specified ServerId our Local Server Id?
* @param serverId
* @return boolean indicating true if specified server id is our local Server Id or false ir not.
*/
}
/**
* Constructs an instance for the cluster service
* @param localServerId id of the server instance in which this
* ClusterStateService instance is running
* @param timeout timeout for waiting on an individual server (millisec)
* @param period checking cycle period (millisecs)
* @param members map if server id - > url for all cluster members
* @throws Exception
*/
{
String message = "ClusterStateService: Local Server Id argument is null, unable to instantiate Cluster State Service!";
throw new IllegalArgumentException(message);
}
// Ensure we Synchronize this Instantiation.
synchronized (this) {
this.sessionService = sessionService;
this.localServerId = localServerId;
// Fix for Deadlock. If this is our server, set to true, else false.
// Check for Down Servers.
}
// Add Server to Server List.
// Associate to a Server Selection Bucket.
if (sessionDebug.messageEnabled())
} // End of For Loop.
// to ensure that ordering in different server instances is identical
} // End of Synchronized Block.
}
/**
* Implements "wrap-around" lastSelected index advancement
*
* @return updated lastSelected index value
*/
private int getNextSelected() {
}
/**
* Returns currently known status of the server instance identified by
* serverId
*
* @param serverId server instance id
* @return true if server is up, false otherwise
*/
return false;
}
return true;
}
{ return false; }
}
/**
* Actively checks and updates the status of the server instance identified
* by serverId
*
* @param serverId server instance id
* @return true if server is up, false otherwise
*/
return false;
}
return true;
}
{ return false; }
}
/**
* Returns size of the server list
*
* @return size of the server list
*/
int getServerSelectionListSize() {
}
/**
* Returns server id for a given index inside the server list
* or null if out of bounds.
* @param index index in the server list, relative to Zero.
* @return server id
*/
if ( (getServerSelectionListSize() <= 0) || (index < 0) || (index >= getServerSelectionListSize()) ) {
return null;
}
}
/**
* Implements for GeneralTaskRunnable
*
* @return The run period of the task.
*/
public long getRunPeriod() {
return period;
}
/**
* Implements for GeneralTaskRunnable.
*
* @return false since this class will not be used as container.
*/
return false;
}
/**
* Implements for GeneralTaskRunnable.
*
* @return false since this class will not be used as container.
*/
return false;
}
/**
* Implements for GeneralTaskRunnable.
*
* @return true since this class will not be used as container.
*/
public boolean isEmpty() {
return true;
}
/**
* Monitoring logic used by background thread
*/
public void run() {
try {
boolean cleanRemoteSessions = false;
synchronized (servers) {
} else {
if (!downServers.isEmpty() &&
cleanRemoteSessions = true;
}
}
}
}
if (cleanRemoteSessions) {
}
sessionDebug.error("cleanRemoteSessions Background thread has encountered an Exception: " + ex.getMessage(), ex);
}
}
/**
* Internal method for checking health status using sock.connect()
* <p/>
* TODO -- Use a better mechanism for alive status. 10.1+.
*
* @param info server info instance
* @return true if server is up, false otherwise
*/
return false;
}
return true;
}
boolean result = false;
try {
/*
* If we need to check for a front end proxy, we need
* to send a request.
*/
if (doRequest) {
result = true;
} else {
result = false;
}
} else {
int responseCode = 0;
try {
return true;
}
});
int ret = 0;
byte[] buf = new byte[512];
// clear the stream
// do nothing
}
// close the inputstream
} catch (IOException ioe) {
try {
int ret = 0;
byte[] buf = new byte[512];
// read the response body to clear
// do nothing
}
// close the errorstream
} catch (IOException ex) {
// deal with the exception
}
}
result = true;
} else {
result = false;
}
}
} else {
result = true;
}
result = false;
} finally {
try {
}
}
return result;
}
// TODO -- Develop Method to write our Server State to the Session Persistence Store.
/**
* Override toString
*
* @return
*/
}
}
}