Package org.osgi.framework

Examples of org.osgi.framework.ServiceListener


            Configuration[] configs = configAdmin.get().listConfigurations("(|(service.factoryPid=io.fabric8.zookeeper.server)(service.pid=io.fabric8.zookeeper))");
            File karafData = new File(data);

            // Setup the listener for unregistration of {@link BootstrapConfiguration}
            final CountDownLatch unregisterLatch = new CountDownLatch(1);
            ServiceListener listener = new ServiceListener() {
                @Override
                public void serviceChanged(ServiceEvent event) {
                    if (event.getType() == ServiceEvent.UNREGISTERING) {
                        LOGGER.debug("Unregistering BootstrapConfiguration");
                        syscontext.removeServiceListener(this);
                        unregisterLatch.countDown();
                    }
                }
            };
            String filter = "(objectClass=" + BootstrapConfiguration.class.getName() + ")";
            // FABRIC-1052: register listener using the same bundle context that is used for listeners related to SCR
            bootConfig.getComponentContext().getBundleContext().addServiceListener(listener, filter);

            // Disable the BootstrapConfiguration component
            LOGGER.debug("Disable BootstrapConfiguration");
            ComponentContext componentContext = bootConfig.getComponentContext();
            componentContext.disableComponent(BootstrapConfiguration.COMPONENT_NAME);

            if (!unregisterLatch.await(30, TimeUnit.SECONDS))
                throw new TimeoutException("Timeout for unregistering BootstrapConfiguration service");

            // Do the cleanup
            runtimeProps.clearRuntimeAttributes();
            cleanConfigurations(configs);
            cleanZookeeperDirectory(karafData);
            cleanGitDirectory(karafData);

            // Setup the registration listener for the new {@link BootstrapConfiguration}
            final CountDownLatch registerLatch = new CountDownLatch(1);
            final AtomicReference<ServiceReference<?>> sref = new AtomicReference<ServiceReference<?>>();
            listener = new ServiceListener() {
                @Override
                public void serviceChanged(ServiceEvent event) {
                    if (event.getType() == ServiceEvent.REGISTERED) {
                        LOGGER.debug("Registered BootstrapConfiguration");
                        syscontext.removeServiceListener(this);
View Full Code Here


        pendingArtifacts.add(file.getAbsolutePath());
        if (listener == null) {
            try {
                executor = Executors.newSingleThreadExecutor();
                String filter = "(" + Constants.OBJECTCLASS + "=" + DeploymentListener.class.getName() + ")";
                listener = new ServiceListener() {
                    public void serviceChanged(ServiceEvent event) {
                        executor.execute(new Runnable() {
                            public void run() {
                                onFilesChanged(pendingArtifacts);
                            }
View Full Code Here

        public CommandTracker() throws Exception {
            BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
            if (context == null) {
                throw new IllegalStateException("Bundle is stopped");
            }
            ServiceListener listener = new ServiceListener() {
                public void serviceChanged(ServiceEvent event) {
                    commands.clear();
                }
            };
            context.addServiceListener(listener,
View Full Code Here

        public CommandTracker() throws Exception {
            BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext();
            if (context == null) {
                throw new IllegalStateException("Bundle is stopped");
            }
            ServiceListener listener = new ServiceListener() {
                public void serviceChanged(ServiceEvent event) {
                    synchronized (CommandsCompleter.this) {
                        commands.clear();
                    }
                }
View Full Code Here

    counter.increment();

    String filter = "(org.springframework.context.service.name=" + forBundleWithSymbolicName + ")";

    ServiceListener listener = new ServiceListener() {

      public void serviceChanged(ServiceEvent event) {
        if (event.getType() == ServiceEvent.REGISTERED)
          counter.decrement();
      }
View Full Code Here

    ServiceRegistration reg = bundleContext.registerService(Shape.class.getName(), service, null);

    String filter = OsgiFilterUtils.unifyFilter(Shape.class, null);

    ServiceListener listener = new ServiceListener() {

      public void serviceChanged(ServiceEvent event) {
        if (ServiceEvent.UNREGISTERING == event.getType()) {
          ServiceReference ref = event.getServiceReference();
          Object aliveService = bundleContext.getService(ref);
View Full Code Here

   * {@link org.springframework.osgi.util.OsgiListenerUtils#addServiceListener(org.osgi.framework.BundleContext, org.osgi.framework.ServiceListener, java.lang.String)}.
   */
  public void testAddServiceListenerBundleContextServiceListenerString() {
    final List refs = new ArrayList();

    ServiceListener list = new ServiceListener() {

      public void serviceChanged(ServiceEvent event) {
        if (ServiceEvent.REGISTERED == event.getType())
          refs.add(event.getSource());
      }
View Full Code Here

   * {@link org.springframework.osgi.util.OsgiListenerUtils#addSingleServiceListener(org.osgi.framework.BundleContext, org.osgi.framework.ServiceListener, java.lang.String)}.
   */
  public void testAddSingleServiceListenerBundleContextServiceListenerString() {
    final List refs = new ArrayList();

    ServiceListener listener = new ServiceListener() {

      public void serviceChanged(ServiceEvent event) {
        if (ServiceEvent.REGISTERED == event.getType())
          refs.add(event.getSource());
      }
View Full Code Here

  /**
   * Test method for
   * {@link org.springframework.osgi.util.OsgiListenerUtils#removeServiceListener(org.osgi.framework.BundleContext, org.osgi.framework.ServiceListener)}.
   */
  public void testRemoveServiceListenerBundleContextServiceListener() {
    ServiceListener listener = new ServiceListener() {

      public void serviceChanged(ServiceEvent event) {
      }
    };

View Full Code Here

    Collection col = (Collection) serviceFactoryBean.getObject();

    assertFalse(col.isEmpty());
    Set listeners = bundleContext.getServiceListeners();

    ServiceListener list = (ServiceListener) listeners.iterator().next();
    list.serviceChanged(new ServiceEvent(ServiceEvent.UNREGISTERING, ref));

    try {
      // disable filter
      col.isEmpty();
      fail("should have thrown exception");
View Full Code Here

TOP

Related Classes of org.osgi.framework.ServiceListener

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.