سؤال

باستخدام Eclipse Virgo ، لدي حزمة مع حبة تنفذ bundlecontextaware ، أقوم بإضافة AddBundLelistener وأتلقى الأحداث بشكل صحيح عند بدء تشغيل الحزمة أو إيقافها ، وهذا جيد. ولديها حزمة مثبتة بواسطة الحدث bundlechanged.

الآن ، أحتاج إلى استرداد جميع فاصوليا من سياق التطبيق المثبت ، ما هي أفضل طريقة لاسترداد سياق التطبيق للحزمة؟

 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

        }
}
هل كانت مفيدة؟

المحلول

أحل مشكلتي مع مستمع آخر

  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());

} }

ونشر الخدمة مع واجهة OsGiBundleApplicationContextListener (هذا مهم)

 <osgi:service id="bundleContextTrackerOSGi" ref="coreModuleManager"
interface="org.springframework.osgi.context.event.OsgiBundleApplicationContextListener" />
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top