edu.nyu.cs.pdsg.discovery
Class ServiceLocatorCollection

java.lang.Object
  extended byedu.nyu.cs.pdsg.discovery.ServiceLocatorCollection
All Implemented Interfaces:
java.lang.Comparable

public class ServiceLocatorCollection
extends java.lang.Object
implements java.lang.Comparable

Note: this class has a natural ordering that is inconsistent with equals.


Field Summary
private  int advertisingInterval
           
private  ServiceDescriptor descriptor
           
private  java.util.HashSet locators
           
protected  java.util.Date nextAdvertisement
           
private  boolean published
           
private static int seqNumHistoryNextAdb
           
protected  int seqNumNextAdv
           
protected  java.util.HashSet subscribers
           
 
Constructor Summary
ServiceLocatorCollection(ServiceDescriptor _descriptor)
           
 
Method Summary
 boolean addServiceLocation(Locator loc)
          Adds a service location to be advertised/published/subscribed to
 void advertise()
          Sends a broadcast advertisement of this ServiceLocatorCollection if there are Locators present
 void advertise(java.net.InetAddress recipient)
          Advertises this ServiceLocatorCollection to the specified recipient if there are Locators present
protected static boolean authorizeServiceLocation(Authorizer authorizer, Locator location)
          Authorizes a service location using the specified authorizer
protected static java.util.HashSet authorizeServiceLocations(Authorizer authorizer, java.util.HashSet locations)
          Authorizes a list of service locations using the specified authorizer
 void clearServiceLocations()
           
 int compareTo(java.lang.Object o)
          Compares ServiceLocatorCollections based on their next time at which they will be advertised
 boolean equals(java.lang.Object o)
          Two Services are equal if their ServiceDescriptor's are equal.
 int getAdvertisingInterval()
           
 ServiceDescriptor getServiceDescriptor()
           
 java.util.HashSet getServiceLocations()
           
 java.util.HashSet getServiceLocations(Authorizer authorizer)
          This version of getServiceLocations authorizes each service location.
 int hashCode()
           
 boolean isPublished()
           
 boolean removeServiceLocation(Locator loc)
          Removes a service location from the list
private  void sendObject(java.lang.Object o, java.net.InetAddress recipient, int port)
          Serializes and sends an object over a DatagramSocket
 void sendRequest()
          Sends a broadcast service request for this ServiceLocatorCollection
 void sendRequest(java.net.InetAddress recipient)
          Sends a service request for this ServiceLocatorCollection to the specified recipient using the default request port
 void sendRequest(java.net.InetSocketAddress recipient)
          Sends a service request for this ServiceLocatorCollection to the specified recipient
 void setAdvertisingInterval(int _advertisingInterval)
          Sets the interval at which this ServiceLocatorCollection is advertised (broadcasted)
 void setPublished(boolean _published)
          Sets whether or not service locations for this ServiceLocatorCollection should be sent in response to a service request
 boolean subscribe(Subscriber subscriber)
          Registers a Subscriber to receive new service advertisements
 boolean unsubscribe(Subscriber subscriber)
          Unregisters a subscriber from this ServiceLocatorCollection
private  void updateCounter()
          update the value of counter as guaranteeing the order of being added
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

locators

private java.util.HashSet locators

descriptor

private ServiceDescriptor descriptor

subscribers

protected java.util.HashSet subscribers

published

private boolean published

advertisingInterval

private int advertisingInterval

nextAdvertisement

protected java.util.Date nextAdvertisement

seqNumHistoryNextAdb

private static int seqNumHistoryNextAdb

seqNumNextAdv

protected int seqNumNextAdv
Constructor Detail

ServiceLocatorCollection

public ServiceLocatorCollection(ServiceDescriptor _descriptor)
Method Detail

addServiceLocation

public boolean addServiceLocation(Locator loc)
Adds a service location to be advertised/published/subscribed to

Parameters:
loc - the service location to be added
Returns:
true if the service location was not already registered and the name and home of the location correspond to this ServiceLocatorCollection; false otherwise.

removeServiceLocation

public boolean removeServiceLocation(Locator loc)
Removes a service location from the list

Parameters:
loc - the service location to be removed
Returns:
true if the service location was already registered; false otherwise.

clearServiceLocations

public void clearServiceLocations()

getServiceLocations

public java.util.HashSet getServiceLocations()
Returns:
a copy of the list of service locations registered for this Service

getServiceLocations

public java.util.HashSet getServiceLocations(Authorizer authorizer)
This version of getServiceLocations authorizes each service location.

