@Test
  public void testContainsKey() {
    try (ServiceTrackerMap<String, TrackedOne> serviceTrackerMap = createServiceTrackerMap()) {

      ServiceRegistration<TrackedOne> serviceRegistration1 =
          registerService(new TrackedOne(), "aTarget1");
      ServiceRegistration<TrackedOne> serviceRegistration2 =
          registerService(new TrackedOne(), "aTarget1");
      ServiceRegistration<TrackedOne> serviceRegistration3 =
          registerService(new TrackedOne(), "aTarget2");
      ServiceRegistration<TrackedOne> serviceRegistration4 =
          registerService(new TrackedOne(), "aTarget2");

      Assert.assertTrue(serviceTrackerMap.containsKey("aTarget1"));
      Assert.assertTrue(serviceTrackerMap.containsKey("aTarget2"));
      Assert.assertFalse(serviceTrackerMap.containsKey("aTarget3"));
      Assert.assertFalse(serviceTrackerMap.containsKey(""));

      try {
        serviceTrackerMap.containsKey(null);

        Assert.fail();
      } catch (NullPointerException npe) {
      }

      serviceRegistration1.unregister();
      serviceRegistration2.unregister();
      serviceRegistration3.unregister();
      serviceRegistration4.unregister();
    }
  }
  /** @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) */
  public void stop(BundleContext bundleContext) {
    // shut down the trackers.
    m_eventAdmin.destroy();

    // Clean up the listeners.
    bundleContext.removeBundleListener(m_frameworkHandler);
    bundleContext.removeFrameworkListener(m_frameworkHandler);
    bundleContext.removeServiceListener(m_frameworkHandler);

    // Remove the global handler for all JDK Logging (java.util.logging).
    if (m_JdkHandler != null) {
      Logger rootLogger = LogManager.getLogManager().getLogger("");
      rootLogger.removeHandler(m_JdkHandler);
      m_JdkHandler.flush();
      m_JdkHandler.close();
      m_JdkHandler = null;
    }

    m_RegistrationPaxLogging.unregister();
    m_RegistrationPaxLogging = null;

    m_registrationLogReaderService.unregister();
    m_registrationLogReaderService = null;

    m_paxLogging.stop();
    m_paxLogging = null;
  }
  @Test
  public void testKeySetReturnsUnmodifiableSet() {
    try (ServiceTrackerMap<String, TrackedOne> serviceTrackerMap = createServiceTrackerMap()) {

      ServiceRegistration<TrackedOne> serviceRegistration1 =
          registerService(new TrackedOne(), "aTarget1");
      ServiceRegistration<TrackedOne> serviceRegistration2 =
          registerService(new TrackedOne(), "aTarget1");
      ServiceRegistration<TrackedOne> serviceRegistration3 =
          registerService(new TrackedOne(), "aTarget2");
      ServiceRegistration<TrackedOne> serviceRegistration4 =
          registerService(new TrackedOne(), "aTarget2");

      Set<String> keySet = serviceTrackerMap.keySet();

      try {
        keySet.remove("aTarget1");

        Assert.fail();
      } catch (UnsupportedOperationException uoe) {
      }

      serviceRegistration1.unregister();
      serviceRegistration2.unregister();
      serviceRegistration3.unregister();
      serviceRegistration4.unregister();
    }
  }
  @Test
  public void testUnkeyedServiceReferencesBalanceRefCount() {
    RegistryWrapper registryWrapper = getRegistryWrapper();

    try (ServiceTrackerMap<TrackedOne, TrackedOne> serviceTrackerMap =
        ServiceTrackerCollections.singleValueMap(
            TrackedOne.class,
            null,
            new ServiceReferenceMapper<TrackedOne, TrackedOne>() {

              @Override
              public void map(
                  ServiceReference<TrackedOne> serviceReference, Emitter<TrackedOne> emitter) {}
            })) {

      serviceTrackerMap.open();

      ServiceRegistration<TrackedOne> serviceRegistration1 = registerService(new TrackedOne());
      ServiceRegistration<TrackedOne> serviceRegistration2 = registerService(new TrackedOne());

      Map<ServiceReference<?>, AtomicInteger> serviceReferenceCountsMap =
          registryWrapper.getServiceReferenceCountsMap();

      Collection<AtomicInteger> serviceReferenceCounts = serviceReferenceCountsMap.values();

      Assert.assertEquals(0, serviceReferenceCounts.size());

      serviceRegistration1.unregister();
      serviceRegistration2.unregister();

      Assert.assertEquals(0, serviceReferenceCounts.size());
    } finally {
      RegistryUtil.setRegistry(registryWrapper.getWrappedRegistry());
    }
  }
  @Test
  public void testKeySet() {
    try (ServiceTrackerMap<String, TrackedOne> serviceTrackerMap = createServiceTrackerMap()) {

      ServiceRegistration<TrackedOne> serviceRegistration1 =
          registerService(new TrackedOne(), "aTarget1");
      ServiceRegistration<TrackedOne> serviceRegistration2 =
          registerService(new TrackedOne(), "aTarget1");
      ServiceRegistration<TrackedOne> serviceRegistration3 =
          registerService(new TrackedOne(), "aTarget2");
      ServiceRegistration<TrackedOne> serviceRegistration4 =
          registerService(new TrackedOne(), "aTarget2");

      Set<String> targets = new HashSet<>();

      targets.add("aTarget1");
      targets.add("aTarget2");

      Assert.assertEquals(targets, serviceTrackerMap.keySet());

      serviceRegistration1.unregister();
      serviceRegistration2.unregister();
      serviceRegistration3.unregister();
      serviceRegistration4.unregister();
    }
  }
  @Test
  public void testObjectClassFilter() throws Exception {
    Bundle bundle = installBundle(getBundleArchiveA());
    try {
      bundle.start();
      BundleContext context = bundle.getBundleContext();
      assertNotNull(context);
      assertNoServiceEvent();

      String filter = "(" + Constants.OBJECTCLASS + "=" + BundleContext.class.getName() + ")";
      context.addServiceListener(this, filter);

      ServiceRegistration sreg =
          context.registerService(BundleContext.class.getName(), context, null);
      ServiceReference sref = sreg.getReference();

      assertServiceEvent(ServiceEvent.REGISTERED, sref);

      sreg.unregister();
      assertServiceEvent(ServiceEvent.UNREGISTERING, sref);

      filter = "(objectClass=dummy)";
      context.addServiceListener(this, filter);

      sreg = context.registerService(BundleContext.class.getName(), context, null);
      assertNoServiceEvent();

      sreg.unregister();
      assertNoServiceEvent();
    } finally {
      bundle.uninstall();
    }
  }
