Blueprint Osgi - Service created/destroyed Listener

1.1k Views Asked by At

Is possible add a Listener to know when a Bean Service with a particular Interface is created. And when the bean with the same interface is destroyed???

What is the best way to do it? reading the list of injecting services

<reference-list
        id="javoraiConceptProcessList"
        interface="com.api.MyTask"
        availability="optional"
        ></reference-list>

What is the way to know when the list values is changed?

I am using Gemini Blueprint(Spring)

1

There are 1 best solutions below

6
On BEST ANSWER

See the blueprint documentation at IBM.

This is how to do it (below). So you specify bind and unbind methods on a bean that will be called.

  public class ReferenceListener {
       public void bind(ServiceReference reference) {
           ...
       }
       public void bind(Serializable service) {
           ...
       }
       public void unbind(ServiceReference reference) {
           ...
       }       
   }

   <reference-list id=”serviceReferenceListTwo” interface=”java.io.Serializable”
              availability=”optional”>
      <reference-listener 
              bind-method=”bind” unbind-method=”unbind”>
          <bean class=“org.apache.geronimo.osgi.ReferenceListener”/>        
      </reference-listener>
   </reference-list>