Search in sources :

Example 21 with IServiceInfo

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

Example 22 with IServiceInfo

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

Example 23 with IServiceInfo

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

Example 24 with IServiceInfo

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;
}
Also used : Filter(org.osgi.framework.Filter) ServiceTracker(org.osgi.util.tracker.ServiceTracker) IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IServiceProperties(org.eclipse.ecf.discovery.IServiceProperties) IRemoteService(org.eclipse.ecf.remoteservice.IRemoteService) ExecutionException(org.eclipse.core.commands.ExecutionException) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference)

Example 25 with IServiceInfo

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);
    }
}
Also used : IServiceInfo(org.eclipse.ecf.discovery.IServiceInfo) ContainerCreateException(org.eclipse.ecf.core.ContainerCreateException) ID(org.eclipse.ecf.core.identity.ID) IContainer(org.eclipse.ecf.core.IContainer) ExecutionException(org.eclipse.core.commands.ExecutionException)

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