Exemple #7
0
 public void stop(BundleContext bundleContext) throws Exception {
   if (userCredentialsService != null) {
     userCredentialsService.unregister();
   }
   if (userProfileService != null) {
     userProfileService.unregister();
   }
 }
  @Test
  public void testGetServiceWithServiceCustomizer() {
    final Registry registry = RegistryUtil.getRegistry();

    try (ServiceTrackerMap<String, TrackedTwo> serviceTrackerMap =
        ServiceTrackerCollections.singleValueMap(
            TrackedOne.class,
            "target",
            new ServiceTrackerCustomizer<TrackedOne, TrackedTwo>() {

              @Override
              public TrackedTwo addingService(ServiceReference<TrackedOne> serviceReference) {

                return new TrackedTwo(registry.getService(serviceReference));
              }

              @Override
              public void modifiedService(
                  ServiceReference<TrackedOne> serviceReference, TrackedTwo service) {

                removedService(serviceReference, service);
              }

              @Override
              public void removedService(
                  ServiceReference<TrackedOne> serviceReference, TrackedTwo service) {

                registry.ungetService(serviceReference);
              }
            })) {

      serviceTrackerMap.open();

      TrackedOne trackedOne1 = new TrackedOne();

      ServiceRegistration<TrackedOne> serviceRegistration1 =
          registerService(trackedOne1, "trackedOne1");

      TrackedOne trackedOne2 = new TrackedOne();

      ServiceRegistration<TrackedOne> serviceRegistration2 =
          registerService(trackedOne2, "trackedOne2");

      TrackedTwo trackedTwo1 = serviceTrackerMap.getService("trackedOne1");

      Assert.assertEquals(trackedOne1, trackedTwo1.getTrackedOne());

      TrackedTwo trackedTwo2 = serviceTrackerMap.getService("trackedOne2");

      Assert.assertEquals(trackedOne2, trackedTwo2.getTrackedOne());

      serviceRegistration1.unregister();
      serviceRegistration2.unregister();
    }
  }
 private void unregisterEventingService() {
   if (eventingServiceRegistration != null) {
     EventingDataHolder.getInstance().setRegistryEventingService(null);
     eventingServiceRegistration.unregister();
     eventingServiceRegistration = null;
     notificationServiceRegistration.unregister();
     notificationServiceRegistration = null;
     emailVerificationServiceRegistration.unregister();
     emailVerificationServiceRegistration = null;
     service = null;
     log.debug("Successfully unregistered the Eventing OGSi Service");
   }
 }
  @Test
  public void testItemSelectorReturnTypeResolverIsReplacedByServiceRanking() {
    ServiceRegistration<ItemSelectorReturnTypeResolver>
        itemSelectorReturnTypeResolverServiceRegistration1 =
            registerItemSelectorReturnTypeResolver(new TestItemSelectorReturnTypeResolver1(), 100);
    ServiceRegistration<ItemSelectorReturnTypeResolver>
        itemSelectorReturnTypeResolverServiceRegistration2 =
            registerItemSelectorReturnTypeResolver(new TestItemSelectorReturnTypeResolver2(), 200);
    ServiceRegistration<ItemSelectorReturnTypeResolver>
        itemSelectorReturnTypeResolverServiceRegistration3 =
            registerItemSelectorReturnTypeResolver(new TestItemSelectorReturnTypeResolver3(), 50);

    List<ServiceRegistration> serviceRegistrations = new CopyOnWriteArrayList<>();

    serviceRegistrations.add(itemSelectorReturnTypeResolverServiceRegistration1);
    serviceRegistrations.add(itemSelectorReturnTypeResolverServiceRegistration2);
    serviceRegistrations.add(itemSelectorReturnTypeResolverServiceRegistration3);

    try {
      ItemSelectorReturnTypeResolver itemSelectorReturnTypeResolver =
          _itemSelectorReturnTypeResolverHandler.getItemSelectorReturnTypeResolver(
              TestItemSelectorReturnType.class, String.class);

      Assert.assertTrue(
          itemSelectorReturnTypeResolver instanceof TestItemSelectorReturnTypeResolver2);

      serviceRegistrations.remove(itemSelectorReturnTypeResolverServiceRegistration2);

      itemSelectorReturnTypeResolverServiceRegistration2.unregister();

      itemSelectorReturnTypeResolver =
          _itemSelectorReturnTypeResolverHandler.getItemSelectorReturnTypeResolver(
              TestItemSelectorReturnType.class, String.class);

      Assert.assertTrue(
          itemSelectorReturnTypeResolver instanceof TestItemSelectorReturnTypeResolver1);

      serviceRegistrations.remove(itemSelectorReturnTypeResolverServiceRegistration1);

      itemSelectorReturnTypeResolverServiceRegistration1.unregister();

      itemSelectorReturnTypeResolver =
          _itemSelectorReturnTypeResolverHandler.getItemSelectorReturnTypeResolver(
              TestItemSelectorReturnType.class, String.class);

      Assert.assertTrue(
          itemSelectorReturnTypeResolver instanceof TestItemSelectorReturnTypeResolver3);
    } finally {
      _unregister(serviceRegistrations);
    }
  }
  @Override
  public void stop(BundleContext context) throws Exception {
    if (filterReg != null) {
      filterReg.unregister();
    }

    if (bundle1ServletReg != null) {
      bundle1ServletReg.unregister();
    }

    if (httpContextReg != null) {
      httpContextReg.unregister();
    }
  }
 public void stop(BundleContext context) throws Exception {
   if (embeddedService != null) {
     embeddedService.unregister();
   }
   if (clientService != null) {
     clientService.unregister();
   }
   if (embeddedService4 != null) {
     embeddedService4.unregister();
   }
   if (clientService4 != null) {
     clientService4.unregister();
   }
 }
