livespace.osgi
Class NewServiceBinding

java.lang.Object
  extended by livespace.osgi.NewServiceBinding
All Implemented Interfaces:
EventListener, org.osgi.framework.ServiceListener

public class NewServiceBinding
extends Object
implements org.osgi.framework.ServiceListener

Creates a binding to another service or services. When the required services start and stop, the binding will call nominated methods on the client. The methods are called with two parameters, eg:

   public void register (BundleContext context, ISomeService service)
 
If the System property "use.experimental.service_binding" is true, it is possible to listen for multiple instances of a single service interface; clients will be notified about the starting and stopping of each of them. Otherwise clients will only be notified about one instance of a service interface, the first one to become available. It's default value is now true but it can be turned off by running the Livespace client with the command line switch for Java:
   -Duse.experimental.service_binding=false
 

Author:
Matthew Phillips

Constructor Summary
NewServiceBinding(org.osgi.framework.BundleContext context, Class<?> serviceType, Object activator, String bindMethodName, String unbindMethodName)
          Create a new instance.
NewServiceBinding(org.osgi.framework.BundleContext context, String filter, Object activator, String bindMethodName, String unbindMethodName)
          Create a new instance.
 
Method Summary
 void dispose()
           
static String ldapFilterFor(Class<?> serviceType)
          Create an LDAP filter for selecting a service with a given service class type.
static String ldapFilterFor(Class<?> serviceType, String filter)
          Create an LDAP filter for selecting a service with a given service class type plus an addition filter.
static String ldapFilterFor(String serviceType)
          Create an LDAP filter for selecting a service with a given service class type.
static String ldapFilterFor(String serviceType, String filter)
          Create an LDAP filter for selecting a service with a given service class type plus an addition filter.
 void serviceChanged(org.osgi.framework.ServiceEvent e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NewServiceBinding

public NewServiceBinding(org.osgi.framework.BundleContext context,
                         Class<?> serviceType,
                         Object activator,
                         String bindMethodName,
                         String unbindMethodName)
Create a new instance.

Parameters:
context - The bundle context.
serviceType - The class name of the required service (usually an interface).
activator - The activator instance to call back.
bindMethodName - The method to call on the activator when the required service becomes available.
unbindMethodName - The method to call on the activator when the required service becomes unavailable.
See Also:
NewServiceBinding(BundleContext, Class, Object, String, String)

NewServiceBinding

public NewServiceBinding(org.osgi.framework.BundleContext context,
                         String filter,
                         Object activator,
                         String bindMethodName,
                         String unbindMethodName)
                  throws org.osgi.framework.InvalidSyntaxException
Create a new instance.

Parameters:
context - The bundle context.
filter - The LDAP filter expression to use to select services. May be null for select all. See the ldapFilterFor () methods for ways to easily create common filters.
activator - The activator instance to call back.
bindMethodName - The method to call on the activator when the required service becomes available.
unbindMethodName - The method to call on the activator when the required service becomes unavailable.
Throws:
org.osgi.framework.InvalidSyntaxException
See Also:
NewServiceBinding(BundleContext, String, Object, String, String)
Method Detail

ldapFilterFor

public static String ldapFilterFor(Class<?> serviceType)
Create an LDAP filter for selecting a service with a given service class type. This can be used in the ServiceBinding constructor's filter parameter.

Parameters:
serviceType - The class (usually a service interface) to generate the filter for.
Returns:
An LDAP filter that selects the class.

ldapFilterFor

public static String ldapFilterFor(String serviceType)
Create an LDAP filter for selecting a service with a given service class type. This can be used in the ServiceBinding constructor's filter parameter.

Parameters:
serviceType - The class name (usually a service interface) to generate the filter for.
Returns:
An LDAP filter that selects the class.

ldapFilterFor

public static String ldapFilterFor(Class<?> serviceType,
                                   String filter)
Create an LDAP filter for selecting a service with a given service class type plus an addition filter. This can be used in the ServiceBinding constructor's filter parameter.

Parameters:
serviceType - The class (usually a service interface) to generate the filter for.
filter - A filter to subselect from the services selected by serviceType. e.g. "panelId=livespace.ui.some_dashboard_id".
Returns:
An LDAP filter that selects the class.

ldapFilterFor

public static String ldapFilterFor(String serviceType,
                                   String filter)
Create an LDAP filter for selecting a service with a given service class type plus an addition filter. This can be used in the ServiceBinding constructor's filter parameter.

Parameters:
serviceType - The class name (usually a service interface) to generate the filter for.
filter - A filter to subselect from the services selected by serviceType. e.g. "panelId=livespace.ui.some_dashboard_id".
Returns:
An LDAP filter that selects the class.

dispose

public void dispose()

serviceChanged

public void serviceChanged(org.osgi.framework.ServiceEvent e)
Specified by:
serviceChanged in interface org.osgi.framework.ServiceListener


Copyright © 2008 Commonwealth of Australia