Search in sources :

Example 1 with IServiceID

use of org.eclipse.ecf.discovery.identity.IServiceID in project ecf by eclipse.

the class DnsSdDiscoveryComparator method compare.

/* (non-Javadoc)
	 * @see java.util.Comparator#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;
        final IServiceID firstServiceId = first.getServiceID();
        final IServiceID secondServiceId = second.getServiceID();
        boolean idsSame = firstServiceId.equals(secondServiceId);
        boolean prioSame = first.getPriority() == second.getPriority();
        boolean weightSame = first.getWeight() == second.getWeight();
        boolean servicePropertiesSame = compareServiceProperties(first.getServiceProperties(), second.getServiceProperties());
        // <= due to the fact that we might get a cache hit during testing which ttl has already decreased
        boolean ttlSame = first.getTTL() <= second.getTTL();
        final boolean result = (idsSame && prioSame && weightSame && servicePropertiesSame && ttlSame);
        if (result == true) {
            return 0;
        }
    }
    return -1;
}
Also used : IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IServiceID(org.eclipse.ecf.discovery.identity.IServiceID)

Example 2 with IServiceID

use of org.eclipse.ecf.discovery.identity.IServiceID 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 3 with IServiceID

use of org.eclipse.ecf.discovery.identity.IServiceID 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 4 with IServiceID

use of org.eclipse.ecf.discovery.identity.IServiceID in project ecf by eclipse.

the class ServiceInfoComparator method compare.

/* (non-Javadoc)
	 * @see java.util.Comparator#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;
        final IServiceID firstServiceId = first.getServiceID();
        final IServiceID secondServiceId = second.getServiceID();
        boolean idsSame = firstServiceId.equals(secondServiceId);
        boolean prioSame = first.getPriority() == second.getPriority();
        boolean weightSame = first.getWeight() == second.getWeight();
        boolean servicePropertiesSame = compareServiceProperties(first.getServiceProperties(), second.getServiceProperties());
        boolean ttlSame = first.getTTL() == second.getTTL();
        final boolean result = (idsSame && prioSame && weightSame && servicePropertiesSame && ttlSame);
        if (result == true) {
            return 0;
        }
    }
    return -1;
}
Also used : IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IServiceID(org.eclipse.ecf.discovery.identity.IServiceID)

Example 5 with IServiceID

use of org.eclipse.ecf.discovery.identity.IServiceID in project ecf by eclipse.

the class JSLPTestComparator method compare.

/* (non-Javadoc)
	 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
	 */
public int compare(final Object arg0, final Object arg1) {
    if (arg0 instanceof IServiceInfo && arg1 instanceof IServiceInfo) {
        final IServiceInfo first = (IServiceInfo) arg0;
        final IServiceInfo second = (IServiceInfo) arg1;
        final IServiceID firstID = first.getServiceID();
        final IServiceID secondID = second.getServiceID();
        final IServiceTypeID firstTypeID = firstID.getServiceTypeID();
        final IServiceTypeID secondTypeID = secondID.getServiceTypeID();
        final boolean protocolsSame = Arrays.equals(firstTypeID.getProtocols(), secondTypeID.getProtocols());
        final boolean weightSame = first.getWeight() == second.getWeight();
        final boolean prioSame = first.getPriority() == second.getPriority();
        final String firstName = firstID.getName();
        final String secondName = secondID.getName();
        final boolean nameSame = firstName.equals(secondName);
        final String[] firstServices = firstTypeID.getServices();
        final String[] secondServices = secondTypeID.getServices();
        final boolean serviceSame = Arrays.equals(firstServices, secondServices);
        final Namespace firstNamespace = firstID.getNamespace();
        final Namespace secondNamespace = secondID.getNamespace();
        final boolean namespaceSame = firstNamespace.equals(secondNamespace);
        final String firstNA = firstTypeID.getNamingAuthority();
        final String secondsSA = secondTypeID.getNamingAuthority();
        final boolean naSame = firstNA.equals(secondsSA);
        final URI firstLocation = first.getLocation();
        final URI secondLocation = second.getLocation();
        final boolean locationSame = firstLocation.equals(secondLocation);
        final boolean scopesSame = Arrays.equals(firstTypeID.getScopes(), secondTypeID.getScopes());
        final IServiceProperties firstProperty = first.getServiceProperties();
        final IServiceProperties secondProperty = second.getServiceProperties();
        final boolean propertySame = firstProperty.equals(secondProperty);
        final boolean result = protocolsSame && weightSame && prioSame && nameSame && namespaceSame && serviceSame && naSame && locationSame && scopesSame && propertySame;
        if (result == true) {
            return 0;
        }
    }
    return -1;
}
Also used : IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IServiceID(org.eclipse.ecf.discovery.identity.IServiceID) IServiceProperties(org.eclipse.ecf.discovery.IServiceProperties) URI(java.net.URI) Namespace(org.eclipse.ecf.core.identity.Namespace)

Aggregations

IServiceID (org.eclipse.ecf.discovery.identity.IServiceID)8 IServiceInfo (org.eclipse.ecf.discovery.IServiceInfo)6 IServiceTypeID (org.eclipse.ecf.discovery.identity.IServiceTypeID)4 URI (java.net.URI)3 ServiceURL (ch.ethz.iks.slp.ServiceURL)2 ArrayList (java.util.ArrayList)2 ServicePropertiesAdapter (org.eclipse.ecf.internal.provider.jslp.ServicePropertiesAdapter)2 ServiceURLAdapter (org.eclipse.ecf.internal.provider.jslp.ServiceURLAdapter)2 JSLPServiceInfo (org.eclipse.ecf.provider.jslp.container.JSLPServiceInfo)2 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)1 Namespace (org.eclipse.ecf.core.identity.Namespace)1 StringID (org.eclipse.ecf.core.identity.StringID)1 IServiceProperties (org.eclipse.ecf.discovery.IServiceProperties)1 IEndpointDescriptionLocator (org.eclipse.ecf.osgi.services.remoteserviceadmin.IEndpointDescriptionLocator)1 AbstractEndpointNode (org.eclipse.ecf.remoteserviceadmin.ui.endpoint.model.AbstractEndpointNode)1 EndpointAsyncInterfacesNode (org.eclipse.ecf.remoteserviceadmin.ui.endpoint.model.EndpointAsyncInterfacesNode)1 EndpointConfigTypesNode (org.eclipse.ecf.remoteserviceadmin.ui.endpoint.model.EndpointConfigTypesNode)1 EndpointConnectTargetIDNode (org.eclipse.ecf.remoteserviceadmin.ui.endpoint.model.EndpointConnectTargetIDNode)1 EndpointDiscoveryGroupNode (org.eclipse.ecf.remoteserviceadmin.ui.endpoint.model.EndpointDiscoveryGroupNode)1 EndpointFrameworkIDNode (org.eclipse.ecf.remoteserviceadmin.ui.endpoint.model.EndpointFrameworkIDNode)1