Exemple #13
0
 public void stop(BundleContext context1) throws Exception {
   if (socketFactoryRegistration != null) {
     socketFactoryRegistration.unregister();
     socketFactoryRegistration = null;
   }
   if (serverSocketFactoryRegistration != null) {
     serverSocketFactoryRegistration.unregister();
     serverSocketFactoryRegistration = null;
   }
   if (trustEngineTracker != null) {
     trustEngineTracker.close();
     trustEngineTracker = null;
   }
   ECFTrustManager.context = null;
 }
  @Test
  public void testGetServiceWithCustomResolver() {
    try (ServiceTrackerMap<String, TrackedOne> serviceTrackerMap =
        ServiceTrackerCollections.singleValueMap(
            TrackedOne.class,
            "(&(other=*)(target=*))",
            new ServiceReferenceMapper<String, TrackedOne>() {

              @Override
              public void map(ServiceReference<TrackedOne> serviceReference, Emitter<String> keys) {

                keys.emit(
                    serviceReference.getProperty("other")
                        + " - "
                        + serviceReference.getProperty("target"));
              }
            })) {

      serviceTrackerMap.open();

      Dictionary<String, String> properties = new Hashtable<>();

      properties.put("other", "aProperty");
      properties.put("target", "aTarget");

      ServiceRegistration<TrackedOne> serviceRegistration =
          _bundleContext.registerService(TrackedOne.class, new TrackedOne(), properties);

      Assert.assertNotNull(serviceTrackerMap.getService("aProperty - aTarget"));

      serviceRegistration.unregister();
    }
  }
  /**
   * Removes the specified account from the list of accounts that this provider factory is handling.
   * If the specified accountID is unknown to the ProtocolProviderFactory, the call has no effect
   * and false is returned. This method is persistent in nature and once called the account
   * corresponding to the specified ID will not be loaded during future runs of the project.
   *
   * @param accountID the ID of the account to remove.
   * @return true if an account with the specified ID existed and was removed and false otherwise.
   */
  public boolean uninstallAccount(AccountID accountID) {
    // unregister the protocol provider
    ServiceReference serRef = getProviderForAccount(accountID);

    if (serRef == null) return false;

    ProtocolProviderService protocolProvider =
        (ProtocolProviderService) SipActivator.getBundleContext().getService(serRef);

    try {
      protocolProvider.unregister();
    } catch (OperationFailedException e) {
      logger.error(
          "Failed to unregister protocol provider for account : "
              + accountID
              + " caused by : "
              + e);
    }

    ServiceRegistration registration = (ServiceRegistration) registeredAccounts.remove(accountID);

    if (registration == null) return false;

    // kill the service
    registration.unregister();

    return removeStoredAccount(SipActivator.getBundleContext(), accountID);
  }
 @Override
 public void dispose() {
   if (serviceRegistration != null) {
     serviceRegistration.unregister();
   }
   super.dispose();
 }
 /**
  * unregisters the Engines service registration, closes the SolrCore and rests the fields. If no
  * engine is registered this does nothing!
  */
 private void unregisterEngine() {
   // use local copies for method calls to avoid concurrency issues
   ServiceRegistration engineRegistration = this.engineRegistration;
   if (engineRegistration != null) {
     log.info(" ... unregister Lucene FSTLinkingEngine {}", engineName);
     engineRegistration.unregister();
     this.engineRegistration = null; // reset the field
   }
   solrServerReference = null;
   SolrCore solrServer = this.solrCore;
   if (solrServer != null) {
     log.debug(" ... unregister SolrCore {}", solrServer.getName());
     solrServer.close(); // decrease the reference count!!
     this.solrCore = null; // rest the field
   }
   // deactivate the index configuration if present
   if (indexConfig != null) {
     log.debug(" ... deactivate IndexingConfiguration");
     indexConfig.deactivate();
     // close the EntityCacheManager (if present
     EntityCacheManager cacheManager = indexConfig.getEntityCacheManager();
     if (cacheManager != null) {
       log.debug(" ... deactivate {}", cacheManager.getClass().getSimpleName());
       cacheManager.close();
     }
     indexConfig = null;
   }
 }
 /**
  * unregister the remote service.
  *
  * @see org.eclipse.ecf.remoteservice.IRemoteServiceRegistration#unregister()
  */
 public void unregister() {
   try {
     reg.unregister();
   } catch (IllegalStateException e) {
     // underlying service registration already unregistered
   }
 }
  public void testGetExtHttpService() {
    final BundleContext bundleContext = getContext();
    assertNotNull(bundleContext);
    final ExtHttpServiceMock extHttpService = new ExtHttpServiceMock(new UrlUtilImpl());
    assertNotNull(extHttpService);
    // zum start: keine Dienste registriert
    assertEquals(0, extHttpService.getRegisterFilterCallCounter());
    assertEquals(0, extHttpService.getRegisterServletCallCounter());
    assertEquals(0, extHttpService.getUnregisterFilterCallCounter());
    assertEquals(0, extHttpService.getUnregisterServletCallCounter());
    final ServiceRegistration serviceRegistration =
        bundleContext.registerService(ExtHttpService.class.getName(), extHttpService, null);
    assertNotNull(serviceRegistration);
    // nach start: Dienste vorhanden?
    assertTrue("no filters registered", extHttpService.getRegisterFilterCallCounter() > 0);
    assertTrue("no servlets registered.", extHttpService.getRegisterServletCallCounter() > 0);
    assertEquals(0, extHttpService.getUnregisterFilterCallCounter());
    assertEquals(0, extHttpService.getUnregisterServletCallCounter());

    // do unregister
    serviceRegistration.unregister();

    assertTrue("no servlets unregistered", extHttpService.getUnregisterServletCallCounter() > 0);
    assertEquals(
        extHttpService.getRegisterServletCallCounter(),
        extHttpService.getRegisterServletCallCounter());
    assertEquals(
        extHttpService.getRegisterFilterCallCounter(),
        extHttpService.getUnregisterFilterCallCounter());
  }
 /*
  * (non-Javadoc)
  *
  * @see
  * org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
  */
 @Override
 public void stop(final BundleContext aContext) throws Exception {
   if (pRegistration != null) {
     pRegistration.unregister();
     pRegistration = null;
   }
 }
 @Override
 public void stop(StopContext context) {
   super.stop(context);
   registration.unregister();
   registration = null;
   delegate = null;
 }
