edu.UCL.satin.impl.advertising.central.clients.discovery
Class CentralDiscovery

java.lang.Object
  extended byedu.UCL.satin.arch.components.Component
      extended byedu.UCL.satin.impl.arch.components.comms.Discovery
          extended byedu.UCL.satin.impl.advertising.central.clients.discovery.CentralDiscovery
All Implemented Interfaces:
ComponentFacet, DiscoveryFacet, Facet, java.lang.Runnable

public class CentralDiscovery
extends Discovery
implements java.lang.Runnable

This Discovery component interfaces with AdvertisingServer.java

Author:
Stefanos Zachariadis

Field Summary
private  DebugFacet debug
           
private  boolean enabled
           
private  java.lang.String ip
           
private  java.util.Vector listeners
           
private  int port
           
private  java.util.Vector repo
           
private  long sleep
           
 
Fields inherited from class edu.UCL.satin.arch.components.Component
immutable, properties
 
Fields inherited from interface edu.UCL.satin.arch.facets.ComponentFacet
DISABLED, ENABLED
 
Constructor Summary
CentralDiscovery()
          Initialises the component.
 
Method Summary
 void addListener(ComponentListener c)
          Adds a listener that will be notified when any new component is discovered.
 void addListener(ComponentListener c, java.util.Hashtable filter)
          Adds a listener that will be notified when any new component matching the filter given is discovered.
private  void checkListeners(Component c)
          Method to notify any listeners about a component found
 Component[] getComponents(java.util.Hashtable properties)
          Returns an array of Components found that match the given property set
 java.lang.String getIp()
           
 int getPort()
           
private  java.util.Vector getRemoteComponents()
          This method returns all the components available at a remote server.
 long getSleep()
           
 boolean isEnabled()
          Returns whether this component is enabled/active or not.
 void removeListener(ComponentListener c)
          Removes all instances of the given listener (including any different filters) from the list of listeners to be notified.
 void removeListener(ComponentListener c, java.util.Hashtable filter)
          Removes the particular listener+filter pair from the list of listeners to be notified.
 void run()
           
 void setEnabled(boolean enabled)
          Activates or deactivates this component (if applicable).
 void setIP(java.lang.String string)
          Sets the IP address of the CentralDiscovery server
 void setPort(int i)
          Sets the port that the CentralDiscovery server is listening to
 void setSleep(long sleep)
          Sets the period between poling the registry for new components
 
Methods inherited from class edu.UCL.satin.arch.components.Component
addAttribute, construct, destroy, getAttribute, getProperties, hasAttribute, match, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

repo

private java.util.Vector repo

listeners

private java.util.Vector listeners

ip

private java.lang.String ip

port

private int port

enabled

private boolean enabled

sleep

private long sleep

debug

private DebugFacet debug
Constructor Detail

CentralDiscovery

public CentralDiscovery()
Initialises the component. Note that by default the component is disabled, the polling period (yup, it polls) is 10 seconds and no IP or port is given for the remote server.

Method Detail

run

public void run()
Specified by:
run in interface java.lang.Runnable

addListener

public void addListener(ComponentListener c)
Description copied from class: Discovery
Adds a listener that will be notified when any new component is discovered.

Specified by:
addListener in interface DiscoveryFacet
Specified by:
addListener in class Discovery
Parameters:
c - the listener that will be notified

addListener

public void addListener(ComponentListener c,
                        java.util.Hashtable filter)
Description copied from class: Discovery
Adds a listener that will be notified when any new component matching the filter given is discovered.

Specified by:
addListener in interface DiscoveryFacet
Specified by:
addListener in class Discovery
Parameters:
c - the listener to be notified
filter - The filter, as a hashtable of attributes

removeListener

public void removeListener(ComponentListener c)
Description copied from class: Discovery
Removes all instances of the given listener (including any different filters) from the list of listeners to be notified.

Specified by:
removeListener in interface DiscoveryFacet
Specified by:
removeListener in class Discovery
Parameters:
c - The listener to be removed.

setSleep

public void setSleep(long sleep)
Sets the period between poling the registry for new components

Parameters:
sleep -

getSleep

public long getSleep()

removeListener

public void removeListener(ComponentListener c,
                           java.util.Hashtable filter)
Description copied from class: Discovery
Removes the particular listener+filter pair from the list of listeners to be notified.

Specified by:
removeListener in interface DiscoveryFacet
Specified by:
removeListener in class Discovery
Parameters:
c - The listener to be removed
filter - The filter matches of which this listener will not be notified any more.

getComponents

public Component[] getComponents(java.util.Hashtable properties)
Description copied from class: Discovery
Returns an array of Components found that match the given property set

Specified by:
getComponents in interface DiscoveryFacet
Specified by:
getComponents in class Discovery
Parameters:
properties - The properties that the returned components need to match
Returns:
The components that match the given properties

isEnabled

public boolean isEnabled()
Description copied from class: Component
Returns whether this component is enabled/active or not. Note that unless overloaded, the component is assumed to always be enabled

Specified by:
isEnabled in interface ComponentFacet
Overrides:
isEnabled in class Component
Returns:

setEnabled

public void setEnabled(boolean enabled)
Description copied from class: Component
Activates or deactivates this component (if applicable). Note that unless overloaded, the component is assumed to always be enabled.

Specified by:
setEnabled in interface ComponentFacet
Overrides:
setEnabled in class Component
Parameters:
enabled -

getRemoteComponents

private java.util.Vector getRemoteComponents()
This method returns all the components available at a remote server. If new components are found, it notifies any listeners

Returns:

checkListeners

private void checkListeners(Component c)
Method to notify any listeners about a component found

Parameters:
c - the new component found

getIp

public java.lang.String getIp()
Returns:
The IP address of the CentralDiscovery server

getPort

public int getPort()
Returns:
The port number that the CentralDiscovery server is listening to

setIP

public void setIP(java.lang.String string)
Sets the IP address of the CentralDiscovery server

Parameters:
string -

setPort

public void setPort(int i)
Sets the port that the CentralDiscovery server is listening to

Parameters:
i -