use of org.eclipse.ecf.discovery.IServiceInfo in project ecf by eclipse.
the class ServiceInfoComparator 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());
boolean ttlSame = first.getTTL() == second.getTTL();
final boolean result = (idsSame && prioSame && weightSame && servicePropertiesSame && ttlSame);
if (result == true) {
return 0;
}
}
return -1;
}
use of org.eclipse.ecf.discovery.IServiceInfo in project ecf by eclipse.
the class AbstractTopologyManager method advertiseEndpointDescription.
/**
* @param endpointDescription endpoint description
* @since 3.0
*/
protected void advertiseEndpointDescription(org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription) {
this.registrationLock.lock();
try {
if (this.registrations.containsKey(endpointDescription)) {
return;
}
final IServiceInfoFactory service = serviceInfoFactoryTracker.getService();
if (service != null) {
final IServiceInfo serviceInfo = service.createServiceInfo(null, endpointDescription);
if (serviceInfo != null) {
trace(// $NON-NLS-1$
"advertiseEndpointDescription", // $NON-NLS-1$
"advertising endpointDescription=" + endpointDescription + " and IServiceInfo " + // $NON-NLS-1$
serviceInfo);
final ServiceRegistration<IServiceInfo> registerService = this.context.registerService(IServiceInfo.class, serviceInfo, null);
addRegistration(endpointDescription, registerService);
} else {
logError(// $NON-NLS-1$
"advertiseEndpointDescription", // $NON-NLS-1$1
"IServiceInfoFactory failed to convert EndpointDescription " + endpointDescription);
}
} else {
logError(// $NON-NLS-1$
"advertiseEndpointDescription", // $NON-NLS-1$
"no IServiceInfoFactory service found");
}
} finally {
this.registrationLock.unlock();
}
}
use of org.eclipse.ecf.discovery.IServiceInfo in project ecf by eclipse.
the class AbstractTopologyManager method advertiseModifyEndpointDescription.
/**
* @param endpointDescription endpoint description
* @since 4.1
*/
protected void advertiseModifyEndpointDescription(org.osgi.service.remoteserviceadmin.EndpointDescription endpointDescription) {
this.registrationLock.lock();
try {
final IServiceInfoFactory service = serviceInfoFactoryTracker.getService();
if (service != null) {
final IServiceInfo serviceInfo = service.createServiceInfo(null, endpointDescription);
if (serviceInfo != null) {
trace(// $NON-NLS-1$
"advertiseModifyEndpointDescription", // $NON-NLS-1$
"advertising modify endpointDescription=" + endpointDescription + " and IServiceInfo " + // $NON-NLS-1$
serviceInfo);
final ServiceRegistration<IServiceInfo> registerService = this.context.registerService(IServiceInfo.class, serviceInfo, null);
addRegistration(endpointDescription, registerService);
} else {
logError(// $NON-NLS-1$
"advertiseModifyEndpointDescription", // $NON-NLS-1$1
"IServiceInfoFactory failed to convert EndpointDescription " + endpointDescription);
}
} else {
logError(// $NON-NLS-1$
"advertiseModifyEndpointDescription", // $NON-NLS-1$
"no IServiceInfoFactory service found");
}
} finally {
this.registrationLock.unlock();
}
}
use of org.eclipse.ecf.discovery.IServiceInfo in project ecf by eclipse.
the class DOSGiReflectiveRemoteServiceHandler method execute.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands
* .ExecutionEvent)
*/
public Object execute(ExecutionEvent event) throws ExecutionException {
final IServiceInfo serviceInfo = DiscoveryHandlerUtil.getActiveIServiceInfoChecked(event);
final IServiceProperties serviceProperties = serviceInfo.getServiceProperties();
final String clazz = serviceProperties.getPropertyString(Constants.OBJECTCLASS);
final String serviceId = new String(serviceProperties.getPropertyString(RemoteConstants.SERVICE_IMPORTED_ENDPOINT_SERVICE_ID));
final String containerId = new String(serviceProperties.getPropertyString(RemoteConstants.SERVICE_IMPORTED_ENDPOINT_ID));
// get the service via the osgi service registry
final BundleContext context = Activator.getDefault().getBundle().getBundleContext();
final Filter filter;
try {
filter = context.createFilter(// $NON-NLS-1$ //$NON-NLS-2$
"(&(" + Constants.OBJECTCLASS + "=" + clazz + ")" + "(" + IDistributionConstants.SERVICE_IMPORTED + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"=*" + ")" + "(" + RemoteConstants.SERVICE_IMPORTED_ENDPOINT_ID + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"=" + containerId + ")(" + RemoteConstants.SERVICE_IMPORTED_ENDPOINT_SERVICE_ID + "=" + serviceId + // $NON-NLS-1$ //$NON-NLS-2$
"))");
} catch (InvalidSyntaxException e1) {
MessageDialog.openError(null, Messages.DOSGiReflectiveRemoteServiceHandler_HandlerInvocationFailed, NLS.bind(Messages.DOSGiReflectiveRemoteServiceHandler_FilterCreationFailed, e1.getMessage()));
return null;
}
final ServiceTracker serviceTracker = new ServiceTracker(context, filter, null);
serviceTracker.open();
final ServiceReference serviceReference = serviceTracker.getServiceReference();
if (serviceReference == null) {
MessageDialog.openError(null, Messages.DOSGiReflectiveRemoteServiceHandler_HandlerInvocationFailed, NLS.bind(Messages.DOSGiReflectiveRemoteServiceHandler_NoServiceMatch, filter.toString()));
return null;
}
// obtain the remote service reference from the local service ref (cool
// ECF feature, huh?)
final IRemoteService remoteService = (IRemoteService) serviceReference.getProperty(IDistributionConstants.SERVICE_IMPORTED);
if (remoteService == null) {
MessageDialog.openError(null, Messages.DOSGiReflectiveRemoteServiceHandler_HandlerInvocationFailed, Messages.DOSGiReflectiveRemoteServiceHandler_RemoteServiceUnresolveable);
return null;
}
try {
executeMethodInvocationDialog(Class.forName(clazz), remoteService);
} catch (ClassNotFoundException e) {
MessageDialog.openError(null, Messages.DOSGiReflectiveRemoteServiceHandler_HandlerInvocationFailed, e.getLocalizedMessage());
throw new ExecutionException(e.getMessage(), e);
}
return null;
}
use of org.eclipse.ecf.discovery.IServiceInfo in project ecf by eclipse.
the class RemoteServiceHandlerUtil method getActiveIRemoteServiceContainerChecked.
public static IContainer getActiveIRemoteServiceContainerChecked(ExecutionEvent event) throws ExecutionException {
final IServiceInfo serviceInfo = DiscoveryHandlerUtil.getActiveIServiceInfoChecked(event);
final ID createConnectId = getActiveConnectIDChecked(event);
final IContainer container = getContainerWithConnectID(createConnectId);
if (container != null) {
return container;
}
// TODO remove parameters once
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=256586 is fixed
final Object[] parameters = new Object[] { createConnectId };
try {
// new one
return ContainerFactory.getDefault().createContainer(getContainerFactory(serviceInfo), parameters);
} catch (ContainerCreateException e) {
throw new ExecutionException(e.getMessage(), e);
}
}
Aggregations