Exemple #22
0
  /** Called whenever the OSGi framework stops our bundle */
  @Override
  public void stop(BundleContext bc) throws Exception {
    context = null;

    if (sseFeatureRegistration != null) {
      sseFeatureRegistration.unregister();
      logger.debug("SseFeature unregistered.");
    }

    if (blockingAsyncFeatureRegistration != null) {
      blockingAsyncFeatureRegistration.unregister();
      logger.debug("BlockingAsyncFeature unregistered.");
    }

    logger.debug("SSE API has been stopped.");
  }
 protected void deactivate(ComponentContext context) {
   if (infoServiceRegistration != null) {
     infoServiceRegistration.unregister();
     infoServiceRegistration = null;
   }
   log.debug("******* Registry Info UI Management bundle is deactivated ******* ");
 }
  @Override
  public void removeContext(final HttpContext httpContext) {
    LOG.debug("remove context [{}]", httpContext);

    try {
      if (servletContextService != null) {
        servletContextService.unregister();
      }
    } catch (final IllegalStateException e) {
      LOG.info("ServletContext service already removed");
    }

    final Context context = m_contexts.remove(httpContext);
    this.m_server.getHost().removeChild(context);
    if (context == null) {
      throw new RemoveContextException(
          "cannot remove the context because it does not exist: " + httpContext);
      // LOG.warn("cannot remove the context because it does not exist: {}"
      // , httpContext );
      // return;
    }
    try {
      final LifecycleState state = context.getState();
      if (LifecycleState.DESTROYED != state || LifecycleState.DESTROYING != state) {
        context.destroy();
      }
    } catch (final LifecycleException e) {
      throw new RemoveContextException("cannot destroy the context: " + httpContext, e);
      // LOG.warn("cannot destroy the context: " + httpContext);
    }
  }
 @Override
 protected void destory(int arg) {
   servletFilterBridgeServiceRegistration.unregister();
   // 停止时,保存相关运行时状态到ServletContext中。
   WebContext.getServletContext()
       .setAttribute(QUICKWEBFRAMEWORK_STATE_FILTERCONFIG, getFilterConfig());
 }
