use of org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter in project ecf by eclipse.
the class SSLRemoteServiceProxyTest method testServiceListener.
public void testServiceListener() throws Exception {
final IRemoteServiceContainerAdapter[] adapters = getRemoteServiceAdapters();
done = false;
final Object lock = new Object();
adapters[1].addRemoteServiceListener(new IRemoteServiceListener() {
public void handleServiceEvent(IRemoteServiceEvent event) {
if (event instanceof IRemoteServiceRegisteredEvent) {
IRemoteServiceRegisteredEvent e = (IRemoteServiceRegisteredEvent) event;
IRemoteServiceReference ref = e.getReference();
remoteService = adapters[1].getRemoteService(ref);
assertNotNull(remoteService);
synchronized (lock) {
done = true;
lock.notify();
}
}
}
});
// Now register service on server (adapters[0]). This should result in notification on client (adapters[1])
// in above handleServiceEvent
adapters[0].registerRemoteService(new String[] { IConcatService.class.getName() }, createService(), customizeProperties(null));
// wait until block above called asynchronously
int count = 0;
synchronized (lock) {
while (!done && count++ < 10) {
try {
lock.wait(1000);
} catch (InterruptedException e) {
fail();
}
}
}
assertTrue(done);
if (remoteService == null)
return;
// We've got the remote service, so we're good to go
assertTrue(remoteService != null);
traceCallStart("callAsynchResult");
final IFuture result = remoteService.callAsync(createRemoteConcat("ECF AsynchResults ", "are cool"));
traceCallEnd("callAsynch");
assertNotNull(result);
Thread.sleep(SLEEPTIME);
}
use of org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter 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.IRemoteServiceContainerAdapter in project ecf by eclipse.
the class SSLSimpleConcatServer method start.
public void start(int port) throws Exception {
// Start server
server = new SSLSimpleGenericServer(HOST, port);
server.start(PATH, KEEPALIVE);
SSLGenericServerContainer serverContainer = server.getServerContainer(0);
IRemoteServiceContainerAdapter adapter = (IRemoteServiceContainerAdapter) serverContainer.getAdapter(IRemoteServiceContainerAdapter.class);
Assert.isNotNull(adapter);
registration = adapter.registerRemoteService(new String[] { IConcatService.class.getName() }, new ConcatService(), null);
Assert.isNotNull(registration);
System.out.println("generic server started with id=" + serverContainer.getID());
}
use of org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter in project ecf by eclipse.
the class Activator method start.
/*
* (non-Javadoc)
*
* @see
* org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext
* )
*/
public void start(BundleContext context) throws Exception {
this.context = context;
// Create R-OSGi Container
IContainerManager containerManager = getContainerManagerService();
container = containerManager.getContainerFactory().createContainer("ecf.r_osgi.peer");
// Get remote service container adapter
IRemoteServiceContainerAdapter containerAdapter = (IRemoteServiceContainerAdapter) container.getAdapter(IRemoteServiceContainerAdapter.class);
// Register remote service
serviceRegistration = containerAdapter.registerRemoteService(new String[] { IHello.class.getName() }, new Hello(), null);
System.out.println("IHello RemoteService registered");
}
use of org.eclipse.ecf.remoteservice.IRemoteServiceContainerAdapter 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);
}
Aggregations