Pergunta

Usando o Eclipse Virgo, tenho um pacote com um feijão que implementa o BundleContextAwe, adiciono um addbundleListener e recebo os eventos corretamente quando um pacote é iniciado ou parado, tudo bem. e tenha um pacote instalado pelo evento Bundlechanged.

Agora, preciso recuperar todos os grãos do contexto de aplicação do pacote instalados, qual é a melhor maneira de recuperar o contexto do aplicativo do pacote?

 public class PluginManager implements BundleContextAware {
               private BundleContext bundleContext;
          @Override
          public void setBundleContext(BundleContext bundleContext) {
            this.bundleContext = bundleContext;
            bundleContext.addBundleListener(this);
           }

              @Override
         public void bundleChanged(BundleEvent event) {


           Bundle bundle = event.getBundle();

    //HOW TO DO TO GET ALL BEANS OF BUNDLE

        }
}
Foi útil?

Solução

Eu resolvo meu problema com outro ouvinte

  public class PluginManager implements BundleContextAware,OsgiBundleApplicationContextListener {
           private BundleContext bundleContext;
      @Override
      public void setBundleContext(BundleContext bundleContext) {
        this.bundleContext = bundleContext;
        bundleContext.addBundleListener(this);
       }

          @Override
     public void bundleChanged(BundleEvent event) {


       Bundle bundle = event.getBundle();

      //NOW use this method to receive destroy event

    }
    @Override
public void onOsgiApplicationEvent(OsgiBundleApplicationContextEvent event) {

             Bundle bundle = event.getBundle();

    PluginBundleDescriptor pluginBundleDescriptor = new PluginBundleDescriptor();
    pluginBundleDescriptor.setId(bundle.getBundleId());
    pluginBundleDescriptor.setName(bundle.getSymbolicName());
    pluginBundleDescriptor.setApplicationContext(event
            .getApplicationContext());

} }

e publique o serviço com uma interface osgibundleApplicationContextListener (isso é importante)

 <osgi:service id="bundleContextTrackerOSGi" ref="coreModuleManager"
interface="org.springframework.osgi.context.event.OsgiBundleApplicationContextListener" />
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top