org.eclipse.ecf.osgi.services.discovery.local
Class FileBasedDiscoveryImpl

java.lang.Object
  extended by org.eclipse.ecf.osgi.services.discovery.local.FileBasedDiscoveryImpl

public class FileBasedDiscoveryImpl
extends java.lang.Object


Field Summary
static java.lang.String PROP_KEY_PUBLISH_STRATEGY
          ServiceRegistration property identifying Discovery's default strategy for distribution of published service information.
static java.lang.String PROP_VAL_PUBLISH_STRATEGY_PULL
          Constant for a "pull" publication strategy: published service information is available just upon lookup requests.
static java.lang.String PROP_VAL_PUBLISH_STRATEGY_PUSH
          Constant for a "push" publication strategy: published service information is actively pushed to the network for discovery.
 
Constructor Summary
FileBasedDiscoveryImpl(org.osgi.framework.BundleContext bc, org.osgi.service.log.LogService logger)
          Constructor.
 
Method Summary
 void destroy()
          Shutdown method called by Activator.
 java.util.Map getCachedServices()
          Returns the list of known services without the locally published ones.
protected  java.util.Map getRegisteredServiceTracker()
          Returns a Map of all registered DiscoveredServiceTracker trackers.
 void init()
          Initialization method called by Activator.
static boolean isTrackerInterestedInSED(ServiceEndpointDescription svcDescr, java.util.Map trackerProperties, java.util.Collection matchingInterfaces, java.util.Collection matchingFilters)
          Compares the properties of a registered DiscoveredServiceTracker with the SED properties.
protected static void log(int logLevel, java.lang.String msg)
           
protected static void log(int logLevel, java.lang.String msg, java.lang.Exception e)
           
protected  void notifyListenersOnModifiedServiceDescription(ServiceEndpointDescription svcDescr)
           
protected  void notifyListenersOnNewServiceDescription(ServiceEndpointDescription svcDescr)
           
protected  void notifyListenersOnRemovedServiceDescription(ServiceEndpointDescription svcDescr)
          Notifies all DSTTrackers about an unpublished service.
static void notifyOnAvailableSEDs(DiscoveredServiceTracker tracker, java.util.Map matchingCriteria)
          This method informs a just registered or modified service tracker if a service matches its properties.
protected  ServiceEndpointDescription publishService(java.util.Collection javaInterfaces, java.util.Collection javaInterfacesAndVersions, java.util.Collection javaInterfacesAndEndpointInterfaces, java.util.Map properties, java.lang.String strategy, java.lang.String endpointID)
          Publishes a service.
protected  void publishService(ServiceEndpointDescription svcDescr)
           
static void setLogService(org.osgi.service.log.LogService logger)
           
protected  void unpublishService(ServiceEndpointDescription serviceDescription)
          Unpublishes a given service description.
protected  void validateServiceDescription(ServiceEndpointDescription serviceDescription)
          This method checks if a given ServiceEndpointDescrioption follows the minimal requirements.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROP_KEY_PUBLISH_STRATEGY

public static final java.lang.String PROP_KEY_PUBLISH_STRATEGY
ServiceRegistration property identifying Discovery's default strategy for distribution of published service information. It's up to the Discovery service to provide and support this property. Value of this property is of type String. TODO do we support this property?

See Also:
Constant Field Values

PROP_VAL_PUBLISH_STRATEGY_PUSH

public static final java.lang.String PROP_VAL_PUBLISH_STRATEGY_PUSH
Constant for a "push" publication strategy: published service information is actively pushed to the network for discovery.

See Also:
Constant Field Values

PROP_VAL_PUBLISH_STRATEGY_PULL

public static final java.lang.String PROP_VAL_PUBLISH_STRATEGY_PULL
Constant for a "pull" publication strategy: published service information is available just upon lookup requests.

See Also:
Constant Field Values
Constructor Detail

FileBasedDiscoveryImpl

public FileBasedDiscoveryImpl(org.osgi.framework.BundleContext bc,
                              org.osgi.service.log.LogService logger)
Constructor.

Parameters:
bc - the BundleContext of the containing bundle.
logger - a LogService instance
Method Detail

init

public void init()
Initialization method called by Activator.


