Remote OSGI over XMPP
In a previous post, I showed how real-time collaboration could be added to Eclipse/RCP apps using ECF datashare API running on the ECF XMPP provider.
One can also use ECF to make remote OSGi calls using the ECF remoteservices API.
For example, on an ECF XMPP peer that is to be the 'server' for a given service (a trivial IConcatService in this case):
And for clients to lookup and use the service:
Further, note that the client can use any of the 'style's of remote invocation desired:
With 'getProxy()' this returns an instance that implements IConcatService, and allows direct method invocation:
There is more test and example code available here. Note that with the IRemoteService.callAsynch, callSynch, and fireAsynch methods it is not even necessary that the client have the service interface locally. All that is needed is the string identifying the desired class name.
The support for remote services on the ECF generic provider is already in ECF 1.0.0, and the support for doing remote services on XMPP will be available in ECF 1.0.2.
One can also use ECF to make remote OSGi calls using the ECF remoteservices API.
For example, on an ECF XMPP peer that is to be the 'server' for a given service (a trivial IConcatService in this case):
// Get ECF adapter for remote services
IRemoteServiceContainerAdapter adapter = ... (e.g. from contacts list)
// Get targetID[] buddies who are to receive service registration
ID [] targetIDs = ... (e.g. from contacts list)
Dictionary props = new Hashtable();
props.put(Constants.SERVICE_REGISTRATION_TARGETS,targetIDs);
// Create service instance...this does the actual concatenate
Object concatService = new IConcatService() {
public String concat(String string1, String string2) {
return string1.concat(string2);
}
};
// Register service instance
adapter.registerRemoteService(new String[] { "IConcatService" }, concatService, props);
// Service now registered
And for clients to lookup and use the service:
// Get adapter for accessing remote services
IRemoteServiceContainerAdapter adapter = ...
// Get remote service reference
IRemoteServiceReference[] refs = adapter.getRemoteServiceReferences(null, "IConcatService", null);
// Get service for remote reference
IRemoteService service = adapter.getRemoteService(refs[0]);
// Create remote call
IRemoteCall remoteCall = new IRemoteCall() {
public String getMethod() {
return "concat";
}
public Object[] getParameters() {
return new Object[] { "Eclipse", " is cool" };
}
public long getTimeout() {
return 3000;
}};
// Call synchronously
String result = (String) service.callSynch(remoteCall);
System.out.println("concat result is: "+result);
// prints out: concat result is: Eclipse is cool
Further, note that the client can use any of the 'style's of remote invocation desired:
IRemoteService.callSynch(...)
IRemoteService.callAsynch(...)
IRemoteService.fireAsynch(...)
IRemoteService.getProxy()
With 'getProxy()' this returns an instance that implements IConcatService, and allows direct method invocation:
IConcatService concat = (IConcatService) remoteService.getProxy();
String result = concat.concat("OSGi"," is cool");
System.out.println("concat result is: "+result);
// prints out: concat result is: OSGi is cool
There is more test and example code available here. Note that with the IRemoteService.callAsynch, callSynch, and fireAsynch methods it is not even necessary that the client have the service interface locally. All that is needed is the string identifying the desired class name.
The support for remote services on the ECF generic provider is already in ECF 1.0.0, and the support for doing remote services on XMPP will be available in ECF 1.0.2.


5 Comments:
I want to use test and example code available hire: http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.ecf/tests/org.eclipse.ecf.tests.remoteservice/?root=Technology_Project
But what have to enter about
Host:
User:
Password:
Boris Starchev - Teacher
Hi bstarchev,
Yes, you need to provide information for two xmpp accounts (one that publishes/registers the service, the other that uses the service). The way this is done for the test code in org.eclipse.ecf.tests.remoteservice.presence.RemoteServiceContainerAdapterTest package is to put the following (e.g. ) on the command line for the test:
-Dusername0=slewis@ecf.eclipse.org -Dpassword0=slewispassword
-Dusername1=fliwatuet@ecf.eclipse.org -Dpassword1=fliwatuetpassword
The accounts can also be gmail.com.
If you want to use a test account please let me know at slewis@composent.com.
Hi Scott,
I'm trying to use your example to call a remote method on different clients (though different machines) but I always get a timeout exception while calling a remote method. What am I doing wrong?
Here is my code snippet:
ISessionService tempService = ProvisioningActivator.getDefault().getService(ISessionService.class);
IRemoteServiceContainerAdapter remoteServiceContainerAdapter = tempService.getRemoteServiceContainerAdapter();
// get remote services
IRemoteServiceReference[] refs = remoteServiceContainerAdapter.getRemoteServiceReferences(null,
IInstalledFeaturesService.class.getName(),null);
// try to call a remote service on all connected user
for (int serviceNumber = 0; serviceNumber < refs.length; serviceNumber++) {
IRemoteService remService = remoteServiceContainerAdapter.getRemoteService(refs[serviceNumber]);
Assert.isNotNull(remService);
// get proxy for remote service
IInstalledFeaturesService featureService = (IInstalledFeaturesService) remService.getProxy();
// ************
// so far everything worked fine, but now a timeout exception is thrown
String userInfo = featureService.getUserInfo();
System.out.println(userInfo);
}
} catch (ECFException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Hi bstarchev,
You should try turning on the trace options (when running in the debugger) for the org.eclipse.ecf.provider.remoteservice
plugin. Do this for both the service 'server' as well as for the service 'client'. Then you should see the activity on both the client and the server when a remote call is made. It seems likely to me that the service is blocking/deadlocked somehow, and the response is never sent back to the client. If you want further help with this please LMK at slewis at composent.com and/or ecf-dev at eclipse.org and we'll get you going.
I assume that you are able to run the ECF remote services over XMPP tests on your XMPP accounts...is that right?
Hi Scott, thanks for the quick reply. I've sent you an email to discuss the problem further.
Regards,
Eugen
Post a Comment
<< Home