Search in sources :

Example 11 with IRemoteServiceReference

use of org.eclipse.ecf.remoteservice.IRemoteServiceReference in project ecf by eclipse.

the class SSLSimpleConcatClient method start.

public void start(int port) throws Exception {
    IContainer client = ContainerFactory.getDefault().createContainer(CLIENT_TYPE);
    // Get adapter for accessing remote services
    IRemoteServiceContainerAdapter adapter = (IRemoteServiceContainerAdapter) client.getAdapter(IRemoteServiceContainerAdapter.class);
    rsContainer = new RemoteServiceContainer(client, adapter);
    System.out.println("Client created with ID=" + client.getID());
    ID connectTargetID = IDFactory.getDefault().createStringID(NLS.bind(SERVER_ID, new Integer(port)));
    System.out.println("Attempting connect to id=" + connectTargetID);
    client.connect(connectTargetID, null);
    System.out.println("Client connected to connectTargetID=" + connectTargetID);
    Thread.sleep(1000);
    // Get remote service reference
    IRemoteServiceReference[] refs = adapter.getRemoteServiceReferences((ID[]) null, IConcatService.class.getName(), null);
    rsReference = refs[0];
    System.out.println("Remote service with ref=" + refs[0]);
}
Also used : IRemoteServiceReference(org.eclipse.ecf.remoteservice.IRemoteServiceReference) IConcatService(org.eclipse.ecf.tests.remoteservice.IConcatService) RemoteServiceContainer(org.eclipse.ecf.remoteservice.RemoteServiceContainer) IRemoteServiceContainer(org.eclipse.ecf.remoteservice.IRemoteServiceContainer) IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) ID(org.eclipse.ecf.core.identity.ID) IContainer(org.eclipse.ecf.core.IContainer)

Example 12 with IRemoteServiceReference

use of org.eclipse.ecf.remoteservice.IRemoteServiceReference in project ecf by eclipse.

the class Activator method start.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.core.runtime.Plugins#start(org.osgi.framework.BundleContext)
	 */
public void start(BundleContext context) throws Exception {
    this.context = context;
    // 1. Create R-OSGi Container
    IContainerManager containerManager = getContainerManagerService();
    container = containerManager.getContainerFactory().createContainer("ecf.r_osgi.peer");
    // 2. Get remote service container adapter
    IRemoteServiceContainerAdapter containerAdapter = (IRemoteServiceContainerAdapter) container.getAdapter(IRemoteServiceContainerAdapter.class);
    // 3. Lookup IRemoteServiceReference
    IRemoteServiceReference[] helloReferences = containerAdapter.getRemoteServiceReferences(IDFactory.getDefault().createID(container.getConnectNamespace(), ROSGI_SERVICE_HOST), IHello.class.getName(), null);
    Assert.isNotNull(helloReferences);
    Assert.isTrue(helloReferences.length > 0);
    // 4. Get remote service for reference
    IRemoteService remoteService = containerAdapter.getRemoteService(helloReferences[0]);
    // 5. Get the proxy
    IHello proxy = (IHello) remoteService.getProxy();
    // 6. Finally...call the proxy
    proxy.hello("RemoteService Consumer");
    // Call asynchronously via listener
    callViaListener(remoteService);
}
Also used : IRemoteServiceReference(org.eclipse.ecf.remoteservice.IRemoteServiceReference) IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) IContainerManager(org.eclipse.ecf.core.IContainerManager) IRemoteService(org.eclipse.ecf.remoteservice.IRemoteService) IHello(org.eclipse.ecf.examples.remoteservices.hello.IHello)

Example 13 with IRemoteServiceReference

use of org.eclipse.ecf.remoteservice.IRemoteServiceReference in project ecf by eclipse.

the class RemoteServiceAdmin method importService.

