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