Search in sources :

Example 26 with IServiceInfo

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

the class RemoteServiceHandlerUtil method getActiveIRemoteServiceReferencesChecked.

public static IRemoteServiceReference[] getActiveIRemoteServiceReferencesChecked(ExecutionEvent event) throws ExecutionException {
    final IServiceInfo serviceInfo = DiscoveryHandlerUtil.getActiveIServiceInfoChecked(event);
    final IRemoteServiceContainerAdapter adapter = getActiveIRemoteServiceContainerAdapterChecked(event);
    try {
        return getRemoteServiceReferencesForRemoteServiceAdapter(adapter, serviceInfo);
    } catch (IDCreateException e) {
        throw new ExecutionException(e.getMessage(), e);
    } catch (InvalidSyntaxException e) {
        throw new ExecutionException(e.getMessage(), e);
    }
}
Also used : IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 27 with IServiceInfo

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

the class DnsSdAdvertiserComparator method compare.

/* (non-Javadoc)
	 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
	 */
public int compare(final Object arg0, final Object arg1) {
    int result = -1;
    if (arg0 instanceof IServiceInfo) {
        final IServiceInfo serviceInfo = (IServiceInfo) arg0;
        if (arg1 instanceof List) {
            result = (serviceInfo.getServiceProperties().size() + membercount) * -1;
            final List records = (List) arg1;
            for (final Iterator itr = records.iterator(); itr.hasNext(); ) {
                final Record record = (Record) itr.next();
                if (record instanceof SRVRecord) {
                    result = compareSrvRecord(result, serviceInfo, record);
                } else if (record instanceof TXTRecord) {
                    final String[] str = record.rdataToString().split("=");
                    final String key = str[0].substring(1);
                    final String value = str[1].substring(0, str[1].length() - 1);
                    final Object property = serviceInfo.getServiceProperties().getProperty(key);
                    if (property != null) {
                        result += value.equals(property.toString()) ? 1 : -1;
                    } else {
                        result += -1;
                    }
                }
            }
        } else if (arg1 instanceof SRVRecord) {
            result = compareSrvRecord(-membercount, serviceInfo, (SRVRecord) arg1);
        }
    }
    return result;
}
Also used : TXTRecord(org.xbill.DNS.TXTRecord) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) Iterator(java.util.Iterator) List(java.util.List) SRVRecord(org.xbill.DNS.SRVRecord) Record(org.xbill.DNS.Record) TXTRecord(org.xbill.DNS.TXTRecord) SRVRecord(org.xbill.DNS.SRVRecord)

Example 28 with IServiceInfo

use of org.eclipse.ecf.discovery.IServiceInfo 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 29 with IServiceInfo

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

the class JSLPServiceIDTest method testCreateByjSLPAndRemoveServicePrefixWithServiceService.

/* (non-Javadoc)
	 * @see org.eclipse.ecf.tests.discovery.identity.ServiceIDTest#testRemoveServicePrefixWithServiceService()
	 * 
	 * test from jSLP -> ECF discovery which needs to remove the first occurrence of "service:"
	 */
public void testCreateByjSLPAndRemoveServicePrefixWithServiceService() throws ServiceLocationException {
    final String internalRep = "service:service.eclipse:foo: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();
    assertEquals(internalRep, stid.getInternal());
    assertEquals("_service._foo._bar._" + IServiceTypeID.DEFAULT_PROTO[0] + "." + IServiceTypeID.DEFAULT_SCOPE[0] + "._eclipse", stid.getName());
    assertEquals("eclipse", stid.getNamingAuthority());
    assertTrue(Arrays.equals(new String[] { "service", "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 30 with IServiceInfo

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

the class DnsSdTestHelper method createServiceInfo.

public static IServiceInfo createServiceInfo(Namespace namespace) {
    final Properties props = new Properties();
    final URI uri = URI.create(SCHEME + "://" + DOMAIN_A_RECORD + ":" + PORT + PATH);
    IServiceTypeID serviceTypeID = ServiceIDFactory.getDefault().createServiceTypeID(namespace, new String[] { SCHEME }, new String[] { DOMAIN }, new String[] { PROTO }, NAMING_AUTH);
    final ServiceProperties serviceProperties = new ServiceProperties(props);
    serviceProperties.setPropertyString("path", PATH);
    serviceProperties.setPropertyString("dns-sd.ptcl", SCHEME);
    return new ServiceInfo(uri, DOMAIN_A_RECORD, serviceTypeID, 10, 0, serviceProperties);
}
Also used : IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID) ServiceInfo(org.eclipse.ecf.discovery.ServiceInfo) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) ServiceProperties(org.eclipse.ecf.discovery.ServiceProperties) Properties(java.util.Properties) ServiceProperties(org.eclipse.ecf.discovery.ServiceProperties) URI(java.net.URI)

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