/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2006 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: URLFailoverHelper.java,v 1.5 2008/06/25 05:51:42 qcheng Exp $
*
* Portions Copyrighted 2012-2014 ForgeRock AS.
*/
/**
* The class manages URL failover
*/
implements IURLFailoverHelper
{
super(module);
}
public void initialize(
boolean probeEnabled,
boolean isPrioritized,
long timeout,
if(isLogWarningEnabled()) {
logWarning("URLFailoverHelper: Only one URL is specified, "
+ "failover will be disabled");
}
markDisabled();
}
}
}
return null;
}
if (isAvailable(url)) {
if(isLogMessageEnabled()) {
+ " is available");
}
return url;
}
}
} else {
if (isLogMessageEnabled()) {
logMessage("URLFailoverHelper: No conditional URL found for "
}
}
if(isEnabled()) {
if(isAvailable(url)) {
} else {
if(isLogWarningEnabled()) {
logWarning("URLFailoverHelper: Detected the failure of "
+ url + ", initiating failover sequence");
}
int currentIndex = getCurrentIndex();
int newIndex = currentIndex;
boolean done = false;
while( !done) {
if(isAvailable(newURL)) {
if(isLogMessageEnabled()) {
+ " is available");
}
if(newIndex != currentIndex) {
}
done = true;
} else {
if(newIndex == currentIndex) {
"URLFailoverHelper: No URL is available at"
+ " this time");
throw new AgentServerErrorException(
"No URL is available at this time");
}
}
}
}
} else {
result = getCurrentURL();
if( !this.isAvailable(result)) {
"URLFailoverHelper: No URL is available at this time");
throw new AgentServerErrorException(
"No URL is available at this time");
}
}
if(isLogMessageEnabled()) {
}
return result;
}
}
}
/**
* Method updateIndex
*
*
* @param newIndex
* @param oldIndex
*
*/
boolean indexUpdated = false;
if (!isPrioritized()) {
{
synchronized(this) {
if(oldIndex == getCurrentIndex()) {
indexUpdated = true;
}
}
}
if(isLogWarningEnabled()) {
if(indexUpdated) {
+ " to " + newURL);
}
}
}
}
boolean result = true;
if (isProbeEnabled()) {
}
return result;
}
/**
* Method setCurrentIndex
*
*
* @param index
*
*/
}
/**
* Method getURL
*
*
* @param index
*
* @return
*
*/
}
/**
* Method getCurrentURL
*
*
* @return
*
*/
return _urlList[getCurrentIndex()];
}
/**
* Method getCurrentIndex
*
*
* @return
*
*/
private int getCurrentIndex() {
return _index;
}
/**
* Method setURLList
*
*
* @param urlList
*
*/
}
this.conditionalUrls = conditionalUrls;
}
/**
* Method getMaxIndex
*
*
* @return
*
*/
private int getMaxIndex() {
}
}
private boolean isPrioritized() {
return _isPrioritized;
}
}
private boolean isProbeEnabled() {
return _probeEnabled;
}
}
private long getTimeout() {
return _timeout;
}
/**
* Method isEnabled
*
*
* @return
*
*/
private boolean isEnabled() {
return !_disabled;
}
/**
* Method markDisabled
*
*
*/
private void markDisabled() {
_disabled = true;
}
/*
* This is a Runnable class used to proble login url's availablity.
* It simulates adding a timeout value for HttpURLConnection.connect().
* Since only JDK1.5 adds URLConnection.setConnectTimeout(), we can not
* use setConnectTimeout now until Agent can use JDK1.5.
*/
private boolean isAvailable = false;
}
public boolean isAvailable () {
try {
long timeout = getTimeout();
return false;
}
} catch (InterruptedException ex) {
if(isLogWarningEnabled()) {
+ " is not available", ex);
}
return false;
}
return this.isAvailable;
}
public void run() {
try {
isAvailable = true;
} catch (IOException ex) {
if(isLogWarningEnabled()) {
+ " is not available", ex);
}
} finally {
if (connection != null) {
if (isLogMessageEnabled()) {
"URLFailoverHelper: disconnected the "
+ "connection for availability check");
}
}
}
}
}
private boolean _disabled = false;
private boolean _isPrioritized = false;
private boolean _probeEnabled = false;
}