Search in sources :

Example 6 with IServiceProperties

use of org.eclipse.ecf.discovery.IServiceProperties 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)

Example 7 with IServiceProperties

use of org.eclipse.ecf.discovery.IServiceProperties 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)

Aggregations

IServiceProperties (org.eclipse.ecf.discovery.IServiceProperties)7 IServiceInfo (org.eclipse.ecf.discovery.IServiceInfo)3 URI (java.net.URI)2 Enumeration (java.util.Enumeration)2 TreeMap (java.util.TreeMap)2 IServiceTypeID (org.eclipse.ecf.discovery.identity.IServiceTypeID)2 Record (org.xbill.DNS.Record)2 SRVRecord (org.xbill.DNS.SRVRecord)2 TXTRecord (org.xbill.DNS.TXTRecord)2 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 Namespace (org.eclipse.ecf.core.identity.Namespace)1 ServiceInfo (org.eclipse.ecf.discovery.ServiceInfo)1 ServiceProperties (org.eclipse.ecf.discovery.ServiceProperties)1 IServiceID (org.eclipse.ecf.discovery.identity.IServiceID)1 IRemoteService (org.eclipse.ecf.remoteservice.IRemoteService)1 BundleContext (org.osgi.framework.BundleContext)1