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;
}
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);
}
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;
}
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);
}
Aggregations