private ImportRegistration importService(final EndpointDescription endpointDescription, IRemoteServiceContainer rsContainer) {
    // Get interfaces from endpoint description
    Collection<String> interfaces = endpointDescription.getInterfaces();
    Assert.isNotNull(interfaces);
    Assert.isTrue(interfaces.size() > 0);
    // Get ECF endpoint ID...if this throws IDCreateException (because the
    // local system does not have
    // namespace for creating ID, or no namespace is present in
    // endpointDescription or endpoint id,
    // then it will be caught by the caller
    ID endpointContainerID = endpointDescription.getContainerID();
    Assert.isNotNull(endpointContainerID);
    // Get connect target ID. May be null
    ID tID = endpointDescription.getConnectTargetID();
    if (tID == null)
        tID = endpointContainerID;
    final ID targetID = tID;
    // Get idFilter...also may be null
    final ID[] idFilter = getIDFilter(endpointDescription, targetID);
    // Get remote service filter
    final String rsFilter = getRemoteServiceFilter(endpointDescription);
    // IRemoteServiceReferences from query
    Collection<IRemoteServiceReference> rsRefs = new ArrayList<IRemoteServiceReference>();
    // Get IRemoteServiceContainerAdapter
    final IRemoteServiceContainerAdapter containerAdapter = rsContainer.getContainerAdapter();
    // rsContainerID
    ID rsContainerID = rsContainer.getContainer().getID();
    try {
        final IRSAConsumerContainerAdapter cca = (IRSAConsumerContainerAdapter) containerAdapter.getAdapter(IRSAConsumerContainerAdapter.class);
        // Get first interface name for service reference
        // lookup
        final String intf = interfaces.iterator().next();
        // Get/lookup remote service references
        IRemoteServiceReference[] refs = AccessController.doPrivileged(new PrivilegedExceptionAction<IRemoteServiceReference[]>() {

            public IRemoteServiceReference[] run() throws ContainerConnectException, InvalidSyntaxException {
                // If the RSAConsumerContainerAdapter is present, use it
                if (cca != null)
                    // Call importEndpoint if the IRSAConsumerContainerAdapter is present
                    return cca.importEndpoint(endpointDescription.getProperties());
                else
                    return containerAdapter.getRemoteServiceReferences(targetID, idFilter, intf, rsFilter);
            }
        });
        if (refs == null) {
            logWarning(// $NON-NLS-1$
            "doImportService", // $NON-NLS-1$
            "getRemoteServiceReferences return null for targetID=" + targetID + ",idFilter=" + // $NON-NLS-1$
            idFilter + ",intf=" + intf + ",rsFilter=" + // $NON-NLS-1$ //$NON-NLS-2$
            rsFilter + " on rsContainerID=" + // $NON-NLS-1$
            rsContainerID);
        } else
            for (int i = 0; i < refs.length; i++) rsRefs.add(refs[i]);
        // If there are several refs resulting (should not be)
        // we select the one to use
        IRemoteServiceReference selectedRsReference = selectRemoteServiceReference(rsRefs, targetID, idFilter, interfaces, rsFilter, rsContainer);
        // If none found, we obviously can't continue
        if (selectedRsReference == null)
            throw new RemoteReferenceNotFoundException(targetID, idFilter, interfaces, rsFilter);
        return new ImportRegistration(createAndRegisterProxy(endpointDescription, rsContainer, selectedRsReference));
    } catch (PrivilegedActionException e) {
        logError("importService", // $NON-NLS-1$ //$NON-NLS-2$
        "selectRemoteServiceReference returned null for rsRefs=" + rsRefs + ",targetID=" + // $NON-NLS-1$
        targetID + ",idFilter=" + idFilter + // $NON-NLS-1$ //$NON-NLS-2$
        ",interfaces=" + interfaces + ",rsFilter=" + // $NON-NLS-1$
        rsFilter + ",rsContainerID=" + rsContainerID, // $NON-NLS-1$
        e.getException());
        return new ImportRegistration(endpointDescription, e.getException());
    } catch (Exception e) {
        logError("importService", // $NON-NLS-1$ //$NON-NLS-2$
        "selectRemoteServiceReference returned null for rsRefs=" + rsRefs + ",targetID=" + // $NON-NLS-1$
        targetID + ",idFilter=" + idFilter + // $NON-NLS-1$ //$NON-NLS-2$
        ",interfaces=" + interfaces + ",rsFilter=" + // $NON-NLS-1$
        rsFilter + ",rsContainerID=" + rsContainerID, // $NON-NLS-1$
        e);
        return new ImportRegistration(endpointDescription, e);
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) ArrayList(java.util.ArrayList) IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) ECFException(org.eclipse.ecf.core.util.ECFException) ServiceException(org.osgi.framework.ServiceException) BundleException(org.osgi.framework.BundleException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) PrivilegedActionException(java.security.PrivilegedActionException) ContainerCreateException(org.eclipse.ecf.core.ContainerCreateException) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) IRemoteServiceReference(org.eclipse.ecf.remoteservice.IRemoteServiceReference) IRSAConsumerContainerAdapter(org.eclipse.ecf.remoteservice.IRSAConsumerContainerAdapter) ContainerConnectException(org.eclipse.ecf.core.ContainerConnectException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) ID(org.eclipse.ecf.core.identity.ID) IRemoteServiceID(org.eclipse.ecf.remoteservice.IRemoteServiceID) UUID(java.util.UUID) StringID(org.eclipse.ecf.core.identity.StringID)