destroy

public void destroy()
Shutdown method called by Activator.


publishService

protected ServiceEndpointDescription publishService(java.util.Collection javaInterfaces,
                                                    java.util.Collection javaInterfacesAndVersions,
                                                    java.util.Collection javaInterfacesAndEndpointInterfaces,
                                                    java.util.Map properties,
                                                    java.lang.String strategy,
                                                    java.lang.String endpointID)
Publishes a service. TODO: publish also for every endpoint interface TODO: use endpointLocation as service URL if given

Parameters:
javaInterfaces - collection of java interface names
javaInterfacesAndVersions - collection of versions, where the order of the version must match the order of the java interfaces
javaInterfacesAndEndpointInterfaces - optional collection of endpointinterface names, where the order must match the order of the java interfaces
properties - map of properties; keys must be Strings, values are of type object
strategy - optional string that defines the publish strategy
Returns:
a ServiceEndpointDescription or null, if an error occurred during creation of the ServiceDescription

publishService

protected void publishService(ServiceEndpointDescription svcDescr)

unpublishService

protected void unpublishService(ServiceEndpointDescription serviceDescription)
Unpublishes a given service description.

Parameters:
serviceDescription - the service to unpublish
Throws:
java.lang.IllegalArgumentException - if serviceDescription is null or does not contain at least one java interface

log

protected static void log(int logLevel,
                          java.lang.String msg)

log

protected static void log(int logLevel,
                          java.lang.String msg,
                          java.lang.Exception e)

setLogService

public static void setLogService(org.osgi.service.log.LogService logger)
Parameters:
logger - the reference to the LogService which get called for logging

validateServiceDescription

protected void validateServiceDescription(ServiceEndpointDescription serviceDescription)
This method checks if a given ServiceEndpointDescrioption follows the minimal requirements.

Parameters:
serviceDescription - the given ServiceEndpointDescription
Throws:
java.lang.IllegalArgumentException - if serviceDescription is null or does not contain at least one java interface

getRegisteredServiceTracker

protected java.util.Map getRegisteredServiceTracker()
Returns a Map of all registered DiscoveredServiceTracker trackers. TODO should it be a copy of the map for thread safety? This could lead to failures during usage of the copy. But we do not block the Tracker, registrations and deregistrations of DSTs.

Returns:
a copied Map of all registered DiscoveredServiceTracker trackers.

notifyOnAvailableSEDs

public static void notifyOnAvailableSEDs(DiscoveredServiceTracker tracker,
                                         java.util.Map matchingCriteria)
This method informs a just registered or modified service tracker if a service matches its properties. TODO: add suppression of informing trackers twice for the same SED

Parameters:
tracker - the just registered or modified DiscoveredServiceTracker

notifyListenersOnNewServiceDescription

protected void notifyListenersOnNewServiceDescription(ServiceEndpointDescription svcDescr)
Parameters:
svcDescr -

notifyListenersOnRemovedServiceDescription

protected void notifyListenersOnRemovedServiceDescription(ServiceEndpointDescription svcDescr)
Notifies all DSTTrackers about an unpublished service.

Parameters:
svcDescr - the unpublished ServiceEndpointDescription

notifyListenersOnModifiedServiceDescription

protected void notifyListenersOnModifiedServiceDescription(ServiceEndpointDescription svcDescr)
Parameters:
svcDescr -

isTrackerInterestedInSED

public static boolean isTrackerInterestedInSED(ServiceEndpointDescription svcDescr,
                                               java.util.Map trackerProperties,
                                               java.util.Collection matchingInterfaces,
                                               java.util.Collection matchingFilters)
Compares the properties of a registered DiscoveredServiceTracker with the SED properties. IF they match, it returns true.

Parameters:
svcDescr -
trackerProperties -
matchingInterfaces - (an out-argument) a collection which will contain all tracker's interface criteria matching with given ServiceEndpointDescription object
matchingFilters - (an out-argument) a collection which will contain all tracker's filter criteria matching with given ServiceEndpointDescription object
Returns:
true if the service tracker properties match the SEDs properties, else false

getCachedServices

public java.util.Map getCachedServices()
Returns the list of known services without the locally published ones.

Returns:
a list of all remote services