Search in sources :

Example 31 with IServiceTypeID

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" }));
}
Also used : IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID)

Example 32 with IServiceTypeID

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);
}
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 33 with IServiceTypeID

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");
}
Also used : IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID) IFuture(org.eclipse.equinox.concurrent.future.IFuture)

Example 34 with IServiceTypeID

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);
        }
    }
}
Also used : IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID) InetAddress(java.net.InetAddress) URI(java.net.URI) IOException(java.io.IOException)

Example 35 with IServiceTypeID

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

IServiceTypeID (org.eclipse.ecf.discovery.identity.IServiceTypeID)35 Namespace (org.eclipse.ecf.core.identity.Namespace)10 URI (java.net.URI)9 IServiceInfo (org.eclipse.ecf.discovery.IServiceInfo)9 ServiceInfo (org.eclipse.ecf.discovery.ServiceInfo)5 JSLPNamespace (org.eclipse.ecf.provider.jslp.identity.JSLPNamespace)5 ArrayList (java.util.ArrayList)4 Properties (java.util.Properties)4 IServiceID (org.eclipse.ecf.discovery.identity.IServiceID)4 ServiceURL (ch.ethz.iks.slp.ServiceURL)3 ServiceProperties (org.eclipse.ecf.discovery.ServiceProperties)3 URISyntaxException (java.net.URISyntaxException)2 List (java.util.List)2 Map (java.util.Map)2 IServiceProperties (org.eclipse.ecf.discovery.IServiceProperties)2 ServiceTypeID (org.eclipse.ecf.discovery.identity.ServiceTypeID)2 ServicePropertiesAdapter (org.eclipse.ecf.internal.provider.jslp.ServicePropertiesAdapter)2 ServiceURLAdapter (org.eclipse.ecf.internal.provider.jslp.ServiceURLAdapter)2 JSLPServiceInfo (org.eclipse.ecf.provider.jslp.container.JSLPServiceInfo)2 PTRRecord (org.xbill.DNS.PTRRecord)2