Package org.osgi.framework

Examples of org.osgi.framework.ServiceListener


    event = new ServiceEvent(ServiceEvent.REGISTERED, ref);

    services.put(ref, service);

    for (Iterator iter = context.getServiceListeners().iterator(); iter.hasNext();) {
      ServiceListener listener = (ServiceListener) iter.next();
      listener.serviceChanged(event);
    }
  }
View Full Code Here


    services.remove(ref);

    ServiceEvent event = new ServiceEvent(ServiceEvent.UNREGISTERING, ref);

    for (Iterator iter = context.getServiceListeners().iterator(); iter.hasNext();) {
      ServiceListener listener = (ServiceListener) iter.next();
      listener.serviceChanged(event);
    }

  }
View Full Code Here

    interceptor.afterPropertiesSet();

    assertEquals(1, SimpleTargetSourceLifecycleListener.BIND);
    assertEquals(0, SimpleTargetSourceLifecycleListener.UNBIND);

    ServiceListener sl = (ServiceListener) bundleContext.getServiceListeners().iterator().next();

    // save old ref and invalidate it so new services are not found
    ServiceReference oldRef = refs[0];
    refs = null;

    sl.serviceChanged(new ServiceEvent(ServiceEvent.UNREGISTERING, oldRef));

    assertEquals(1, SimpleTargetSourceLifecycleListener.BIND);
    assertEquals(1, SimpleTargetSourceLifecycleListener.UNBIND);
  }
View Full Code Here

  }

  public void testRebindWhenNewServiceAppears() {
    interceptor.afterPropertiesSet();

    ServiceListener sl = (ServiceListener) bundleContext.getServiceListeners().iterator().next();

    Dictionary props = new Hashtable();
    // increase service ranking
    props.put(Constants.SERVICE_RANKING, new Integer(10));

    ServiceReference ref = new MockServiceReference(null, props, null);

    ServiceEvent event = new ServiceEvent(ServiceEvent.REGISTERED, ref);

    assertEquals(1, SimpleTargetSourceLifecycleListener.BIND);
    assertEquals(0, SimpleTargetSourceLifecycleListener.UNBIND);

    sl.serviceChanged(event);

    assertEquals(2, SimpleTargetSourceLifecycleListener.BIND);
    assertEquals(0, SimpleTargetSourceLifecycleListener.UNBIND);
  }
View Full Code Here

    interceptor.afterPropertiesSet();

    assertEquals(1, SimpleTargetSourceLifecycleListener.BIND);
    assertEquals(0, SimpleTargetSourceLifecycleListener.UNBIND);

    ServiceListener sl = (ServiceListener) bundleContext.getServiceListeners().iterator().next();

    // unregister the old service
    sl.serviceChanged(new ServiceEvent(ServiceEvent.UNREGISTERING, refs[0]));

    // a new one is found since the mock context will return one again
    assertEquals(2, SimpleTargetSourceLifecycleListener.BIND);
    assertEquals(0, SimpleTargetSourceLifecycleListener.UNBIND);
  }
View Full Code Here

    config.update(properties);
   
    String filter = "(" + Constants.SERVICE_PID + "=" + config.getPid() + ")";
   
    // add the service listener
    locListener = new ServiceListener() {
      public void serviceChanged(ServiceEvent event) {
        switch (event.getType()) {
        case ServiceEvent.REGISTERED:
          ServiceReference serviceReference = event.getServiceReference();
          discoveryLocator = (IDiscoveryLocator) context.getService(serviceReference);
          synchronized (locLock) {
            locLock.notifyAll();
          }
        }
      }
    };
    context.addServiceListener(locListener, filter);
   
    // try to get the service initially
    ServiceReference[] references = context.getServiceReferences(IDiscoveryLocator.class.getName(), filter);
    if(references != null) {
      for (int i = 0; i < references.length;) {
        ServiceReference serviceReference = references[i];
        discoveryLocator = (IDiscoveryLocator) context.getService(serviceReference);
        synchronized (locLock) {
          locLock.notifyAll();
        }
      }
    }

 
    // advertiser
    config = configAdmin.createFactoryConfiguration(
        DnsSdTestHelper.ECF_DISCOVERY_DNSSD + ".advertiser", null);
    properties = new Hashtable();
    properties.put(IDnsSdDiscoveryConstants.CA_SEARCH_PATH, new String[]{DnsSdTestHelper.DOMAIN});
    properties.put(IDnsSdDiscoveryConstants.CA_RESOLVER, DnsSdTestHelper.DNS_RESOLVER);
    properties.put(IDnsSdDiscoveryConstants.CA_TSIG_KEY, DnsSdTestHelper.TSIG_KEY);
    properties.put(IDnsSdDiscoveryConstants.CA_TSIG_KEY_NAME, DnsSdTestHelper.TSIG_KEY_NAME);
    config.update(properties);
   
    filter = "(" + Constants.SERVICE_PID + "=" + config.getPid() + ")";
   
    // add the service listener
    advListener = new ServiceListener() {
      public void serviceChanged(ServiceEvent event) {
        switch (event.getType()) {
        case ServiceEvent.REGISTERED:
          ServiceReference serviceReference = event.getServiceReference();
          discoveryAdvertiser = (IDiscoveryAdvertiser) context.getService(serviceReference);
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.