Exemple #26
0
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.core.runtime.Plugin#stop(org.osgi.framework.BundleContext)
   */
  public void stop(final BundleContext context) throws Exception {
    // TODO-mkuppe here we should do something like a deregisterAll(), but see ungetService(...);
    if (serviceRegistration != null && serviceFactory.isActive()) {
      ServiceReference reference = serviceRegistration.getReference();
      IDiscoveryLocator aLocator = (IDiscoveryLocator) context.getService(reference);

      serviceRegistration.unregister();

      IContainer container = (IContainer) aLocator.getAdapter(IContainer.class);
      container.disconnect();
      container.dispose();

      serviceRegistration = null;
    }
    plugin = null;
    bundleContext = null;
    if (advertiserSt != null) {
      advertiserSt.close();
      advertiserSt = null;
    }
    if (locatorSt != null) {
      locatorSt.close();
      locatorSt = null;
    }
  }
  @Override
  public void stop(BundleContext arg0) throws Exception {
    wrapper.disconnect();
    wrapperRegistration.unregister();

    System.out.println("MyCampus wrapper service has stopped");
  }
 @Deactivate
 void deactivate(BundleContext bundleContext) {
   super.deactivate(bundleContext);
   if (registration != null) {
     registration.unregister();
   }
 }
Exemple #29
0
 @Override
 public void stop(BundleContext bc) throws Exception {
   ctx = null;
   if (serverConfigurationListener != null) {
     serverConfigurationListener.unregister();
     serverConfigurationListener = null;
   }
 }
 @Override
 protected void doStop() throws Exception {
   if (registration != null) {
     registration.unregister();
   }
   executor.shutdown();
   super.doStop();
 }