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