use of org.eclipse.ecf.discovery.identity.IServiceTypeID in project ecf by eclipse.
the class ServiceIDTest method testServiceTypeIDWithECFGenericString2.
/*
* use case: consumer instantiates a IServiceTypeID with the generic (ECF) String
*/
public void testServiceTypeIDWithECFGenericString2() {
final String serviceType = "_service._dns-srv._udp.ecf.eclipse.org._IANA";
final IServiceTypeID stid = createIDFromString(serviceType);
assertTrue(serviceType.equalsIgnoreCase(stid.getName()));
assertTrue("IANA".equalsIgnoreCase(stid.getNamingAuthority()));
assertTrue(Arrays.equals(stid.getProtocols(), new String[] { "udp" }));
assertTrue(Arrays.equals(stid.getScopes(), new String[] { "ecf.eclipse.org" }));
assertTrue(Arrays.equals(stid.getServices(), new String[] { "service", "dns-srv" }));
}
use of org.eclipse.ecf.discovery.identity.IServiceTypeID 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.identity.IServiceTypeID in project ecf by eclipse.
the class DiscoveryTest method testGetAsyncServiceTypes.
/**
* Test method for
* {@link org.eclipse.ecf.discovery.IDiscoveryLocator#getAsyncServiceTypes()}.
* @throws ContainerConnectException
* @throws InterruptedException
* @throws OperationCanceledException
*/
public void testGetAsyncServiceTypes() throws ContainerConnectException, OperationCanceledException, InterruptedException {
registerService();
final IFuture aFuture = discoveryLocator.getAsyncServiceTypes();
final Object object = aFuture.get();
assertTrue(object instanceof IServiceTypeID[]);
final IServiceTypeID[] services = (IServiceTypeID[]) object;
// just expect one event as the implementation filters dupes
assertTrue("Found: " + services.length + Arrays.asList(services), services.length == 1);
for (int i = 0; i < services.length; i++) {
IServiceTypeID iServiceTypeId = services[i];
if (serviceInfo.getServiceID().getServiceTypeID().equals(iServiceTypeId)) {
return;
}
}
fail("Self registered service not found");
}
use of org.eclipse.ecf.discovery.identity.IServiceTypeID in project ecf by eclipse.
the class ServerManager method registerServerForDiscovery.
private void registerServerForDiscovery(NamedGroup group, boolean pwrequired) {
final IDiscoveryAdvertiser discovery = Activator.getDefault().getDiscovery();
if (discovery != null) {
try {
final String rawGroupName = group.getRawName();
final Connector connector = group.getConnector();
final Properties props = new Properties();
props.put(PROTOCOL_PROPERTY_NAME, TCPServerSOContainer.DEFAULT_PROTOCOL);
props.put(PWREQUIRED_PROPERTY_NAME, new Boolean(pwrequired).toString());
props.put(GROUP_PROPERTY_NAME, rawGroupName);
final Namespace ns = IDFactory.getDefault().getNamespaceByName(ECF_NAMESPACE_JMDNS);
final IServiceTypeID serviceTypeID = ServiceIDFactory.getDefault().createServiceTypeID(ns, new String[] { SERVICE_TYPE }, IServiceTypeID.DEFAULT_PROTO);
final InetAddress host = InetAddress.getByName(connector.getHostname());
URI uri = new URI(TCPServerSOContainer.DEFAULT_PROTOCOL, null, host.getHostAddress(), connector.getPort(), null, null, null);
final ServiceInfo svcInfo = new ServiceInfo(uri, rawGroupName, serviceTypeID, 0, 0, new ServiceProperties(props));
discovery.registerService(svcInfo);
} catch (final Exception e) {
// $NON-NLS-1$
Activator.log("Discovery registration exception", e);
}
}
}
use of org.eclipse.ecf.discovery.identity.IServiceTypeID 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