edu.nyu.cs.pdsg.discovery
Class ServiceManager

java.lang.Object
  extended byedu.nyu.cs.pdsg.discovery.ServiceManager

public class ServiceManager
extends java.lang.Object

The ServiceManager class is responsible for managing a list of service locations and starting the advertising, publishing, and response listeners.


Field Summary
protected static boolean advertising
          The flag that the Advertiser checks to determine if it should stop listening.
private static int advertisingPort
           
static int POLL_INTERVAL
          The interval at which the listener threads should check for their respective stop calls.
protected static boolean publishing
          The flag that the PublishingListener checks to determine if it should stop listening.
private static int requestPort
           
private static java.lang.Thread responseListenerThread
           
protected static boolean responseListening
          The flag that the ResponseListener checks to determine if it should stop listening.
protected static syncQueue serviceQueue
           
private static java.util.Hashtable services
           
 
Constructor Summary
private ServiceManager()
           
 
Method Summary
static boolean addService(ServiceLocatorCollection service)
          Registers a ServiceLocatorCollection with the ServiceManager
static java.util.HashSet findService(ServiceDescriptor sd, Authorizer authorizer)
          Finds a service by broadcasting a request on the local network.
static int getAdvertisingPort()
           
static int getRequestPort()
           
static ServiceLocatorCollection getService(ServiceDescriptor sd)
          Retrieves a registered ServiceLocatorCollection given its ServiceDescriptor.
static boolean isAdvertising()
           
static boolean isListeningForLocators()
           
static boolean isPublishing()
           
static boolean registerServiceLocation(Locator loc)
          Adds a service location to be advertised/published/subscribed to.
static boolean removeService(ServiceLocatorCollection service)
          Removes a ServiceLocatorCollection from the list
static boolean removeServiceLocation(Locator loc)
          Removes a service location and stops it from being advertised/published/subscribed to.
static void setAdvertisingPort(int port)
           
static void setRequestPort(int port)
           
static boolean startAdvertising()
          Begins advertising (broadcasting) services at regular intervals on advertisingPort in a new thread
static boolean startListeningForLocators()
          Begins listening for service advertisements on the advertisingPort in a new thread
static boolean startPublishing()
          Begins listening for service requests on the requestPort in a new thread
static void stopAdvertising()
          Stops the background thread from advertising
static void stopListeningForLocators()
          Stops the background thread from listening
static void stopPublishing()
          Stops the background thread from listening for service requests
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

services

private static java.util.Hashtable services

serviceQueue

protected static syncQueue serviceQueue

requestPort

private static int requestPort

advertisingPort

private static int advertisingPort

responseListenerThread

private static java.lang.Thread responseListenerThread

publishing

protected static volatile boolean publishing
The flag that the PublishingListener checks to determine if it should stop listening.


advertising

protected static volatile boolean advertising
The flag that the Advertiser checks to determine if it should stop listening.


responseListening

protected static volatile boolean responseListening
The flag that the ResponseListener checks to determine if it should stop listening.


POLL_INTERVAL

public static final int POLL_INTERVAL
The interval at which the listener threads should check for their respective stop calls.

See Also:
Constant Field Values
Constructor Detail

ServiceManager

private ServiceManager()
Method Detail

setAdvertisingPort

public static void setAdvertisingPort(int port)
                               throws java.net.SocketException
Throws:
java.net.SocketException - if the specified port is in use

getAdvertisingPort

public static int getAdvertisingPort()

setRequestPort

public static void setRequestPort(int port)
                           throws java.net.SocketException
Throws:
java.net.SocketException - if the specified port is in use

getRequestPort

public static int getRequestPort()

registerServiceLocation

public static boolean registerServiceLocation(Locator loc)
Adds a service location to be advertised/published/subscribed to. A ServiceLocatorCollection corresponding to this Locator is created automatically if it does not yet exist.

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

removeServiceLocation

public static boolean removeServiceLocation(Locator loc)
Removes a service location and stops it from being advertised/published/subscribed to.

Parameters:
loc - the service location to be removed
Returns:
true if the service location has been removed successfully; false otherwise.

addService

public static boolean addService(ServiceLocatorCollection service)
Registers a ServiceLocatorCollection with the ServiceManager

Parameters:
service - the ServiceLocatorCollection to be added
Returns:
true if the ServiceLocatorCollection was not already registered; false otherwise.

removeService

public static boolean removeService(ServiceLocatorCollection service)
Removes a ServiceLocatorCollection from the list

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

getService

public static ServiceLocatorCollection getService(ServiceDescriptor sd)
Retrieves a registered ServiceLocatorCollection given its ServiceDescriptor.

Parameters:
sd - the ServiceDescriptor to retrieve
Returns:
the ServiceLocatorCollection found or null if sd is not registered

findService

public static java.util.HashSet findService(ServiceDescriptor sd,
                                            Authorizer authorizer)
                                     throws java.io.IOException
Finds a service by broadcasting a request on the local network.   If the service is not found in DiscoveryConstants.WAIT_TIME milliseconds, a request is sent to the service home.

Parameters:
sd - the service to locate
authorizer - the Authorizer to use when validating a service location
Returns:
all authorized Locators for the service
Throws:
java.io.IOException - if a serialization or socket I/O error occurs

startPublishing

public static boolean startPublishing()
                               throws java.net.SocketException
Begins listening for service requests on the requestPort in a new thread

Returns:
false if the ServiceManager object is already publishing or true if successful.
Throws:
java.net.SocketException - if there is an error binding to requestPort

stopPublishing

public static void stopPublishing()
Stops the background thread from listening for service requests


isPublishing

public static boolean isPublishing()
Returns:
whether or not the ServiceManager object is currently listening for service requests.

startAdvertising

public static boolean startAdvertising()
Begins advertising (broadcasting) services at regular intervals on advertisingPort in a new thread

Returns:
false if the ServiceManager object is already advertising or true if successful.

stopAdvertising

public static void stopAdvertising()
Stops the background thread from advertising


isAdvertising

public static boolean isAdvertising()
Returns:
whether or not the ServiceManager object is currently advertising

startListeningForLocators

public static boolean startListeningForLocators()
                                         throws java.net.SocketException
Begins listening for service advertisements on the advertisingPort in a new thread

Returns:
false if the ServiceManager object is already listening or true if successful.
Throws:
java.net.SocketException - if there is an error binding to advertisingPort

stopListeningForLocators

public static void stopListeningForLocators()
Stops the background thread from listening


isListeningForLocators

public static boolean isListeningForLocators()
Returns:
whether or not the ServiceManager object is currently listening


Copyright (c) 2002-2003 New York University RLAB