Search in sources :

Example 6 with IServiceInfo

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

the class JSLPServiceIDTest method testCreateByjSLPAndRemoveServicePrefix.

/* (non-Javadoc)
	 * @see org.eclipse.ecf.tests.discovery.identity.ServiceIDTest#testCreateServiceTypeIDFromInternalString()
	 * 
	 * test from jSLP -> ECF discovery which needs to remove the first occurrence of "service:"
	 */
public void testCreateByjSLPAndRemoveServicePrefix() throws ServiceLocationException {
    final String internalRep = "service:foo.eclipse:bar";
    final ServiceURL sUrl = new ServiceURL(internalRep + "://localhost:1234/a/path/to/something", ServiceURL.LIFETIME_PERMANENT);
    final IServiceInfo serviceInfo = new JSLPServiceInfo(DiscoveryTestHelper.SERVICENAME, new ServiceURLAdapter(sUrl), DiscoveryTestHelper.PRIORITY, DiscoveryTestHelper.WEIGHT, new ServicePropertiesAdapter(new ArrayList()));
    assertEquals(serviceInfo.getPriority(), DiscoveryTestHelper.PRIORITY);
    assertEquals(serviceInfo.getWeight(), DiscoveryTestHelper.WEIGHT);
    final IServiceID sid = serviceInfo.getServiceID();
    assertEquals(serviceInfo.getServiceName(), DiscoveryTestHelper.SERVICENAME);
    final IServiceTypeID stid = sid.getServiceTypeID();
    String internal = stid.getInternal();
    assertEquals(internalRep, internal);
    assertEquals("_foo._bar._" + IServiceTypeID.DEFAULT_PROTO[0] + "." + IServiceTypeID.DEFAULT_SCOPE[0] + "._eclipse", stid.getName());
    assertEquals("eclipse", stid.getNamingAuthority());
    assertTrue(Arrays.equals(new String[] { "foo", "bar" }, stid.getServices()));
    assertTrue(Arrays.equals(IServiceTypeID.DEFAULT_SCOPE, stid.getScopes()));
    assertTrue(Arrays.equals(IServiceTypeID.DEFAULT_PROTO, stid.getProtocols()));
}
Also used : IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID) ServiceURLAdapter(org.eclipse.ecf.internal.provider.jslp.ServiceURLAdapter) JSLPServiceInfo(org.eclipse.ecf.provider.jslp.container.JSLPServiceInfo) ServicePropertiesAdapter(org.eclipse.ecf.internal.provider.jslp.ServicePropertiesAdapter) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IServiceID(org.eclipse.ecf.discovery.identity.IServiceID) ArrayList(java.util.ArrayList) ServiceURL(ch.ethz.iks.slp.ServiceURL)

Example 7 with IServiceInfo

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

the class CompositeServiceInfoComporator method compare.

/* (non-Javadoc)
	 * @see org.eclipse.ecf.tests.discovery.ServiceInfoComparator#compare(java.lang.Object, java.lang.Object)
	 */
public int compare(Object arg0, Object arg1) {
    if (arg0 instanceof IServiceInfo && arg1 instanceof IServiceInfo) {
        final IServiceInfo first = (IServiceInfo) arg0;
        final IServiceInfo second = (IServiceInfo) arg1;
        boolean priority = first.getPriority() == second.getPriority();
        boolean weight = first.getWeight() == second.getWeight();
        final URI uri1 = first.getLocation();
        final URI uri2 = second.getLocation();
        boolean port = uri1.getPort() == uri2.getPort();
        boolean host = uri1.getHost().equals(uri2.getHost());
        final IServiceID firstID = first.getServiceID();
        final IServiceID secondID = second.getServiceID();
        boolean serviceType = firstID.getServiceTypeID().equals(secondID.getServiceTypeID());
        boolean serviceName = firstID.getServiceName().equals(secondID.getServiceName());
        String firstName = firstID.getName();
        String secondName = secondID.getName();
        boolean name = firstName.equals(secondName);
        boolean serviceProperties = compareServiceProperties(first.getServiceProperties(), second.getServiceProperties());
        final boolean result = name && serviceType && serviceName && host && port && priority && weight && serviceProperties;
        if (result == true) {
            return 0;
        }
    }
    return -1;
}
Also used : IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IServiceID(org.eclipse.ecf.discovery.identity.IServiceID) URI(java.net.URI)

Example 8 with IServiceInfo

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

the class DiscoveryServiceRegistryTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    // override the service info with a _generic_ service info. Generic in
    // the sense that its namespace if the parent DiscoveryNamespace and not
    // a provider specific one. We need to use the parent DN because users of the
    // whiteboard pattern do not interact with the IDA directly.
    IServiceTypeID serviceTypeID = ServiceIDFactory.getDefault().createServiceTypeID(IDFactory.getDefault().getNamespaceByName(DiscoveryNamespace.NAME), services, new String[] { scope }, new String[] { protocol }, namingAuthority);
    assertNotNull(serviceTypeID);
    // Register a generic IServiceInfo (discovery generic) in the OSGi
    // service registry. Let all comparison be done on the provider specific
    // ("serviceInfo") super class member though Otherwise we would have to
    // register a specific type ignoring ServiceInfoComparator (see below) because the
    // generic IServiceInfo will never be equal to the (converted) discovery
    // provider .
    genericServiceInfo = new ServiceInfo(serviceInfo.getLocation(), DiscoveryTestHelper.SERVICENAME, serviceTypeID, 1, 1, serviceInfo.getServiceProperties(), ttl);
}
Also used : IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID) ServiceInfo(org.eclipse.ecf.discovery.ServiceInfo) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo)

Example 9 with IServiceInfo

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

the class DiscoveryServiceTest method testAddServiceTypeListenerOSGi.

public void testAddServiceTypeListenerOSGi() throws ContainerConnectException {
    IServiceInfo[] services = discoveryLocator.getServices();
    assertTrue("No Services must be registerd at this point " + (services.length == 0 ? "" : services[0].toString()), services.length == 0);
    final TestServiceTypeListener testTypeListener = new TestServiceTypeListener(eventsToExpect);
    Properties props = new Properties();
    props.put(IDiscoveryLocator.CONTAINER_NAME, containerUnderTest);
    BundleContext ctxt = Activator.getDefault().getContext();
    ServiceRegistration registration = ctxt.registerService(IServiceTypeListener.class.getName(), testTypeListener, props);
    synchronized (testTypeListener) {
        // register a service which we expect the test listener to get notified of
        registerService();
        try {
            testTypeListener.wait(waitTimeForProvider);
        } catch (final InterruptedException e) {
            Thread.currentThread().interrupt();
            fail("Some discovery unrelated threading issues?");
        }
    }
    registration.unregister();
    IContainerEvent[] event = testTypeListener.getEvent();
    assertNotNull("Test listener didn't receive discovery", event);
    assertEquals("Test listener received unexpected amount of discovery events: \n\t" + Arrays.asList(event), eventsToExpect, event.length);
}
Also used : TestServiceTypeListener(org.eclipse.ecf.tests.discovery.listener.TestServiceTypeListener) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IContainerEvent(org.eclipse.ecf.core.events.IContainerEvent) IServiceTypeListener(org.eclipse.ecf.discovery.IServiceTypeListener) Properties(java.util.Properties) BundleContext(org.osgi.framework.BundleContext) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 10 with IServiceInfo

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

the class DiscoveryServiceTest method testAddServiceListenerIServiceTypeIDIServiceListenerOSGi.

public void testAddServiceListenerIServiceTypeIDIServiceListenerOSGi() throws ContainerConnectException {
    IServiceInfo[] services = discoveryLocator.getServices();
    assertTrue("No Services must be registerd at this point " + (services.length == 0 ? "" : services[0].toString()), services.length == 0);
    final TestServiceListener tsl = new TestServiceListener(eventsToExpect, discoveryLocator, getName(), getTestId());
    IServiceTypeID serviceTypeID = serviceInfo.getServiceID().getServiceTypeID();
    Properties props = new Properties();
    props.put("org.eclipse.ecf.discovery.services", serviceTypeID.getServices());
    props.put("org.eclipse.ecf.discovery.scopes", serviceTypeID.getScopes());
    props.put("org.eclipse.ecf.discovery.protocols", serviceTypeID.getProtocols());
    props.put("org.eclipse.ecf.discovery.namingauthority", serviceTypeID.getNamingAuthority());
    props.put(IDiscoveryLocator.CONTAINER_NAME, containerUnderTest);
    BundleContext ctxt = Activator.getDefault().getContext();
    ServiceRegistration registration = ctxt.registerService(IServiceListener.class.getName(), tsl, props);
    addListenerRegisterAndWait(tsl, serviceInfo);
    registration.unregister();
    IContainerEvent[] event = tsl.getEvent();
    assertNotNull("Test listener didn't receive discovery", event);
    assertEquals("Test listener received unexpected amount of discovery events: \n\t" + Arrays.asList(event), eventsToExpect, event.length);
    IServiceInfo serviceInfo2 = ((IServiceEvent) event[eventsToExpect - 1]).getServiceInfo();
    assertTrue("IServiceInfo should match, expected:\n\t" + serviceInfo + " but:\n\t" + serviceInfo2, comparator.compare(serviceInfo2, serviceInfo) == 0);
}
Also used : ThreadTestServiceListener(org.eclipse.ecf.tests.discovery.listener.ThreadTestServiceListener) TestServiceListener(org.eclipse.ecf.tests.discovery.listener.TestServiceListener) IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID) IServiceListener(org.eclipse.ecf.discovery.IServiceListener) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IContainerEvent(org.eclipse.ecf.core.events.IContainerEvent) Properties(java.util.Properties) IServiceEvent(org.eclipse.ecf.discovery.IServiceEvent) BundleContext(org.osgi.framework.BundleContext) ServiceRegistration(org.osgi.framework.ServiceRegistration)

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