Search in sources :

Example 1 with JSLPServiceInfo

use of org.eclipse.ecf.provider.jslp.container.JSLPServiceInfo in project ecf by eclipse.

the class JSLPDiscoveryJob method run.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
	 */
protected IStatus run(final IProgressMonitor monitor) {
    Assert.isNotNull(monitor);
    try {
        final Map availableServices = Activator.getDefault().getLocator().getServiceURLs();
        final Map removedServices = new HashMap(services);
        for (final Iterator itr = availableServices.entrySet().iterator(); itr.hasNext() && !monitor.isCanceled(); ) {
            final Map.Entry entry = (Map.Entry) itr.next();
            final ServiceURL url = (ServiceURL) entry.getKey();
            // do we know the service already?
            if (removedServices.containsKey(url)) {
                removedServices.remove(url);
            } else {
                // we don't know the service, so we need to create the
                final ServicePropertiesAdapter spa = new ServicePropertiesAdapter((List) entry.getValue());
                final String serviceName = spa.getServiceName() == null ? url.toString() : spa.getServiceName();
                final IServiceInfo serviceInfo = new JSLPServiceInfo(serviceName, new ServiceURLAdapter(url), spa.getPriority(), spa.getWeight(), spa);
                services.put(url, serviceInfo);
                discoveryContainer.fireServiceTypeDiscovered(serviceInfo.getServiceID().getServiceTypeID());
                discoveryContainer.fireServiceDiscovered(serviceInfo);
            }
            monitor.worked(1);
        }
        // at this point removedServices only contains stale services
        for (final Iterator itr = removedServices.entrySet().iterator(); itr.hasNext() && !monitor.isCanceled(); ) {
            final Map.Entry entry = (Map.Entry) itr.next();
            final Object key = entry.getKey();
            final IServiceInfo value = (IServiceInfo) entry.getValue();
            discoveryContainer.fireServiceUndiscovered(value);
            services.remove(key);
            monitor.worked(1);
        }
    } catch (final ServiceLocationException e) {
        // TODO-mkuppe if the advertiser is gone, we run into this exception
        // but we have to let the listeners know about the gone services
        // too
        // $NON-NLS-1$
        Trace.catching(Activator.PLUGIN_ID, JSLPDebugOptions.EXCEPTIONS_CATCHING, this.getClass(), "run", e);
    }
    // check if the JSLPDiscoveryContainer has been disconnected or disposed
    if (discoveryContainer.getConnectedID() != null) {
        this.schedule(JSLPDiscoveryContainer.REDISCOVER);
    }
    return Status.OK_STATUS;
}
Also used : JSLPServiceInfo(org.eclipse.ecf.provider.jslp.container.JSLPServiceInfo) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) ServiceURL(ch.ethz.iks.slp.ServiceURL) ServiceLocationException(ch.ethz.iks.slp.ServiceLocationException)

Example 2 with JSLPServiceInfo

use of org.eclipse.ecf.provider.jslp.container.JSLPServiceInfo in project ecf by eclipse.

the class JSLPServiceIDTest method testCreateByjSLPAndRemoveServicePrefix.

/* (non-Javadoc)
	 * @see org.eclipse.ecf.tests.discovery.identity.ServiceIDTest#testCreateServiceTypeIDFromInternalString()
	 * 
	 * test from jSLP -> ECF discovery which needs to remove the first occurrence of "service:"
	 */
public void testCreateByjSLPAndRemoveServicePrefix() throws ServiceLocationException {
    final String internalRep = "service:foo.eclipse:bar";
    final ServiceURL sUrl = new ServiceURL(internalRep + "://localhost:1234/a/path/to/something", ServiceURL.LIFETIME_PERMANENT);
    final IServiceInfo serviceInfo = new JSLPServiceInfo(DiscoveryTestHelper.SERVICENAME, new ServiceURLAdapter(sUrl), DiscoveryTestHelper.PRIORITY, DiscoveryTestHelper.WEIGHT, new ServicePropertiesAdapter(new ArrayList()));
    assertEquals(serviceInfo.getPriority(), DiscoveryTestHelper.PRIORITY);
    assertEquals(serviceInfo.getWeight(), DiscoveryTestHelper.WEIGHT);
    final IServiceID sid = serviceInfo.getServiceID();
    assertEquals(serviceInfo.getServiceName(), DiscoveryTestHelper.SERVICENAME);
    final IServiceTypeID stid = sid.getServiceTypeID();
    String internal = stid.getInternal();
    assertEquals(internalRep, internal);
    assertEquals("_foo._bar._" + IServiceTypeID.DEFAULT_PROTO[0] + "." + IServiceTypeID.DEFAULT_SCOPE[0] + "._eclipse", stid.getName());
    assertEquals("eclipse", stid.getNamingAuthority());
    assertTrue(Arrays.equals(new String[] { "foo", "bar" }, stid.getServices()));
    assertTrue(Arrays.equals(IServiceTypeID.DEFAULT_SCOPE, stid.getScopes()));
    assertTrue(Arrays.equals(IServiceTypeID.DEFAULT_PROTO, stid.getProtocols()));
}
Also used : IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID) ServiceURLAdapter(org.eclipse.ecf.internal.provider.jslp.ServiceURLAdapter) JSLPServiceInfo(org.eclipse.ecf.provider.jslp.container.JSLPServiceInfo) ServicePropertiesAdapter(org.eclipse.ecf.internal.provider.jslp.ServicePropertiesAdapter) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IServiceID(org.eclipse.ecf.discovery.identity.IServiceID) ArrayList(java.util.ArrayList) ServiceURL(ch.ethz.iks.slp.ServiceURL)

