Java 类org.osgi.framework.SynchronousBundleListener 实例源码

项目:blueprint-test    文件:BlueprintHelper.java   
@Override
public void start(BundleContext bundleContext) throws Exception {
    final String configAdminInit = bundleContext.getBundle().getHeaders().get("X-Aries-Blueprint-ConfigAdmin-Init");
    if (configAdminInit != null) {
        final BundleContext sysContext = bundleContext.getBundle(0).getBundleContext();
        // we are started before blueprint.core and felix.configadmin
        // we are sure that felix.configadmin is started before blueprint.core
        sysContext.addBundleListener(new SynchronousBundleListener() {
            @Override
            public void bundleChanged(BundleEvent event) {
                if (event.getType() == BundleEvent.STARTED
                        && "org.apache.felix.configadmin".equals(event.getBundle().getSymbolicName())) {
                    // configadmin should have already been started
                    ServiceReference<?> sr = sysContext.getServiceReference("org.osgi.service.cm.ConfigurationAdmin");
                    if (sr != null && sysContext.getService(sr) != null) {
                        initializeConfigAdmin(sysContext, configAdminInit);
                    }
                }
            }
        });
    }
}
项目:Camel    文件:CamelBlueprintHelper.java   
@Override
public void start(BundleContext bundleContext) throws Exception {
    final String configAdminInit = bundleContext.getBundle().getHeaders().get("X-Camel-Blueprint-ConfigAdmin-Init");
    if (configAdminInit != null) {
        final BundleContext sysContext = bundleContext.getBundle(0).getBundleContext();
        // we are started before blueprint.core and felix.configadmin
        // we are sure that felix.configadmin is started before blueprint.core
        sysContext.addBundleListener(new SynchronousBundleListener() {
            @Override
            public void bundleChanged(BundleEvent event) {
                if (event.getType() == BundleEvent.STARTED
                        && "org.apache.felix.configadmin".equals(event.getBundle().getSymbolicName())) {
                    // configadmin should have already been started
                    ServiceReference<?> sr = sysContext.getServiceReference("org.osgi.service.cm.ConfigurationAdmin");
                    if (sr != null && sysContext.getService(sr) != null) {
                        initializeConfigAdmin(sysContext, configAdminInit);
                    }
                }
            }
        });
    }
}
项目:openeos    文件:ObserverConfigurator.java   
@Override
public void init(ConfigurationProvider configurationProvider) {
    LOG.debug("Initializing observer configuration");
    tracker = new ServiceTracker<SessionFactoryObserver, SessionFactoryObserver>(bundleContext, SessionFactoryObserver.class,
            null);
    tracker.open();
    bundleContext.addBundleListener(new SynchronousBundleListener() {

        @Override
        public void bundleChanged(BundleEvent event) {
            if (event.getBundle().equals(bundleContext.getBundle()) && event.getType() == BundleEvent.STOPPING) {
                tracker.close();
                tracker = null;
            }
        }
    });
    configurationProvider.getConfiguration().setSessionFactoryObserver(this);
    configurationProvider.invalidate();
}
项目:Libraries-for-Android-Developers    文件:MainFragment.java   
/**
 * 监听插件安装事件,当有新插件安装或卸载时成功也更新一下
 */
public void ListenerBundleEvent(){
    BundleContextFactory.getInstance().getBundleContext()
            .addBundleListener(
                    new SynchronousBundleListener(){

                        public void bundleChanged(BundleEvent event) {
                            //把插件列表清空
                            bundles.clear();
                            BundleContext context =BundleContextFactory.getInstance().getBundleContext();
                            for(int i=0;i<context.getBundles().length;i++)
                            {
                                bundles.add(context.getBundles()[i]);

                            }
                            adapter.notifyDataSetChanged();
                        }

                    });
}
项目:gemini.blueprint    文件:CallingResourceOnDifferentBundlesTest.java   
public void testCallGetResourceOnADifferentBundleRetrievedThroughBundleEvent() throws Exception {
    String EXTRA_BUNDLE = "org.apache.servicemix.bundles.spring-core";

    Bundle[] bundles = bundleContext.getBundles();
    Bundle bundle = null;
    for (int i = 1; bundle == null && i < bundles.length; i++) {
        String location = bundles[i].getLocation();
        if (location != null && location.contains(EXTRA_BUNDLE))
            bundle = bundles[i];
    }

    assertNotNull("no bundle found", bundle);
    final Bundle sampleBundle = bundle;

    final boolean[] listenerCalled = new boolean[] { false };

    // register listener
    bundleContext.addBundleListener(new SynchronousBundleListener() {

        public void bundleChanged(BundleEvent event) {
            // call getResource
            event.getBundle().getResource(LOCATION);
            // call getResources
            try {
                event.getBundle().getResources(LOCATION);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }

            listenerCalled[0] = true;
        }
    });

    // update
    sampleBundle.stop();

    assertTrue("bundle listener hasn't been called", listenerCalled[0]);
}
项目:motech    文件:UIServiceTrackers.java   
/**
 * Constructs the registry and registers a bundle listener that will remove trackers for bundles that are stopping.
 * @param bundleContext the bundle context used to register the bundle listener
 */
