Search in sources :

Example 1 with IDiscoveryAdvertiser

use of org.eclipse.ecf.discovery.IDiscoveryAdvertiser in project ecf by eclipse.

the class ZooDiscoveryTest method getDiscoveryAdvertiser.

protected IDiscoveryAdvertiser getDiscoveryAdvertiser() {
    final IDiscoveryAdvertiser adapter = (IDiscoveryAdvertiser) this.container.getAdapter(IDiscoveryAdvertiser.class);
    // $NON-NLS-1$
    assertNotNull("Adapter must not be null", adapter);
    return adapter;
}
Also used : IDiscoveryAdvertiser(org.eclipse.ecf.discovery.IDiscoveryAdvertiser)

Example 2 with IDiscoveryAdvertiser

use of org.eclipse.ecf.discovery.IDiscoveryAdvertiser in project ecf by eclipse.

the class Activator method getAdvertiser.

public IDiscoveryAdvertiser getAdvertiser() {
    if (advertiserTracker == null) {
        advertiserTracker = new ServiceTracker(this.context, IDiscoveryAdvertiser.class.getName(), null);
        advertiserTracker.open();
    }
    try {
        return (IDiscoveryAdvertiser) advertiserTracker.waitForService(DISCOVERY_TIMEOUT);
    } catch (InterruptedException e) {
        // $NON-NLS-1$
        log("getAdvertiser", "Cannot get IDiscoveryAdvertiser", e);
    }
    return null;
}
Also used : IDiscoveryAdvertiser(org.eclipse.ecf.discovery.IDiscoveryAdvertiser) ServiceTracker(org.osgi.util.tracker.ServiceTracker)

Example 3 with IDiscoveryAdvertiser

use of org.eclipse.ecf.discovery.IDiscoveryAdvertiser in project ecf by eclipse.

the class Activator method getDiscoveryAdvertiser.

public IDiscoveryAdvertiser getDiscoveryAdvertiser(String containerUnderTest) {
    advertiserTracker.open();
    final ServiceReference[] serviceReferences = advertiserTracker.getServiceReferences();
    if (serviceReferences != null) {
        for (int i = 0; i < serviceReferences.length; i++) {
            ServiceReference sr = serviceReferences[i];
            if (containerUnderTest.equals(sr.getProperty(IDiscoveryAdvertiser.CONTAINER_NAME))) {
                return (IDiscoveryAdvertiser) advertiserTracker.getService(sr);
            }
        }
    }
    return null;
}
Also used : IDiscoveryAdvertiser(org.eclipse.ecf.discovery.IDiscoveryAdvertiser) ServiceReference(org.osgi.framework.ServiceReference)

Example 4 with IDiscoveryAdvertiser

use of org.eclipse.ecf.discovery.IDiscoveryAdvertiser in project ecf by eclipse.

the class Activator method start.

/* (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
	 */
public void start(final BundleContext context) throws Exception {
    final ServiceReference configAdminServiceRef = context.getServiceReference(ConfigurationAdmin.class.getName());
    if (configAdminServiceRef == null) {
        System.err.println("You don't have config admin deployed. Some tests will fail that require configuration!");
        return;
    }
    final ConfigurationAdmin configAdmin = (ConfigurationAdmin) context.getService(configAdminServiceRef);
    Configuration config = configAdmin.createFactoryConfiguration(DnsSdTestHelper.ECF_DISCOVERY_DNSSD + ".locator", null);
    Dictionary 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);
    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);
                    synchronized (advLock) {
                        advLock.notifyAll();
                    }
            }
        }
    };
    context.addServiceListener(advListener, filter);
    // try to get the service initially
    references = context.getServiceReferences(IDiscoveryAdvertiser.class.getName(), filter);
    if (references != null) {
        for (int i = 0; i < references.length; ) {
            ServiceReference serviceReference = references[i];
            discoveryAdvertiser = (IDiscoveryAdvertiser) context.getService(serviceReference);
            synchronized (advLock) {
                advLock.notifyAll();
            }
        }
    }
}
Also used : Dictionary(java.util.Dictionary) ServiceListener(org.osgi.framework.ServiceListener) Configuration(org.osgi.service.cm.Configuration) IDiscoveryAdvertiser(org.eclipse.ecf.discovery.IDiscoveryAdvertiser) Hashtable(java.util.Hashtable) ServiceEvent(org.osgi.framework.ServiceEvent) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) IDiscoveryLocator(org.eclipse.ecf.discovery.IDiscoveryLocator) ServiceReference(org.osgi.framework.ServiceReference)

Example 5 with IDiscoveryAdvertiser

use of org.eclipse.ecf.discovery.IDiscoveryAdvertiser in project ecf by eclipse.

the class AbstractMetadataFactoryTest method getDiscoveryAdvertiser.

protected IDiscoveryAdvertiser getDiscoveryAdvertiser() {
    ServiceTracker serviceTracker = new ServiceTracker(Activator.getDefault().getContext(), IDiscoveryAdvertiser.class.getName(), null);
    serviceTracker.open();
    IDiscoveryAdvertiser result = (IDiscoveryAdvertiser) serviceTracker.getService();
    serviceTracker.close();
    return result;
}
Also used : IDiscoveryAdvertiser(org.eclipse.ecf.discovery.IDiscoveryAdvertiser) ServiceTracker(org.osgi.util.tracker.ServiceTracker)

Aggregations

IDiscoveryAdvertiser (org.eclipse.ecf.discovery.IDiscoveryAdvertiser)8 ServiceTracker (org.osgi.util.tracker.ServiceTracker)3 ServiceReference (org.osgi.framework.ServiceReference)2 Dictionary (java.util.Dictionary)1 Hashtable (java.util.Hashtable)1 IDiscoveryLocator (org.eclipse.ecf.discovery.IDiscoveryLocator)1 ServiceEvent (org.osgi.framework.ServiceEvent)1 ServiceListener (org.osgi.framework.ServiceListener)1 Configuration (org.osgi.service.cm.Configuration)1 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)1