Skip to main content
Jump to: navigation, search

Difference between revisions of "Discovery and Distribution Listeners"

(New page: ECF's implementation of RFC 119 has a listener service API, so that clients can monitor and respond to the activities of the implementation during service registration and service publicat...)
 
Line 1: Line 1:
 
ECF's implementation of RFC 119 has a listener service API, so that clients can monitor and respond to the activities of the implementation during service registration and service publication (on the service host), and service discovery and service lookup/proxy creation (on the service consumer).
 
ECF's implementation of RFC 119 has a listener service API, so that clients can monitor and respond to the activities of the implementation during service registration and service publication (on the service host), and service discovery and service lookup/proxy creation (on the service consumer).
  
For all four of the listener interfaces below, the way for clients to create listeners is to  
+
For all of the listener interfaces below, the way for clients to create listeners is to use the whiteboard pattern to
  
 
# Create an instance of the interface
 
# Create an instance of the interface
 
# Register the instance as a service
 
# Register the instance as a service
  
So, for example, here is how one would create and register a IHostDistributionListener
+
When appropriate events occur (i.e. a RFC 119 remote service is registered), the ECF RFC 119 impl will find all registered IHostDistributionListener services and notify them by calling the appropriate event method.
 +
 
 +
For example, here is how one would create and register a IHostDistributionListener
  
 
<source lang="java">
 
<source lang="java">
Line 23: Line 25:
 
bundleContext.registerService(IHostDistributionListener.class.getName(),new MyHostDistributionListener(),null);
 
bundleContext.registerService(IHostDistributionListener.class.getName(),new MyHostDistributionListener(),null);
 
</source>
 
</source>
 +
 +
When a remote service is registered, the 'registered' method will be called, and when a remote service is unregistered the 'unregistered' method will be called.
  
 
===Service Host===
 
===Service Host===
  
 
On the service, host there are two listeners
 
On the service, host there are two listeners

Revision as of 17:38, 3 June 2009

ECF's implementation of RFC 119 has a listener service API, so that clients can monitor and respond to the activities of the implementation during service registration and service publication (on the service host), and service discovery and service lookup/proxy creation (on the service consumer).

For all of the listener interfaces below, the way for clients to create listeners is to use the whiteboard pattern to

  1. Create an instance of the interface
  2. Register the instance as a service

When appropriate events occur (i.e. a RFC 119 remote service is registered), the ECF RFC 119 impl will find all registered IHostDistributionListener services and notify them by calling the appropriate event method.

For example, here is how one would create and register a IHostDistributionListener

// define class to implement IHostDistributionListener
public class MyHostDistributionListener implements IHostDistributionListener {
   public void registered(ServiceReference serviceReference,IRemoteServiceContainer remoteServiceContainer, IRemoteServiceRegistration remoteRegistration) {
      System.out.println("hostRegistered\n\tserviceReference="+serviceReference+"\n\tremoteServiceContainer="+remoteServiceContainer+"\n\tremoteRegistration="+remoteRegistration);
   }
 
   public void unregistered(ServiceReference serviceReference, IRemoteServiceRegistration remoteRegistration) {
      System.out.println("hostUnregistered\n\tserviceReference="+serviceReference+"\n\tremoteRegistration="+remoteRegistration);
   }
}
...
// register new instance of MyHostDistributionListener as OSGi service
bundleContext.registerService(IHostDistributionListener.class.getName(),new MyHostDistributionListener(),null);

When a remote service is registered, the 'registered' method will be called, and when a remote service is unregistered the 'unregistered' method will be called.

Service Host

On the service, host there are two listeners

Copyright © Eclipse Foundation, Inc. All Rights Reserved.