Search in sources :

Example 41 with IServiceInfo

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

the class DiscoveryTest method testGetServices.

/**
 * Test method for
 * {@link org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#getServices()}.
 * @throws ContainerConnectException
 */
public void testGetServices() throws ContainerConnectException {
    registerService();
    final IServiceInfo[] services = discoveryLocator.getServices();
    assertTrue("IServiceInfo[] is empty", services.length >= 1);
    for (int i = 0; i < services.length; i++) {
        IServiceInfo iServiceInfo = services[i];
        if (comparator.compare(iServiceInfo, serviceInfo) == 0) {
            return;
        }
    }
    fail("Self registered service not found");
}
Also used : IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo)

Example 42 with IServiceInfo

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

the class DiscoveryTest method testGetServiceInfo.

/**
 * Test method for
 * {@link org.eclipse.ecf.discovery.IDiscoveryContainerAdapter#getServiceInfo(org.eclipse.ecf.discovery.identity.IServiceID)}.
 * @throws ContainerConnectException
 */
public void testGetServiceInfo() throws ContainerConnectException {
    registerService();
    final IServiceInfo info = discoveryLocator.getServiceInfo(serviceInfo.getServiceID());
    assertTrue("IServiceInfo should match, expected:\n\t" + serviceInfo + " but:\n\t" + info, comparator.compare(info, serviceInfo) == 0);
}
Also used : IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo)

Example 43 with IServiceInfo

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

the class DiscoveryTest method testGetAsyncServices.

/**
 * Test method for
 * {@link org.eclipse.ecf.discovery.IDiscoveryLocator#getAsyncServices()}.
 * @throws ContainerConnectException
 * @throws InterruptedException
 * @throws OperationCanceledException
 */
public void testGetAsyncServices() throws ContainerConnectException, OperationCanceledException, InterruptedException {
    registerService();
    final IFuture aFuture = discoveryLocator.getAsyncServices();
    final Object object = aFuture.get();
    assertTrue(object instanceof IServiceInfo[]);
    final IServiceInfo[] services = (IServiceInfo[]) object;
    assertTrue("Found: " + services.length + Arrays.asList(services), services.length == eventsToExpect);
    for (int i = 0; i < services.length; i++) {
        IServiceInfo iServiceInfo = services[i];
        if (comparator.compare(iServiceInfo, serviceInfo) == 0) {
            return;
        }
    }
    fail("Self registered service not found");
}
Also used : IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IFuture(org.eclipse.equinox.concurrent.future.IFuture)

Example 44 with IServiceInfo

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

the class ServiceInfoFactory method createServiceInfo.

/**
 * @since 3.0
 */
public IServiceInfo createServiceInfo(IDiscoveryAdvertiser advertiser, org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription) {
    try {
        IServiceTypeID serviceTypeID = createServiceTypeID(endpointDescription, advertiser);
        String serviceName = createServiceName(endpointDescription, advertiser, serviceTypeID);
        URI uri = createURI(endpointDescription, advertiser, serviceTypeID, serviceName);
        IServiceProperties serviceProperties = createServiceProperties(endpointDescription, advertiser, serviceTypeID, serviceName, uri);
        Map edProperties = endpointDescription.getProperties();
        int priority = PropertiesUtil.getIntWithDefault(edProperties, RemoteConstants.DISCOVERY_SERVICE_PRIORITY, ServiceInfo.DEFAULT_PRIORITY);
        int weight = PropertiesUtil.getIntWithDefault(edProperties, RemoteConstants.DISCOVERY_SERVICE_WEIGHT, ServiceInfo.DEFAULT_WEIGHT);
        Long ttl = PropertiesUtil.getLongWithDefault(edProperties, RemoteConstants.DISCOVERY_SERVICE_TTL, ServiceInfo.DEFAULT_TTL);
        return new ServiceInfo(uri, serviceName, serviceTypeID, priority, weight, serviceProperties, ttl);
    } catch (Exception e) {
        logError(// $NON-NLS-1$
        "createServiceInfo", // $NON-NLS-1$
        "Exception creating service info for endpointDescription=" + endpointDescription + ",advertiser=" + // $NON-NLS-1$
        advertiser, e);
        return null;
    }
}
Also used : IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) ServiceInfo(org.eclipse.ecf.discovery.ServiceInfo) IServiceProperties(org.eclipse.ecf.discovery.IServiceProperties) URI(java.net.URI) TreeMap(java.util.TreeMap) Map(java.util.Map) URISyntaxException(java.net.URISyntaxException)

Example 45 with IServiceInfo

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

the class EndpointDescriptionLocator method processInitialLocatorServices.

private void processInitialLocatorServices(final IDiscoveryLocator locator, final LocatorServiceListener locatorListener) {
    IProgressRunnable runnable = new IProgressRunnable() {

        public Object run(IProgressMonitor arg0) throws Exception {
            IServiceInfo[] serviceInfos = null;
            try {
                serviceInfos = locator.getServices();
            } catch (Exception e) {
                logError("processInitialLocatorServices", "Exception in locator.getServices()", // $NON-NLS-1$ //$NON-NLS-2$
                e);
            }
            if (serviceInfos != null)
                for (int i = 0; i < serviceInfos.length; i++) {
                    locatorListener.handleService(serviceInfos[i], true);
                }
            return null;
        }
    };
    executor.execute(runnable, null);
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IProgressRunnable(org.eclipse.equinox.concurrent.future.IProgressRunnable) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Aggregations

IServiceInfo (org.eclipse.ecf.discovery.IServiceInfo)47 IContainerEvent (org.eclipse.ecf.core.events.IContainerEvent)8 IServiceTypeID (org.eclipse.ecf.discovery.identity.IServiceTypeID)8 Properties (java.util.Properties)7 URI (java.net.URI)6 IServiceEvent (org.eclipse.ecf.discovery.IServiceEvent)6 IServiceID (org.eclipse.ecf.discovery.identity.IServiceID)6 BundleContext (org.osgi.framework.BundleContext)6 ArrayList (java.util.ArrayList)5 ExecutionException (org.eclipse.core.commands.ExecutionException)5 ServiceRegistration (org.osgi.framework.ServiceRegistration)5 IServiceListener (org.eclipse.ecf.discovery.IServiceListener)4 ServiceInfo (org.eclipse.ecf.discovery.ServiceInfo)4 TestServiceListener (org.eclipse.ecf.tests.discovery.listener.TestServiceListener)4 ThreadTestServiceListener (org.eclipse.ecf.tests.discovery.listener.ThreadTestServiceListener)4 ServiceURL (ch.ethz.iks.slp.ServiceURL)3 List (java.util.List)3 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)3 IServiceProperties (org.eclipse.ecf.discovery.IServiceProperties)3 Iterator (java.util.Iterator)2