Parameters:
authorizer - the Authorizer to use to authorize each service location
Returns:
the authorized list of service locations

authorizeServiceLocations

protected static java.util.HashSet authorizeServiceLocations(Authorizer authorizer,
                                                             java.util.HashSet locations)
Authorizes a list of service locations using the specified authorizer

Parameters:
authorizer - the Authorizer to use to authorize each service location
locations - the list of service locations to authorize
Returns:
the authorized list of service locations

authorizeServiceLocation

protected static boolean authorizeServiceLocation(Authorizer authorizer,
                                                  Locator location)
Authorizes a service location using the specified authorizer

Parameters:
authorizer - the Authorizer to use
location - the service location to authorize
Returns:
true if authorization was successful; false otherwise

subscribe

public boolean subscribe(Subscriber subscriber)
Registers a Subscriber to receive new service advertisements

Parameters:
subscriber - the Subscriber to register
Returns:
true if subscriberfalse otherwise

unsubscribe

public boolean unsubscribe(Subscriber subscriber)
Unregisters a subscriber from this ServiceLocatorCollection

Parameters:
subscriber - the Subscriber to remove
Returns:
true if subscriber was already registered; false otherwise.

setPublished

public void setPublished(boolean _published)
Sets whether or not service locations for this ServiceLocatorCollection should be sent in response to a service request


isPublished

public boolean isPublished()
Returns:
whether or not service locations for this ServiceLocatorCollection should be sent in response to a service request

setAdvertisingInterval

public void setAdvertisingInterval(int _advertisingInterval)
Sets the interval at which this ServiceLocatorCollection is advertised (broadcasted)

Parameters:
_advertisingInterval - the interval in seconds, use a negative value to stop this Service from being advertised

getAdvertisingInterval

public int getAdvertisingInterval()
Returns:
the interval in seconds at which this ServiceLocatorCollection is advertised (broadcasted)

hashCode

public int hashCode()
Returns:
the hashCode of the ServiceDescriptor for this ServiceLocatorCollection

getServiceDescriptor

public ServiceDescriptor getServiceDescriptor()
Returns:
the ServiceDescriptor for this ServiceLocatorCollection

equals

public boolean equals(java.lang.Object o)
Two Services are equal if their ServiceDescriptor's are equal.


compareTo

public int compareTo(java.lang.Object o)
Compares ServiceLocatorCollections based on their next time at which they will be advertised

Specified by:
compareTo in interface java.lang.Comparable

sendObject

private void sendObject(java.lang.Object o,
                        java.net.InetAddress recipient,
                        int port)
                 throws java.io.IOException
Serializes and sends an object over a DatagramSocket

Parameters:
o - the object to send
recipient - the destination to send to
port - the port to send to
Throws:
java.io.IOException - if a serialization or socket I/O error occurs

advertise

public void advertise(java.net.InetAddress recipient)
               throws java.io.IOException
Advertises this ServiceLocatorCollection to the specified recipient if there are Locators present

Parameters:
recipient - the destination to send the advertisement to
Throws:
java.io.IOException - if a serialization or socket I/O error occurs

advertise

public void advertise()
               throws java.net.UnknownHostException,
                      java.io.IOException
Sends a broadcast advertisement of this ServiceLocatorCollection if there are Locators present

Throws:
java.net.UnknownHostException - if there is an error when getting the local host to compute the broadcast address
java.io.IOException - if a serialization or socket I/O error occurs

sendRequest

public void sendRequest(java.net.InetAddress recipient)
                 throws java.io.IOException
Sends a service request for this ServiceLocatorCollection to the specified recipient using the default request port

Parameters:
recipient - the destination to send the service request to
Throws:
java.io.IOException - if a serialization or socket I/O error occurs

sendRequest

public void sendRequest(java.net.InetSocketAddress recipient)
                 throws java.io.IOException
Sends a service request for this ServiceLocatorCollection to the specified recipient

Parameters:
recipient - the destination to send the service request to
Throws:
java.io.IOException - if a serialization or socket I/O error occurs

sendRequest

public void sendRequest()
                 throws java.net.UnknownHostException,
                        java.io.IOException
Sends a broadcast service request for this ServiceLocatorCollection

Throws:
java.net.UnknownHostException - if there is an error when getting the local host to compute the broadcast address
java.io.IOException - if a serialization or socket I/O error occurs

updateCounter

private void updateCounter()
update the value of counter as guaranteeing the order of being added



Copyright (c) 2002-2003 New York University RLAB