Search in sources :

Example 1 with ServiceProperties

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

the class ServiceInfoFactory method createServiceProperties.

/**
 * @param endpointDescription endpoint description
 * @param advertiser advertiser
 * @param serviceTypeID serviceTypeID
 * @param serviceName serviceName
 * @param uri uri
 * @return IServiceProperties for the given input parameters
 * @since 3.0
 */
protected IServiceProperties createServiceProperties(org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription, IDiscoveryAdvertiser advertiser, IServiceTypeID serviceTypeID, String serviceName, URI uri) {
    Map<String, Object> props = endpointDescription.getProperties();
    Map<String, Object> result = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
    for (String key : props.keySet()) if (!discoveryProperties.contains(key))
        result.put(key, props.get(key));
    ServiceProperties spResult = new ServiceProperties();
    encodeServiceProperties(new EndpointDescription(result), spResult);
    return spResult;
}
Also used : ServiceProperties(org.eclipse.ecf.discovery.ServiceProperties) IServiceProperties(org.eclipse.ecf.discovery.IServiceProperties) TreeMap(java.util.TreeMap)

Example 2 with ServiceProperties

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

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

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

Aggregations

ServiceProperties (org.eclipse.ecf.discovery.ServiceProperties)4 URI (java.net.URI)3 Properties (java.util.Properties)3 IServiceInfo (org.eclipse.ecf.discovery.IServiceInfo)3 ServiceInfo (org.eclipse.ecf.discovery.ServiceInfo)3 IServiceTypeID (org.eclipse.ecf.discovery.identity.IServiceTypeID)3 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)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