Search in sources :

Example 1 with IServiceInfo

use of org.eclipse.ecf.discovery.IServiceInfo in project ecf by eclipse.

the class DnsSdDiscoveryLocator method getServiceInfo.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ecf.discovery.IDiscoveryLocator#getServiceInfo(org.eclipse
	 * .ecf.discovery.identity.IServiceID)
	 */
public IServiceInfo getServiceInfo(IServiceID aServiceId) {
    Assert.isNotNull(aServiceId);
    IServiceInfo[] services = getServices(aServiceId.getServiceTypeID());
    for (int i = 0; i < services.length; i++) {
        // TODO This can be a lot faster if done directly instead of via org.eclipse.ecf.provider.dnssrv.DnsSrvDisocoveryLocator.getServices(IServiceTypeID)
        IServiceInfo iServiceInfo = services[i];
        if (iServiceInfo.getServiceID().equals(aServiceId)) {
            return iServiceInfo;
        }
    }
    return null;
}
Also used : IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo)

Example 2 with IServiceInfo

use of org.eclipse.ecf.discovery.IServiceInfo in project ecf by eclipse.

the class ConnectedTester method hasContainer.

private boolean hasContainer(Object receiver) {
    // get the container instance
    IServiceInfo serviceInfo = DiscoveryPropertyTesterUtil.getIServiceInfoReceiver(receiver);
    final String connectNamespace = getConnectNamespace(serviceInfo);
    final String connectId = getConnectID(serviceInfo);
    try {
        final ID createConnectId = IDFactory.getDefault().createID(connectNamespace, connectId);
        return (getContainerByConnectID(createConnectId) != null);
    } catch (IDCreateException e) {
        // Trace.trace(...);
        return false;
    }
}
Also used : IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) ID(org.eclipse.ecf.core.identity.ID)

Example 3 with IServiceInfo

use of org.eclipse.ecf.discovery.IServiceInfo in project ecf by eclipse.

the class RemoteServiceHandlerUtil method getActiveConnectIDChecked.

public static ID getActiveConnectIDChecked(ExecutionEvent event) throws ExecutionException {
    final IServiceInfo serviceInfo = DiscoveryHandlerUtil.getActiveIServiceInfoChecked(event);
    final String connectNamespace = getConnectNamespace(serviceInfo);
    final String connectId = getConnectID(serviceInfo);
    try {
        return IDFactory.getDefault().createID(connectNamespace, connectId);
    } catch (IDCreateException e) {
        throw new ExecutionException(e.getMessage(), e);
    }
}
Also used : IDCreateException(org.eclipse.ecf.core.identity.IDCreateException) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) ExecutionException(org.eclipse.core.commands.ExecutionException)

Example 4 with IServiceInfo

use of org.eclipse.ecf.discovery.IServiceInfo 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 5 with IServiceInfo

use of org.eclipse.ecf.discovery.IServiceInfo in project ecf by eclipse.

the class DnsSdDiscoveryComparator method compare.

/* (non-Javadoc)
	 * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
	 */
public int compare(Object arg0, Object arg1) {
    if (arg0 instanceof IServiceInfo && arg1 instanceof IServiceInfo) {
        final IServiceInfo first = (IServiceInfo) arg0;
        final IServiceInfo second = (IServiceInfo) arg1;
        final IServiceID firstServiceId = first.getServiceID();
        final IServiceID secondServiceId = second.getServiceID();
        boolean idsSame = firstServiceId.equals(secondServiceId);
        boolean prioSame = first.getPriority() == second.getPriority();
        boolean weightSame = first.getWeight() == second.getWeight();
        boolean servicePropertiesSame = compareServiceProperties(first.getServiceProperties(), second.getServiceProperties());
        // <= due to the fact that we might get a cache hit during testing which ttl has already decreased
        boolean ttlSame = first.getTTL() <= second.getTTL();
        final boolean result = (idsSame && prioSame && weightSame && servicePropertiesSame && ttlSame);
        if (result == true) {
            return 0;
        }
    }
    return -1;
}
Also used : IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) IServiceID(org.eclipse.ecf.discovery.identity.IServiceID)

Aggregations

IServiceInfo (org.eclipse.ecf.discovery.IServiceInfo)47 IContainerEvent (org.eclipse.ecf.core.events.IContainerEvent)8 IServiceTypeID (org.eclipse.ecf.discovery.identity.IServiceTypeID)8 Properties (java.util.Properties)7 URI (java.net.URI)6 IServiceEvent (org.eclipse.ecf.discovery.IServiceEvent)6 IServiceID (org.eclipse.ecf.discovery.identity.IServiceID)6 BundleContext (org.osgi.framework.BundleContext)6 ArrayList (java.util.ArrayList)5 ExecutionException (org.eclipse.core.commands.ExecutionException)5 ServiceRegistration (org.osgi.framework.ServiceRegistration)5 IServiceListener (org.eclipse.ecf.discovery.IServiceListener)4 ServiceInfo (org.eclipse.ecf.discovery.ServiceInfo)4 TestServiceListener (org.eclipse.ecf.tests.discovery.listener.TestServiceListener)4 ThreadTestServiceListener (org.eclipse.ecf.tests.discovery.listener.ThreadTestServiceListener)4 ServiceURL (ch.ethz.iks.slp.ServiceURL)3 List (java.util.List)3 IDCreateException (org.eclipse.ecf.core.identity.IDCreateException)3 IServiceProperties (org.eclipse.ecf.discovery.IServiceProperties)3 Iterator (java.util.Iterator)2