copyright The Portico Project 2008.

org.portico.shared
Class MulticastLookup

java.lang.Object
  extended by org.portico.shared.MulticastLookup

public class MulticastLookup
extends Object

This class provides utility methods for communicating with the MulticastRegistry that resides in the RTI. These methods are generally used to dynamically discover bindings connection information, but they can be used to look up any name/value pair information provided by the MulticastRegistry.


Field Summary
private static MulticastLookup INSTANCE
           
private  org.apache.log4j.Logger logger
           
private static Random RANDOM
           
 
Constructor Summary
MulticastLookup()
           
 
Method Summary
private  String _lookup(String request)
          This method performs the lookup described in lookup(String)
private  String getResponse(String received)
          Extracts and returns the response text from the given packet information.
private  String getSerialNumber(String received)
          Extracts and returns the serial number on the incoming packet information.
static String lookup(String binding)
          This method performs the actual lookup, passing the given string as the request key.
private  int newSerialNumber()
          Generate a new serial number to append to the request so we can identify the response when it comes back.
private  boolean validNotification(String received, int serial)
          Returns true if this is a valid notification (that is, it is a response and has the same serial number as the one we sent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSTANCE

private static final MulticastLookup INSTANCE

RANDOM

private static final Random RANDOM

logger

private org.apache.log4j.Logger logger
Constructor Detail

MulticastLookup

public MulticastLookup()
Method Detail

_lookup

private String _lookup(String request)
                throws Exception
This method performs the lookup described in lookup(String)

Returns:
The value for the given request key stored inside the multicast registry
Throws:
Exception

newSerialNumber

private int newSerialNumber()
Generate a new serial number to append to the request so we can identify the response when it comes back. This is a random number between 1000 and 10000.


validNotification

private boolean validNotification(String received,
                                  int serial)
Returns true if this is a valid notification (that is, it is a response and has the same serial number as the one we sent

Parameters:
received - The received notification
serial - Our serial number
Returns:
True if this is our response, false otherwise

getSerialNumber

private String getSerialNumber(String received)
Extracts and returns the serial number on the incoming packet information. If there is an error finding it, an IllegalArgumentException is thrown


getResponse

private String getResponse(String received)
Extracts and returns the response text from the given packet information. If there is an error working with the received data, an IllegalArgumentException is thrown


lookup

public static String lookup(String binding)
                     throws Exception
This method performs the actual lookup, passing the given string as the request key. See the MulticastRegistry for low-level information on how messages are formatted when communicating with the registry.

The returned string is the value received in response to the request and constitutes the value stored in the registry for the given request key. If there is an error communicating with the registry, or the registry sends back an error response (perhaps it couldn't find any value for the key), an exception will be thrown. Note that the return value has had any packaging information (such as serial numbers or success/error codes) stripped from it before it is returned.

Returns:
The value for the given request key stored inside the multicast registry
Throws:
Exception

copyright The Portico Project 2008.