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

项目:atlas    文件:Framework.java   
/**
 * 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);
    }
}
项目:ACDD    文件:Framework.java   
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);
                }

            }
        }
    }
项目:AtlasForAndroid    文件:Framework.java   
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++;
            }
        }
    }
}
项目:pentaho-osgi-bundles    文件:ActivatorTest.java   
@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() ) );
}
项目:eclipsensis    文件:FileAssociationChecker.java   
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);
        }
    });
}
项目:e4macs    文件:EmacsPlusActivator.java   
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;
                }
            }
        }
    });
}
项目:gemini.blueprint    文件:MockBundleContext.java   
/**
 * 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);
}
项目:M2Doc    文件:EclipseClassProvider.java   
/**
 * 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);
}
项目:restlet-framework    文件:Activator.java   
/**
 * 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();
}
项目:osmp    文件:ServiceWatcher.java   
@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("服务监听启动");
}
项目:communote-server    文件:OSGiManagement.java   
/**
 * 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);
}
项目:ApkLauncher    文件:FrameworkHelper.java   
void registerListener(Framework f) {
    f.getBundleContext().addBundleListener(new BundleListener() {

        @Override
        public void bundleChanged(BundleEvent e) {
            Log.d(TAG, "bundleChanged. event:" + e);

        }
    });
}
项目: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;
    }
}
项目:eclipse-templatevariables    文件:TemplateVariablesStartup.java   
/**
 * {@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);
        }
      }
    });
  }
}
项目:dianne    文件:CompositeModuleFactory.java   
@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();
        }
    }
}
项目:jo-widgets    文件:ClassLoadingActivator.java   
@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();
            }
        }
    });
}
项目:jo-widgets    文件:OsgiApplicationRunner.java   
@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();
            }
        }
    });
}
项目:jo-widgets    文件:OsgiWorkbenchRunner.java   
@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();
            }
        }
    });
}
项目:pentaho-osgi-bundles    文件:ActivatorTest.java   
@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 ) );
}
项目:felix-on-android    文件:FelixWrapper.java   
public static void registerListener(Framework f) {
    f.getBundleContext().addBundleListener(new BundleListener(){

        @Override
        public void bundleChanged(BundleEvent e) {
            Log.d(TAG, "bundleChanged. e:" + e);

        }});
}
项目:osgitest    文件:Activator.java   
@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")));
}
项目:gravia    文件:BundleContextAdaptor.java   
private ModuleListener adaptBundleListener(BundleListener listener) {
    if (listener instanceof SynchronousBundleListener) {
        return new SynchronousBundleListenerAdaptor(listener);
    } else {
        return new BundleListenerAdaptor(listener);
    }
}
项目:gravia    文件:ModuleContextAdaptor.java   
private BundleListener adaptModuleListener(ModuleListener listener) {
    if (listener instanceof SynchronousModuleListener) {
        return new SynchronousModuleListenerAdaptor(listener);
    } else {
        return new ModuleListenerAdaptor(listener);
    }
}
项目:incubator-netbeans    文件:NetigsoSelfQueryTest.java   
public void addBundleListener(BundleListener bl) {
}
项目:incubator-netbeans    文件:NetigsoSelfQueryTest.java   
public void removeBundleListener(BundleListener bl) {
}
项目:incubator-netbeans    文件:Netbinox.java   
public void removeBundleListener(BundleListener bl) {
    delegate.removeBundleListener(bl);
}
项目:incubator-netbeans    文件:Netbinox.java   
public void addBundleListener(BundleListener bl) {
    delegate.addBundleListener(bl);
}
项目:atlas    文件:Framework.java   
static void addBundleListener(BundleListener listener) {
    bundleListeners.add(listener);
}
项目:atlas    文件:Framework.java   
static void removeBundleListener(BundleListener listener) {
    bundleListeners.remove(listener);
}
项目:gemini.blueprint    文件:MockBundleContext.java   
public void addBundleListener(BundleListener listener) {
    bundleListeners.add(listener);
}
项目:gemini.blueprint    文件:MockBundleContext.java   
public void removeBundleListener(BundleListener listener) {
    bundleListeners.remove(listener);
}
项目:ACDD    文件:Framework.java   
static void addBundleListener(BundleListener bundleListener) {
    bundleListeners.add(bundleListener);
}
项目:ACDD    文件:Framework.java   
static void removeBundleListener(BundleListener bundleListener) {
    bundleListeners.remove(bundleListener);
}
项目:ACDD    文件:ACDD.java   
public void addBundleListener(BundleListener bundleListener) {
    Framework.addBundleListener(bundleListener);
}
项目:ACDD    文件:ACDD.java   
public void removeBundleListener(BundleListener bundleListener) {
    Framework.removeBundleListener(bundleListener);
}
项目:osgi-in-action    文件:MockBundleContext.java   
public void addBundleListener( BundleListener arg0 )
{
}
项目:osgi-in-action    文件:MockBundleContext.java   
public void removeBundleListener( BundleListener arg0 )
{
}
项目:eHMP    文件:HmpPluginServiceTests.java   
@Test
public void testAfterPropertiesSet() throws Exception {
    service.afterPropertiesSet();
    verify(mockBundleContext).addBundleListener(any(BundleListener.class));
}
项目:AtlasForAndroid    文件:Atlas.java   
public void addBundleListener(BundleListener bundleListener) {
    Framework.addBundleListener(bundleListener);
}