Example 14 with IRemoteServiceReference

use of org.eclipse.ecf.remoteservice.IRemoteServiceReference in project ecf by eclipse.

the class Lab1Action method run.

/**
 * The action has been activated. The argument of the
 * method represents the 'real' action sitting
 * in the workbench UI.
 * @see IWorkbenchWindowActionDelegate#run
 */
public void run(IAction action) {
    try {
        IRemoteServiceContainerAdapter adapter = getContainerAdapter();
        // Create target ID
        String target = TARGET;
        ID targetID = createTargetID(container, target);
        // Get and resolve remote service reference
        IRemoteServiceReference[] ref = adapter.getRemoteServiceReferences(targetID, org.eclipse.ecf.examples.remoteservices.common.IRemoteEnvironmentInfo.class.getName(), null);
        IRemoteService svc = adapter.getRemoteService(ref[0]);
        // get proxy
        IRemoteEnvironmentInfo proxy = (IRemoteEnvironmentInfo) svc.getProxy();
        // Call it!
        String osArch = proxy.getOSArch();
        // Show result
        MessageDialog.openInformation(window.getShell(), "ECF Lab 1", "Target " + target + " has OS Arch=" + osArch);
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : IRemoteServiceReference(org.eclipse.ecf.remoteservice.IRemoteServiceReference) IRemoteEnvironmentInfo(org.eclipse.ecf.examples.remoteservices.common.IRemoteEnvironmentInfo) IRemoteServiceContainerAdapter(org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter) ID(org.eclipse.ecf.core.identity.ID) IRemoteService(org.eclipse.ecf.remoteservice.IRemoteService) ContainerCreateException(org.eclipse.ecf.core.ContainerCreateException)

Example 15 with IRemoteServiceReference

use of org.eclipse.ecf.remoteservice.IRemoteServiceReference in project ecf by eclipse.

the class RpcRemoteServiceAdapterTest method testUngetRemoteService.

public void testUngetRemoteService() {
    IRemoteServiceRegistration registration = createRpcRegistration(RpcConstants.TEST_ECHO_METHOD);
    IRemoteServiceReference reference = registration.getReference();
    getRemoteServiceClientContainerAdapter().getRemoteService(reference);
    assertTrue(getRemoteServiceClientContainerAdapter().ungetRemoteService(reference));
}
Also used : IRemoteServiceReference(org.eclipse.ecf.remoteservice.IRemoteServiceReference) IRemoteServiceRegistration(org.eclipse.ecf.remoteservice.IRemoteServiceRegistration)

Aggregations

IRemoteServiceReference (org.eclipse.ecf.remoteservice.IRemoteServiceReference)28 IRemoteServiceContainerAdapter (org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter)16 IConcatService (org.eclipse.ecf.tests.remoteservice.IConcatService)10 IRemoteService (org.eclipse.ecf.remoteservice.IRemoteService)8 IRemoteServiceRegistration (org.eclipse.ecf.remoteservice.IRemoteServiceRegistration)8 IRemoteServiceListener (org.eclipse.ecf.remoteservice.IRemoteServiceListener)6 IRemoteServiceEvent (org.eclipse.ecf.remoteservice.events.IRemoteServiceEvent)6 IRemoteServiceRegisteredEvent (org.eclipse.ecf.remoteservice.events.IRemoteServiceRegisteredEvent)6 IFuture (org.eclipse.equinox.concurrent.future.IFuture)6 ID (org.eclipse.ecf.core.identity.ID)4 IRemoteServiceID (org.eclipse.ecf.remoteservice.IRemoteServiceID)3 Dictionary (java.util.Dictionary)2 Hashtable (java.util.Hashtable)2 Properties (java.util.Properties)2 ContainerCreateException (org.eclipse.ecf.core.ContainerCreateException)2 IContainer (org.eclipse.ecf.core.IContainer)2 IRemoteServiceContainer (org.eclipse.ecf.remoteservice.IRemoteServiceContainer)2 IRemoteServiceProxy (org.eclipse.ecf.remoteservice.IRemoteServiceProxy)2 RemoteServiceContainer (org.eclipse.ecf.remoteservice.RemoteServiceContainer)2 RemoteServiceTracker (org.eclipse.ecf.remoteservice.util.tracker.RemoteServiceTracker)2