/** * notify all bundle listeners. * * @param state the new state. * @param bundle the bundle. */ static void notifyBundleListeners(final int state, final Bundle bundle) { if (syncBundleListeners.isEmpty() && bundleListeners.isEmpty()) { return; } final BundleEvent event = new BundleEvent(state, bundle); // inform the synchrounous bundle listeners first ... final BundleListener[] syncs = (BundleListener[]) syncBundleListeners.toArray(new BundleListener[syncBundleListeners.size()]); for (int i = 0; i < syncs.length; i++) { syncs[i].bundleChanged(event); } if (bundleListeners.isEmpty()) { return; } final BundleListener[] asyncs = (BundleListener[]) bundleListeners.toArray(new BundleListener[bundleListeners.size()]); for (int i = 0; i < asyncs.length; i++) { asyncs[i].bundleChanged(event); } }
static void notifyBundleListeners(int event, Bundle bundle) { if (!syncBundleListeners.isEmpty() || !bundleListeners.isEmpty()) { BundleEvent bundleEvent = new BundleEvent(event, bundle); BundleListener[] bundleListenerArr = syncBundleListeners.toArray(new BundleListener[syncBundleListeners.size()]); for (BundleListener bundleChanged : bundleListenerArr) { bundleChanged.bundleChanged(bundleEvent); } if (!bundleListeners.isEmpty()) { bundleListenerArr = bundleListeners.toArray(new BundleListener[bundleListeners.size()]); for (BundleListener bundleListener : bundleListenerArr) { bundleListener.bundleChanged(bundleEvent); } } } }
static void notifyBundleListeners(int i, Bundle bundle) { int i2 = 0; if (!syncBundleListeners.isEmpty() || !bundleListeners.isEmpty()) { BundleEvent bundleEvent = new BundleEvent(i, bundle); BundleListener[] bundleListenerArr = (BundleListener[]) syncBundleListeners.toArray(new BundleListener[syncBundleListeners.size()]); for (BundleListener bundleChanged : bundleListenerArr) { bundleChanged.bundleChanged(bundleEvent); } if (!bundleListeners.isEmpty()) { bundleListenerArr = (BundleListener[]) bundleListeners.toArray(new BundleListener[bundleListeners.size()]); while (i2 < bundleListenerArr.length) { bundleListenerArr[i2].bundleChanged(bundleEvent); i2++; } } } }
@Test public void stop() throws Exception { ArgumentCaptor<BundleListener> bundleListenerCaptor = ArgumentCaptor.forClass( BundleListener.class ); BundleContext mockBundleContext = mock( BundleContext.class ); final ServiceRegistration mockServiceRegistration = mock( ServiceRegistration.class ); when( mockBundleContext .registerService( eq( PentahoWebPackageService.class ), any( PentahoWebPackageService.class ), any() ) ) .thenReturn( mockServiceRegistration ); this.activator.start( mockBundleContext ); verify( mockBundleContext, times( 1 ) ).addBundleListener( bundleListenerCaptor.capture() ); this.activator.stop( mockBundleContext ); verify( mockServiceRegistration, times( 1 ) ).unregister(); verify( mockBundleContext, times( 1 ) ).removeBundleListener( same( bundleListenerCaptor.getValue() ) ); }
public FileAssociationChecker() { mEditorRegistry = PlatformUI.getWorkbench().getEditorRegistry(); mJobName = EclipseNSISStartup.getResourceString("job.name"); //$NON-NLS-1$ mDialogTitleFormat = new MessageFormat(EclipseNSISStartup.getResourceString("dialog.title.format")); //$NON-NLS-1$ mDialogMessageFormat = new MessageFormat(EclipseNSISStartup.getResourceString("dialog.message.format")); //$NON-NLS-1$ mDialogToggleMessageFormat = new MessageFormat(EclipseNSISStartup.getResourceString("dialog.toggle.message.format")); //$NON-NLS-1$ final IExtensionTracker tracker = PlatformUI.getWorkbench().getExtensionTracker(); loadExtensions(tracker); tracker.registerHandler(this, ExtensionTracker.createExtensionPointFilter(getExtensionPointFilter())); final BundleContext bundleContext = EclipseNSISStartup.getDefault().getBundleContext(); bundleContext.addBundleListener(new BundleListener() { public void bundleChanged(BundleEvent event) { if(event.getType() == BundleEvent.STOPPED ) { bundleContext.removeBundleListener(this); } tracker.unregisterHandler(FileAssociationChecker.this); Job.getJobManager().cancel(JOB_FAMILY); } }); }
private void addBundlerListener(BundleContext context) { // Listen for our STARTED event // Alternatively, we can get the bundle from org.osgi.framework.FrameworkUtil context.addBundleListener(new BundleListener() { public void bundleChanged(BundleEvent event) { String name = event.getBundle().getSymbolicName(); if (name != null && name.equals(PLUGIN_ID)) { switch (event.getType()) { case BundleEvent.STARTED: bundleStarted(); break; case BundleEvent.UNINSTALLED: emacsIds = null; break; default: break; } } } }); }
/** * Constructs a new <code>MockBundleContext</code> instance allowing both * the bundle and the context properties to be specified. * * @param bundle associated bundle * @param props context properties */ public MockBundleContext(Bundle bundle, Properties props) { this.bundle = (bundle == null ? new MockBundle(this) : bundle); properties = new Properties(DEFAULT_PROPERTIES); if (props != null) properties.putAll(props); // make sure the order is preserved this.serviceListeners = new LinkedHashSet<ServiceListener>(2); this.bundleListeners = new LinkedHashSet<BundleListener>(2); }
/** * Constructor. * * @param context * the {@link BundleContext} * @param classLoader * the fall back {@link ClassLoader} */ public EclipseClassProvider(BundleContext context, ClassLoader classLoader) { super(classLoader); this.context = context; for (Bundle bundle : context.getBundles()) { bundles.put(bundle.getSymbolicName(), bundle); } listener = new BundleListener() { @Override public void bundleChanged(BundleEvent event) { switch (event.getType()) { case BundleEvent.INSTALLED: bundles.put(event.getBundle().getSymbolicName(), event.getBundle()); break; case BundleEvent.UNINSTALLED: bundles.remove(event.getBundle().getSymbolicName()); break; default: // nothing to do here break; } } }; context.addBundleListener(listener); }
/** * Starts the OSGi bundle by registering the engine with the bundle of the * Restlet API. * * @param context * The bundle context. */ public void start(BundleContext context) throws Exception { org.restlet.engine.Engine.register(false); // Discover helpers in installed bundles and start // the bundle if necessary for (final Bundle bundle : context.getBundles()) { registerHelpers(bundle); } // Listen to installed bundles context.addBundleListener(new BundleListener() { public void bundleChanged(BundleEvent event) { switch (event.getType()) { case BundleEvent.INSTALLED: registerHelpers(event.getBundle()); break; case BundleEvent.UNINSTALLED: break; } } }); Engine.getInstance().registerDefaultConnectors(); Engine.getInstance().registerDefaultAuthentications(); Engine.getInstance().registerDefaultConverters(); }
@Override public void afterPropertiesSet() throws Exception { Assert.notNull(context); Assert.notNull(serviceStateManager); Assert.notNull(serviceFactoryImpl); dataServiceTracker = new ServiceTracker(context, BaseDataService.class.getName(), new DataServiceTrackerCustomizer()); serviceInterceptorTracker = new ServiceTracker(context, ServiceInterceptor.class.getName(), new ServiceInterceptorTrackerCustomizer()); dataServiceTracker.open(true); serviceInterceptorTracker.open(true); context.addBundleListener(new BundleListener() { @Override public void bundleChanged(BundleEvent event) { if (event.getType() == BundleEvent.UNINSTALLED) { String name = event.getBundle().getSymbolicName(); try { logger.info("uninstall bundle " + name); zookeeper.deleteNodeByBundle(name); ServiceWatcher.this.nodeUpdate(); } catch (Exception e) { logger.error( "zookeeper delete service by bundle, bundle name : " + name, e); } } } }); logger.info("服务监听启动"); }
/** * Starts the framework. There is usually no reason to call this method manually because it will * be invoked automatically by the {@link #initializationComplete()} callback. * * @throws BundleException * Exception. */ public synchronized void start() throws BundleException { if (this.framework == null) { this.prepareFramework(); } for (BundleListener listener : listeners) { framework.getBundleContext().addBundleListener(listener); } framework.start(); fileInstall.updated("initial", propertiesDictionary); }
void registerListener(Framework f) { f.getBundleContext().addBundleListener(new BundleListener() { @Override public void bundleChanged(BundleEvent e) { Log.d(TAG, "bundleChanged. event:" + e); } }); }
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); } }
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; } }
/** * {@inheritDoc} */ @Override public void earlyStartup() { // check if plug-in org.eclipse.jdt.ui is final already active final Bundle bundle = Platform.getBundle(JAVA_PLUGIN_ID); if (bundle != null && bundle.getState() == Bundle.ACTIVE) { registerResolvers(); } else { // register listener to final get informed, when plug-in final becomes // active final BundleContext bundleContext = Activator.getDefault().getBundle().getBundleContext(); bundleContext.addBundleListener(new BundleListener() { @Override public void bundleChanged(final BundleEvent pEvent) { final Bundle eventBundle = pEvent.getBundle(); if (!eventBundle.getSymbolicName().equals(JAVA_PLUGIN_ID)) { // ignore other plugins return; } if (eventBundle.getState() == Bundle.ACTIVE) { registerResolvers(); bundleContext.removeBundleListener(this); } } }); } }
@Activate void activate(BundleContext context){ context.addBundleListener(new BundleListener() { @Override public void bundleChanged(BundleEvent event) { long bundleId = event.getBundle().getBundleId(); if(event.getType() == BundleEvent.STOPPING || event.getType() == BundleEvent.UPDATED){ Iterator<Entry<String, CompositeType>> it = supportedModules.entrySet().iterator(); while(it.hasNext()){ if(it.next().getValue().providingBundle==bundleId){ it.remove(); } } } if(event.getType() == BundleEvent.STARTED || event.getType() == BundleEvent.UPDATED){ searchCompositeTypes(event.getBundle()); } } }); for(Bundle b : context.getBundles()){ try { searchCompositeTypes(b); } catch(Throwable t){ t.printStackTrace(); } } }
@Override public void start(final BundleContext context) throws Exception { BundleContextClassLoaderRegisterer.registerClassLoaders(context, includePath); final Bundle bundle = context.getBundle(); context.addBundleListener(new BundleListener() { @Override public void bundleChanged(final BundleEvent event) { if (event.getBundle().equals(bundle) && BundleEvent.STARTED == event.getType()) { bundleStartet(); } } }); }
@Override public void start(final BundleContext context) throws Exception { final Bundle bundle = context.getBundle(); context.addBundleListener(new BundleListener() { @Override public void bundleChanged(final BundleEvent event) { if (event.getBundle().equals(bundle) && BundleEvent.STARTED == event.getType()) { bundleStartet(); } } }); }
@Test public void start() throws Exception { BundleContext mockBundleContext = mock( BundleContext.class ); this.activator.start( mockBundleContext ); verify( mockBundleContext, times( 1 ) ).registerService( eq( PentahoWebPackageService.class ), any( PentahoWebPackageService.class ), any() ); verify( mockBundleContext, times( 1 ) ).addBundleListener( any( BundleListener.class ) ); }
public static void registerListener(Framework f) { f.getBundleContext().addBundleListener(new BundleListener(){ @Override public void bundleChanged(BundleEvent e) { Log.d(TAG, "bundleChanged. e:" + e); }}); }
@Override public void init(BundleContext ctx, DependencyManager mgr) throws Exception { mgr.add(createComponent().setInterface(new String[] { BundleListener.class.getName(), FrameworkStateService.class.getName() }, null) .setImplementation(EntropyBasedFrameworkStateService.class) .add(createServiceDependency().setService(FrameworkStateListener.class) .setCallbacks("listenerAdded", null, "listenerRemoved", null)) .add(createServiceDependency().setService("(objectClass=*)") .setCallbacks("serviceAdded", null, "serviceRemoved", "serviceSwapped"))); }
private ModuleListener adaptBundleListener(BundleListener listener) { if (listener instanceof SynchronousBundleListener) { return new SynchronousBundleListenerAdaptor(listener); } else { return new BundleListenerAdaptor(listener); } }
private BundleListener adaptModuleListener(ModuleListener listener) { if (listener instanceof SynchronousModuleListener) { return new SynchronousModuleListenerAdaptor(listener); } else { return new ModuleListenerAdaptor(listener); } }
public void addBundleListener(BundleListener bl) { }
public void removeBundleListener(BundleListener bl) { }
public void removeBundleListener(BundleListener bl) { delegate.removeBundleListener(bl); }
public void addBundleListener(BundleListener bl) { delegate.addBundleListener(bl); }
static void addBundleListener(BundleListener listener) { bundleListeners.add(listener); }
static void removeBundleListener(BundleListener listener) { bundleListeners.remove(listener); }
public void addBundleListener(BundleListener listener) { bundleListeners.add(listener); }
public void removeBundleListener(BundleListener listener) { bundleListeners.remove(listener); }
static void addBundleListener(BundleListener bundleListener) { bundleListeners.add(bundleListener); }
static void removeBundleListener(BundleListener bundleListener) { bundleListeners.remove(bundleListener); }
public void addBundleListener(BundleListener bundleListener) { Framework.addBundleListener(bundleListener); }
public void removeBundleListener(BundleListener bundleListener) { Framework.removeBundleListener(bundleListener); }
public void addBundleListener( BundleListener arg0 ) { }
public void removeBundleListener( BundleListener arg0 ) { }
@Test public void testAfterPropertiesSet() throws Exception { service.afterPropertiesSet(); verify(mockBundleContext).addBundleListener(any(BundleListener.class)); }