Search in sources :

Example 1 with ServiceInfo

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

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

Example 3 with ServiceInfo

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

the class DnsSdDiscoveryLocator method getServiceInfos.

private List getServiceInfos(Collection srvQueryResult) {
    List infos = new ArrayList();
    for (Iterator iterator = srvQueryResult.iterator(); iterator.hasNext(); ) {
        SRVRecord srvRecord = (SRVRecord) iterator.next();
        long ttl = srvRecord.getTTL();
        int priority = srvRecord.getPriority();
        int weight = srvRecord.getWeight();
        int port = srvRecord.getPort();
        Name target = srvRecord.getTarget();
        String host = target.toString();
        host = host.substring(0, host.length() - 1);
        IServiceTypeID aServiceTypeID = new DnsSdServiceTypeID(getConnectNamespace(), srvRecord.getName());
        // query for txt records (attributes)
        Properties props = new Properties();
        Lookup txtQuery = new Lookup(srvRecord.getName(), Type.TXT);
        txtQuery.setResolver(resolver);
        Record[] txtQueryResults = txtQuery.run();
        int length = txtQueryResults == null ? 0 : txtQueryResults.length;
        for (int l = 0; l < length; l++) {
            TXTRecord txtResult = (TXTRecord) txtQueryResults[l];
            List strings = txtResult.getStrings();
            for (Iterator itr = strings.iterator(); itr.hasNext(); ) {
                String str = (String) itr.next();
                // $NON-NLS-1$
                String[] split = str.split("=");
                props.put(split[0], split[1]);
            }
        }
        String path = props.getProperty(DNS_SD_PATH);
        String proto = props.getProperty(DNS_SD_PTCL) == null ? aServiceTypeID.getProtocols()[0] : props.getProperty(DNS_SD_PTCL);
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        URI uri = URI.create(proto + "://" + host + ":" + port + (path == null ? "" : path));
        IServiceInfo info = new ServiceInfo(uri, host, aServiceTypeID, priority, weight, new ServiceProperties(props), ttl);
        infos.add(info);
    }
    return infos;
}
Also used : IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) ArrayList(java.util.ArrayList) Properties(java.util.Properties) ServiceProperties(org.eclipse.ecf.discovery.ServiceProperties) URI(java.net.URI) Name(org.xbill.DNS.Name) 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) TXTRecord(org.xbill.DNS.TXTRecord) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Lookup(org.xbill.DNS.Lookup) PTRRecord(org.xbill.DNS.PTRRecord) Record(org.xbill.DNS.Record) SRVRecord(org.xbill.DNS.SRVRecord) TXTRecord(org.xbill.DNS.TXTRecord) SRVRecord(org.xbill.DNS.SRVRecord)

Example 4 with ServiceInfo

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

the class AbstractDiscoveryTest method setUp.

protected void setUp() throws Exception {
    super.setUp();
    assertNotNull(containerUnderTest);
    assertTrue(containerUnderTest.startsWith("ecf.discovery."));
    discoveryLocator = getDiscoveryLocator();
    discoveryAdvertiser = getDiscoveryAdvertiser();
    assertNotNull("IDiscoveryLocator must not be null", discoveryLocator);
    assertNotNull("IDiscoveryAdvertiser must not be null", discoveryAdvertiser);
    final Properties props = new Properties();
    final URI uri = DiscoveryTestHelper.createDefaultURI(hostname);
    IServiceTypeID serviceTypeID = ServiceIDFactory.getDefault().createServiceTypeID(discoveryLocator.getServicesNamespace(), services, new String[] { scope }, new String[] { protocol }, namingAuthority);
    assertNotNull(serviceTypeID);
    final ServiceProperties serviceProperties = new ServiceProperties(props);
    serviceProperties.setPropertyString(TEST_NAME, getName());
    testId = Long.toString(random.nextLong());
    serviceProperties.setPropertyString(getName() + "testIdentifier", testId);
    serviceProperties.setPropertyString(getName() + "servicePropertiesString", "serviceProperties");
    serviceProperties.setProperty(getName() + "servicePropertiesIntegerMax", new Integer(Integer.MIN_VALUE));
    serviceProperties.setProperty(getName() + "servicePropertiesIntegerMin", new Integer(Integer.MAX_VALUE));
    serviceProperties.setProperty(getName() + "servicePropertiesBoolean", new Boolean(false));
    serviceProperties.setPropertyBytes(getName() + "servicePropertiesByte", new byte[] { -127, -126, -125, 0, 1, 2, 3, 'a', 'b', 'c', 'd', 126, 127 });
    serviceInfo = new ServiceInfo(uri, DiscoveryTestHelper.SERVICENAME, serviceTypeID, 1, 1, serviceProperties, ttl);
    assertNotNull(serviceInfo);
}
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)

Example 5 with ServiceInfo

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

IServiceInfo (org.eclipse.ecf.discovery.IServiceInfo)5 ServiceInfo (org.eclipse.ecf.discovery.ServiceInfo)5 IServiceTypeID (org.eclipse.ecf.discovery.identity.IServiceTypeID)5 URI (java.net.URI)4 Properties (java.util.Properties)3 ServiceProperties (org.eclipse.ecf.discovery.ServiceProperties)3 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 IServiceProperties (org.eclipse.ecf.discovery.IServiceProperties)1 Lookup (org.xbill.DNS.Lookup)1 Name (org.xbill.DNS.Name)1 PTRRecord (org.xbill.DNS.PTRRecord)1 Record (org.xbill.DNS.Record)1 SRVRecord (org.xbill.DNS.SRVRecord)1 TXTRecord (org.xbill.DNS.TXTRecord)1