Example 3 with JSLPServiceInfo

use of org.eclipse.ecf.provider.jslp.container.JSLPServiceInfo in project ecf by eclipse.

the class JSLPServiceIDTest method testCreateByjSLPAndRemoveServicePrefixWithServiceService.

/* (non-Javadoc)
	 * @see org.eclipse.ecf.tests.discovery.identity.ServiceIDTest#testRemoveServicePrefixWithServiceService()
	 * 
	 * test from jSLP -> ECF discovery which needs to remove the first occurrence of "service:"
	 */
public void testCreateByjSLPAndRemoveServicePrefixWithServiceService() throws ServiceLocationException {
    final String internalRep = "service:service.eclipse:foo:bar";
    final ServiceURL sUrl = new ServiceURL(internalRep + "://localhost:1234/a/path/to/something", ServiceURL.LIFETIME_PERMANENT);
    final IServiceInfo serviceInfo = new JSLPServiceInfo(DiscoveryTestHelper.SERVICENAME, new ServiceURLAdapter(sUrl), DiscoveryTestHelper.PRIORITY, DiscoveryTestHelper.WEIGHT, new ServicePropertiesAdapter(new ArrayList()));
    assertEquals(serviceInfo.getPriority(), DiscoveryTestHelper.PRIORITY);
    assertEquals(serviceInfo.getWeight(), DiscoveryTestHelper.WEIGHT);
    final IServiceID sid = serviceInfo.getServiceID();
    assertEquals(serviceInfo.getServiceName(), DiscoveryTestHelper.SERVICENAME);
    final IServiceTypeID stid = sid.getServiceTypeID();
    assertEquals(internalRep, stid.getInternal());
    assertEquals("_service._foo._bar._" + IServiceTypeID.DEFAULT_PROTO[0] + "." + IServiceTypeID.DEFAULT_SCOPE[0] + "._eclipse", stid.getName());
    assertEquals("eclipse", stid.getNamingAuthority());
    assertTrue(Arrays.equals(new String[] { "service", "foo", "bar" }, stid.getServices()));
    assertTrue(Arrays.equals(IServiceTypeID.DEFAULT_SCOPE, stid.getScopes()));
    assertTrue(Arrays.equals(IServiceTypeID.DEFAULT_PROTO, stid.getProtocols()));
}
Also used : IServiceTypeID(org.eclipse.ecf.discovery.identity.IServiceTypeID) ServiceURLAdapter(org.eclipse.ecf.internal.provider.jslp.ServiceURLAdapter) JSLPServiceInfo(org.eclipse.ecf.provider.jslp.container.JSLPServiceInfo) ServicePropertiesAdapter(org.eclipse.ecf.internal.provider.jslp.ServicePropertiesAdapter) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IServiceID(org.eclipse.ecf.discovery.identity.IServiceID) ArrayList(java.util.ArrayList) ServiceURL(ch.ethz.iks.slp.ServiceURL)

Aggregations

ServiceURL (ch.ethz.iks.slp.ServiceURL)3 IServiceInfo (org.eclipse.ecf.discovery.IServiceInfo)3 JSLPServiceInfo (org.eclipse.ecf.provider.jslp.container.JSLPServiceInfo)3 ArrayList (java.util.ArrayList)2 IServiceID (org.eclipse.ecf.discovery.identity.IServiceID)2 IServiceTypeID (org.eclipse.ecf.discovery.identity.IServiceTypeID)2 ServicePropertiesAdapter (org.eclipse.ecf.internal.provider.jslp.ServicePropertiesAdapter)2 ServiceURLAdapter (org.eclipse.ecf.internal.provider.jslp.ServiceURLAdapter)2 ServiceLocationException (ch.ethz.iks.slp.ServiceLocationException)1