cgl.narada.discovery.broker
Class BrokerDiscoveryHelper

java.lang.Object
  extended by cgl.narada.discovery.broker.BrokerDiscoveryHelper

public class BrokerDiscoveryHelper
extends Object

A client can use the Broker Locator to locate a suitable broker to connect to.
The BrokerDiscoveryHelper sends BrokerDiscoveryRequest to (a) known (BDN)s. If the BDN is not available then the request is broadcasted using UDP multicast.
Created on Mar 26, 2005


Field Summary
static double BROKER_DISCOVERY_PING_TIME
          50% weightage is given to the Ping time
static int MAX_PINGS
           
static int RESPONSE_PACKET_SIZE
           
static int TIMEOUT
           
static double WEIGHTAGE_FREE_TO_TOTAL_MEMORY
          4% weightage is given to the %age of free memory
static double WEIGHTAGE_NUM_LINKS
          5% weightage is given to the Number of links a broker has
static double WEIGHTAGE_TOTAL_MEMORY
          10% weightage is given to the amount of memory present
 
Constructor Summary
BrokerDiscoveryHelper(int entityId, String configFilePath, int timeout, int maxResponses, int maxSetSize)
           
 
Method Summary
 double computeBrokerWeightage(BrokerDiscoveryResponse resp)
          Computes weight for the given broker using the values in the BrokerDiscoveryResponse
 BrokerDiscoveryResponse[] discover(String[] protocols, String secCerts, String brokerNetworks)
          We first initialize and run the UDPReciever thread.
 String getBrokerLocation(BrokerDiscoveryResponse bdr)
           
static void main(String[] args)
          Testing purposes only
 long ping(String host, int port, int timeout)
          Pings a given broker
 BrokerDiscoveryResponse selectBestBroker(BrokerDiscoveryResponse[] brokers)
          Selects the best broker among the specified set of brokers from the broker discovery responses
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIMEOUT

public static int TIMEOUT

RESPONSE_PACKET_SIZE

public static final int RESPONSE_PACKET_SIZE
See Also:
Constant Field Values

BROKER_DISCOVERY_PING_TIME

public static final double BROKER_DISCOVERY_PING_TIME
50% weightage is given to the Ping time

See Also:
Constant Field Values

WEIGHTAGE_TOTAL_MEMORY

public static final double WEIGHTAGE_TOTAL_MEMORY
10% weightage is given to the amount of memory present

See Also:
Constant Field Values

WEIGHTAGE_NUM_LINKS

public static final double WEIGHTAGE_NUM_LINKS
5% weightage is given to the Number of links a broker has

See Also:
Constant Field Values

WEIGHTAGE_FREE_TO_TOTAL_MEMORY

public static final double WEIGHTAGE_FREE_TO_TOTAL_MEMORY
4% weightage is given to the %age of free memory

See Also:
Constant Field Values

MAX_PINGS

public static final int MAX_PINGS
See Also:
Constant Field Values
Constructor Detail

BrokerDiscoveryHelper

public BrokerDiscoveryHelper(int entityId,
                             String configFilePath,
                             int timeout,
                             int maxResponses,
                             int maxSetSize)
Method Detail

discover

public BrokerDiscoveryResponse[] discover(String[] protocols,
                                          String secCerts,
                                          String brokerNetworks)
We first initialize and run the UDPReciever thread. The try to send the request to one of the BDNs of if unsuccessful, try and multicast the request. In either case, if the request could be sent, we wait for responses else we close the UDPReciever's socket and return null.

Parameters:
protocols - - A list of 1 or more matching protocols the broker MUST support.
secCerts - - Security Certificate. TODO: Replace w/ X.509 Certificate
brokerNetworks - - brokers belonging to which networks must be considered. "*" to match any network
Returns:
null if a BrokerDiscoveryRequest could not be sent, an array of Responses (possibly empty) otherwise.

ping

public long ping(String host,
                 int port,
                 int timeout)
Pings a given broker

Parameters:
host - - IP address of the broker
port - - UDP port of broker
timeout - - Time for which to wait
Returns:
PING time in microSeconds if successful, -1 if timeout, -2 if garbled protocol header or other error.

computeBrokerWeightage

public double computeBrokerWeightage(BrokerDiscoveryResponse resp)
Computes weight for the given broker using the values in the BrokerDiscoveryResponse

Parameters:
resp - - The BrokerDiscoveryResponse containing the metrics for the broker
Returns:
- A double value indicating the computed weight

getBrokerLocation

public String getBrokerLocation(BrokerDiscoveryResponse bdr)

selectBestBroker

public BrokerDiscoveryResponse selectBestBroker(BrokerDiscoveryResponse[] brokers)
Selects the best broker among the specified set of brokers from the broker discovery responses

Parameters:
brokers - An array of BrokerDiscoveryResponses
Returns:
The BrokerDiscoveryResponse of the best broker

main

public static void main(String[] args)
Testing purposes only

Parameters:
args -


For comments and suggestions please send e-mail to The NaradaBrokering Project