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