/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
/**
* The list of endpoints are randomized the very first time.
* This happens only once( when called from the static block
* of SerialInitContextFactory class).
* Simple RoundRobin is a special case of Weighted Round Robin where the
* weight per endpoint is equal.With the dynamic reconfiguration
* implementation, the endpoints list willhave the following structure:
* - server_identifier (a stringified name for the machine)
* - weight- list of SocketInfo {type (type = CLEAR_TEXT or SSL) +
* IP address + port }
* The above structure supports multi-homed machines
* i.e. one machinehosting multiple IP addresses.
* The RoundRobinPolicy class can be the class that is also implementing
* the Listener interface for listening to events generated whenever there
* under construction.This list of endpoints will have to be created during
* bootstrapping(i.e. when the client first starts up.) This list will comprise
* of theendpoints specified by the user in "com.sun.appserv.iiop.endpoints"
* property. We can assume a default weight for these endpoints (e.g 10).
* This list will be used to make the first lookup call. During the first
* lookup call, the actual list of endpoints will beprovided back.
* Then on, whenever there is any change in the clustershape,
* the listener will get the updated list of endpoints from theserver.
* The implementation for choosing the endpoint from the list of endpoints
* is as follows:Let's assume 4 endpoints:A(wt=10), B(wt=30), C(wt=40),
* D(wt=20).
* Using the Random API, generate a random number between 1 and10+30+40+20.
* Let's assume that the above list is randomized. Based on the weights, we
* have intervals as follows:
* 1-----10 (A's weight)
* 11----40 (A's weight + B's weight)
* 41----80 (A's weight + B's weight + C's weight)
* 81----100(A's weight + B's weight + C's weight + C's weight)
* Here's the psuedo code for deciding where to send the request:
* if (random_number between 1 & 10) {send request to A;}
* else if (random_number between 11 & 40) {send request to B;}
* else if (random_number between 41 & 80) {send request to C;}
* else if (random_number between 81 & 100) {send request to D;}
* For simple Round Robin, we can assume the same weight for all endpointsand
* perform the above.
* @author Sheetal Vartak
* @date 8/2/05
**/
public class RoundRobinPolicy {
// Each SocketInfo.type() must either start with SSL, or be CLEAR_TEXT
new LinkedList<ClusterInstanceInfo>();
}
}
}
}
}
//called during bootstrapping
}
// Copy list, changing any type that does not start with SSL to CLEAR_TEXT.
}
return result ;
}
private boolean isWeighted() {
warnLog("loadbalancing.polibeforecy.incorrect");
}
return isw ;
}
boolean isw = isWeighted() ;
new ArrayList<ClusterInstanceInfo>() ;
totalWeight = 0 ;
totalWeight += newWeight ;
}
return newList ;
}
return true ;
}
}
}
}
return false ;
}
// Add those elements of the second list that do not contain a clear
// text address that appears in the first list.
}
}
}
return result ;
}
new LinkedList <ClusterInstanceInfo> ();
default_weight ) ;
}
return result ;
}
//will be called after dynamic reconfig
// used in GroupInfoServiceObserverImpl
synchronized final void setClusterInstanceInfo(
}
// Note: regard any addresses supplied here as a permanent part of the
// cluster.
synchronized final void setClusterInstanceInfoFromString(
}
//randomize the list before adding it to linked list
// Put in a default for total weight; any update will correct this.
} else {
fineLog( "no.endpoints" );
}
}
/**
* during bootstrapping, weight is assumed "10" for all endpoints
* then on, whenever server sends updates list,
* create the list again here with right weights
*/
int weight) {
return instanceInfo;
}
/*
* This method checks for other ways of specifying endpoints
* namely JNDI provider url
* orb host:port is used only if even env passed into
* getInitialContext is empty. This check is performed in
* SerialInitContextFactory.getInitialContext()
*/
if (providerURLString != null) {
try {
return newList ;
} catch (MalformedURLException me) {
}
}
}
/**
* randomize the list. Note: this empties its argument.
*/
}
return result ;
}
/*
* get a new shape of the endpoints
* For e.g. if list contains A,B,C
* if the logic below chooses B as the endpoint to send the req to
* then return B,C,A.
* logic used is as described in Class description comments
*/
int random = 0;
//make sure that the random # is not 0
//Random API gives a number between 0 and sumOfAllWeights
//But our range intervals are from 1-upperLimit,
//11-upperLimit and so
//on. Hence we dont want random # to be 0.
// fineLog( "RoundRobinPolicy.getNextRotation -> sumOfAllWeights = {0}",
// totalWeight);
while( random == 0) {
if ( random != 0) {
break;
}
}
// fineLog( "getNextRotation : random # = {0} sum of all weights = {1}",
// new Object[]{random, totalWeight});
int i = 0;
// fineLog( "upperLimit = {0}", upperLimit);
new LinkedList<ClusterInstanceInfo>();
//add the sublist at index 0
//add the remaining list
//print the contents...
fineLog( "getNextRotation: result={0}",
instanceInfo.toString());
return convertIntoCorbaloc(instanceInfo);
}
// fineLog( "lowerLimit = {0}", lowerLimit);
i++;
}
warnLog("Could not find an endpoint to send request to!");
}
// XXX this needs to be revised if we ever do a secure
// bootstrap protocol for the initial corbaloc URL resolution
}
}
}
}
return host_port ;
}
/**
* following methods (over-loaded) for getting all IP addresses
* corresponding to a particular host.
* (multi-homed hosts).
*/
// The list is assumed to contain <HOST NAME>:<PORT> values
try {
} catch (MalformedURLException me) {
}
}
return addressPortVector ;
}
// Pull out the host name and port
// We return a list of <IP ADDRESS>:<PORT> values
}
// Get the ip addresses corresponding to the host.
// XXX this currently does NOT support IPv6.
try {
if (addr instanceof Inet4Address) {
}
}
}
// We return a list of <IP ADDRESS>:<PORT> values
return ret;
} catch (UnknownHostException ukhe) {
}
}
boolean first = true ;
if (first) {
first = false ;
} else {
}
}
}
return resolvedEndpoints ;
}
}