0

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)

jrey
  • 2,163
  • 1
  • 32
  • 48

1 Answers1

1

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>
Christian Schneider
  • 19,420
  • 2
  • 39
  • 64
  • Thanks @Christian-scheneider... works well using bind and unbind with serializable..But with ServiceReference argument. in the line bundleContext.getService(reference); returns ClassCast Exception – jrey Jan 26 '15 at 15:59
  • 1
    Hmm .. that sounds like there are two instances of ServiceReference around. Can you check if this is the case? – Christian Schneider Jan 26 '15 at 16:56
  • I only have one bundle with package org.osgi.framework, the bundle with Symbolic Name: org.apache.felix.framework. that is the question??? In a web console I see that the bundle imports that. – jrey Jan 26 '15 at 17:41
  • If there is only one package org.osgi.framework then it might indeed be a bug in the implementation or the documentation from IBM (which uses aries) does not fully work for Gemini. – Christian Schneider Jan 27 '15 at 12:55
  • With the Serializable args works well.. But with the ServiceReference does not work(ClassCastException). by the moment I will continue using this.. I hope do not have problems later. Thanks Christian! – jrey Jan 27 '15 at 13:53
  • Ah! the blueprint calls the two methods.. with Serializable and with ServiceReference. – jrey Jan 27 '15 at 13:54