public UIServiceTrackers(BundleContext bundleContext) {
    bundleContext.addBundleListener(new SynchronousBundleListener() {
        @Override
        public void bundleChanged(BundleEvent event) {
            if (event.getType() == BundleEvent.STOPPING) {
                removeTrackerFor(event.getBundle());
            }
        }
    });
}
项目:motech    文件:HttpServiceTrackers.java   
/**
 * Creates this http tracker registry and registers a bundle listener,
 * that will close the trackers for a bundle once it is stopped.
 *
 * @param bundleContext the context used for registering the bundle listener
 */
public HttpServiceTrackers(BundleContext bundleContext) {
    bundleContext.addBundleListener(new SynchronousBundleListener() {
        @Override
        public void bundleChanged(BundleEvent event) {
            if (event.getType() == BundleEvent.STOPPING) {
                removeTrackerFor(event.getBundle());
            }
        }
    });
}
项目:AtlasForAndroid    文件:BundleContextImpl.java   
public void addBundleListener(BundleListener bundleListener) {
    checkValid();
    List list = bundleListener instanceof SynchronousBundleListener ? Framework.syncBundleListeners : Framework.bundleListeners;
    if (this.bundle.registeredBundleListeners == null) {
        this.bundle.registeredBundleListeners = new ArrayList();
    }
    if (!this.bundle.registeredBundleListeners.contains(bundleListener)) {
        list.add(bundleListener);
        this.bundle.registeredBundleListeners.add(bundleListener);
    }
}
项目:AtlasForAndroid    文件:BundleContextImpl.java   
public void removeBundleListener(BundleListener bundleListener) {
    checkValid();
    (bundleListener instanceof SynchronousBundleListener ? Framework.syncBundleListeners : Framework.bundleListeners).remove(bundleListener);
    this.bundle.registeredBundleListeners.remove(bundleListener);
    if (this.bundle.registeredBundleListeners.isEmpty()) {
        this.bundle.registeredBundleListeners = null;
    }
}
项目:openeos    文件:FilterConfigurator.java   
@Override
public void init(final ConfigurationProvider configurationProvider) {
    LOG.debug("Initializing filter configuration");
    tracker = new ServiceTracker<FilterProvider, FilterProvider>(bundleContext, FilterProvider.class, null) {

        @Override
        public FilterProvider addingService(ServiceReference<FilterProvider> reference) {
            LOG.debug("Filter provider added as a service");
            FilterProvider provider = super.addingService(reference);
            addFilterDefinitions(provider, configurationProvider);
            return provider;
        }

        @Override
        public void removedService(ServiceReference<FilterProvider> reference, FilterProvider service) {
            LOG.debug("Filter provider removed");
            removeFilterDefinitions(service, configurationProvider);
            super.removedService(reference, service);
        }

    };
    tracker.open();
    bundleContext.addBundleListener(new SynchronousBundleListener() {

        @Override
        public void bundleChanged(BundleEvent event) {
            if (event.getBundle().equals(bundleContext.getBundle()) && event.getType() == BundleEvent.STOPPING) {
                tracker.close();
                tracker = null;
            }
        }
    });
}
项目:spring-osgi    文件:CallingResourceOnDifferentBundlesTest.java   
public void testCallGetResourceOnADifferentBundleRetrievedThroughBundleEvent() throws Exception {
    String EXTRA_BUNDLE = "org.springframework.core";

    Bundle[] bundles = bundleContext.getBundles();
    Bundle bundle = null;
    // find cglib library as we don't use it
    for (int i = 1; bundle == null && i < bundles.length; i++) {
        String location = bundles[i].getLocation();
        if (location != null && location.indexOf(EXTRA_BUNDLE) > -1)
            bundle = bundles[i];
    }

    assertNotNull("no bundle found", bundle);
    final Bundle sampleBundle = bundle;

    final boolean[] listenerCalled = new boolean[] { false };

    // register listener
    bundleContext.addBundleListener(new SynchronousBundleListener() {

        public void bundleChanged(BundleEvent event) {
            // call getResource
            event.getBundle().getResource(LOCATION);
            // call getResources
            try {
                event.getBundle().getResources(LOCATION);
            }
            catch (IOException e) {
                throw new RuntimeException(e);
            }

            listenerCalled[0] = true;
        }
    });

    // update
    sampleBundle.stop();

    assertTrue("bundle listener hasn't been called", listenerCalled[0]);
}
项目:gravia    文件:BundleContextAdaptor.java   
private ModuleListener adaptBundleListener(BundleListener listener) {
    if (listener instanceof SynchronousBundleListener) {
        return new SynchronousBundleListenerAdaptor(listener);
    } else {
        return new BundleListenerAdaptor(listener);
    }
}