Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2018-03-15 12:00:06 -0400
committerslewis2018-03-15 12:00:06 -0400
commit04409504a18579c8fe90b18a8d9bb72bc84cdddb (patch)
tree7d4a0b68a9b4df2b85313c8d3763b00dc35e299c
parenteca50a8929df30b12b3dfc826e59a73fbe5f07a2 (diff)
downloadorg.eclipse.ecf-04409504a18579c8fe90b18a8d9bb72bc84cdddb.tar.gz
org.eclipse.ecf-04409504a18579c8fe90b18a8d9bb72bc84cdddb.tar.xz
org.eclipse.ecf-04409504a18579c8fe90b18a8d9bb72bc84cdddb.zip
Additional fixes for bug
https://bugs.eclipse.org/bugs/show_bug.cgi?id=532205 Added API to AbstractRSAClientService to simplify the creation of providers. Change-Id: I57d69eeaf81de2230eb6ad163c6199f5a780a341
-rw-r--r--examples/bundles/com.mycorp.examples.timeservice.consumer.ds/src/com/mycorp/examples/timeservice/consumer/ds/TimeServiceComponent.java1
-rw-r--r--examples/bundles/com.mycorp.examples.timeservice.host/launch/TimeServiceHost.xmlrpc.zeroconf.product2
-rw-r--r--examples/bundles/com.mycorp.examples.timeservice.host/src/com/mycorp/examples/timeservice/host/Activator.java4
-rw-r--r--framework/bundles/org.eclipse.ecf.remoteservice/src/org/eclipse/ecf/remoteservice/AbstractRemoteService.java99
-rw-r--r--framework/bundles/org.eclipse.ecf.remoteservice/src/org/eclipse/ecf/remoteservice/client/AbstractRSAClientService.java58
-rw-r--r--providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceImpl.java61
6 files changed, 160 insertions, 65 deletions
diff --git a/examples/bundles/com.mycorp.examples.timeservice.consumer.ds/src/com/mycorp/examples/timeservice/consumer/ds/TimeServiceComponent.java b/examples/bundles/com.mycorp.examples.timeservice.consumer.ds/src/com/mycorp/examples/timeservice/consumer/ds/TimeServiceComponent.java
index 9fbcbbba7..b2022e8ff 100644
--- a/examples/bundles/com.mycorp.examples.timeservice.consumer.ds/src/com/mycorp/examples/timeservice/consumer/ds/TimeServiceComponent.java
+++ b/examples/bundles/com.mycorp.examples.timeservice.consumer.ds/src/com/mycorp/examples/timeservice/consumer/ds/TimeServiceComponent.java
@@ -19,7 +19,6 @@ public class TimeServiceComponent {
// Called by DS upon ITimeService discovery
@Reference
void bindTimeService(ITimeService timeService) {
- System.out.println("Discovered ITimeService via DS. Instance="+timeService);
// Call the service and print out result!
System.out.println("Current time on remote is: " + timeService.getCurrentTime());
}
diff --git a/examples/bundles/com.mycorp.examples.timeservice.host/launch/TimeServiceHost.xmlrpc.zeroconf.product b/examples/bundles/com.mycorp.examples.timeservice.host/launch/TimeServiceHost.xmlrpc.zeroconf.product
index 010701a68..15380e615 100644
--- a/examples/bundles/com.mycorp.examples.timeservice.host/launch/TimeServiceHost.xmlrpc.zeroconf.product
+++ b/examples/bundles/com.mycorp.examples.timeservice.host/launch/TimeServiceHost.xmlrpc.zeroconf.product
@@ -15,6 +15,8 @@
-Dservice.exported.configs=ecf.xmlrpc.server
-Decf.xmlrpc.server.uriContext=http://localhost:8181/xml-rpc
-Dcom.mycorp.examples.timeservice.rest.host.id=http://localhost:8181
+-Dservice.intents=osgi.basic
+-Dosgi.basic.timeout=50000
</vmArgs>
<vmArgsMac>-XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts
</vmArgsMac>
diff --git a/examples/bundles/com.mycorp.examples.timeservice.host/src/com/mycorp/examples/timeservice/host/Activator.java b/examples/bundles/com.mycorp.examples.timeservice.host/src/com/mycorp/examples/timeservice/host/Activator.java
index 4a5766d01..526182f85 100644
--- a/examples/bundles/com.mycorp.examples.timeservice.host/src/com/mycorp/examples/timeservice/host/Activator.java
+++ b/examples/bundles/com.mycorp.examples.timeservice.host/src/com/mycorp/examples/timeservice/host/Activator.java
@@ -67,15 +67,13 @@ public class Activator implements BundleActivator {
result.put(DEFAULT_CONFIG + ".hostname", "localhost");
}
- result.put("osgi.basic.timeout", "30001");
-
result.put(SERVICE_EXPORTED_CONFIGS, config);
// add any config properties. config properties start with
// the config name '.' property
for (Object k : props.keySet()) {
if (k instanceof String) {
String key = (String) k;
- if (key.startsWith(config))
+ if (key.startsWith(config) || key.startsWith("osgi.") || key.startsWith("service."))
result.put(key, props.get(key));
}
}
diff --git a/framework/bundles/org.eclipse.ecf.remoteservice/src/org/eclipse/ecf/remoteservice/AbstractRemoteService.java b/framework/bundles/org.eclipse.ecf.remoteservice/src/org/eclipse/ecf/remoteservice/AbstractRemoteService.java
index 01437f489..9b92aee46 100644
--- a/framework/bundles/org.eclipse.ecf.remoteservice/src/org/eclipse/ecf/remoteservice/AbstractRemoteService.java
+++ b/framework/bundles/org.eclipse.ecf.remoteservice/src/org/eclipse/ecf/remoteservice/AbstractRemoteService.java
@@ -703,17 +703,18 @@ public abstract class AbstractRemoteService extends AbstractAsyncProxyRemoteServ
/**
* @since 8.13
*/
- public Object submitCallable(Callable<Object> callable, long timeout) throws ECFException {
- Future<Object> f = getFutureExecutorService(null).submit(callable);
- try {
- return f.get(timeout, TimeUnit.MILLISECONDS);
- } catch (InterruptedException e) {
- throw new ECFException("submitCallable interrupted", e); //$NON-NLS-1$
- } catch (ExecutionException e) {
- throw new ECFException("submitCallable interrupted", e.getCause()); //$NON-NLS-1$
- } catch (TimeoutException e) {
- throw new ECFException("submitCallable timed out", e); //$NON-NLS-1$
- }
+ public Future<Object> callAsync(IRemoteCall call, Callable<Object> callable) {
+ return getFutureExecutorService(call).submit(callable);
+ }
+
+ /**
+ * @throws TimeoutException
+ * @throws ExecutionException
+ * @throws InterruptedException
+ * @since 8.13
+ */
+ public Object callSync(IRemoteCall call, Callable<Object> callable) throws InterruptedException, ExecutionException, TimeoutException {
+ return callAsync(call, callable).get(call.getTimeout(), TimeUnit.MILLISECONDS);
}
/**
@@ -728,4 +729,80 @@ public abstract class AbstractRemoteService extends AbstractAsyncProxyRemoteServ
iFutureExecutor = null;
}
}
+
+ /**
+ * @since 8.13
+ */
+ protected Future<Object> callAsyncWithTimeout(final IRemoteCall call, final Callable<Object> callable) {
+ return getFutureExecutorService(call).submit(new Callable<Object>() {
+ public Object call() throws Exception {
+ try {
+ return getFutureExecutorService(call).submit(callable).get(call.getTimeout(), TimeUnit.MILLISECONDS);
+ } catch (InterruptedException e) {
+ throw new InterruptedException("Interrupted calling remote service method=" + call.getMethod()); //$NON-NLS-1$
+ } catch (ExecutionException e) {
+ throw new InvocationTargetException(e.getCause(), "Exception calling remote service method=" + call.getMethod()); //$NON-NLS-1$
+ } catch (TimeoutException e) {
+ throw new TimeoutException("Timeout calling remote service method=" + call.getMethod() + " timeout=" + call.getTimeout()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ });
+ }
+
+ /**
+ * @since 8.13
+ */
+ protected IRemoteCallCompleteEvent createRCCESuccess(final Object result) {
+ return createRCCE(result, null);
+ }
+
+ /**
+ * @since 8.13
+ */
+ protected IRemoteCallCompleteEvent createRCCEFailure(final Throwable e) {
+ return createRCCE(null, e);
+ }
+
+ /**
+ * @since 8.13
+ */
+ protected IRemoteCallCompleteEvent createRCCE(final Object result, final Throwable e) {
+ return new IRemoteCallCompleteEvent() {
+ public long getRequestId() {
+ return 0;
+ }
+
+ public Object getResponse() {
+ return result;
+ }
+
+ public boolean hadException() {
+ return (e != null);
+ }
+
+ public Throwable getException() {
+ return e;
+ }
+ };
+ }
+
+ /**
+ * @since 8.13
+ */
+ protected void callAsyncWithTimeout(final IRemoteCall call, final Callable<IRemoteCallCompleteEvent> callable, final IRemoteCallListener callback) {
+ getFutureExecutorService(call).submit(new Runnable() {
+ public void run() {
+ try {
+ callback.handleEvent(getFutureExecutorService(call).submit(callable).get(call.getTimeout(), TimeUnit.MILLISECONDS));
+ } catch (InterruptedException e) {
+ callback.handleEvent(createRCCE(null, new InterruptedException("Interrupted calling remote service method=" + call.getMethod()))); //$NON-NLS-1$
+ } catch (ExecutionException e) {
+ callback.handleEvent(createRCCE(null, new InvocationTargetException(e.getCause(), "Exception calling remote service method=" + call.getMethod()))); //$NON-NLS-1$
+ } catch (TimeoutException e) {
+ callback.handleEvent(createRCCE(null, new TimeoutException("Timeout calling remote service method=" + call.getMethod() + " timeout=" + call.getTimeout()))); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+ });
+ }
+
}
diff --git a/framework/bundles/org.eclipse.ecf.remoteservice/src/org/eclipse/ecf/remoteservice/client/AbstractRSAClientService.java b/framework/bundles/org.eclipse.ecf.remoteservice/src/org/eclipse/ecf/remoteservice/client/AbstractRSAClientService.java
index a7bd70f82..aa6c4371d 100644
--- a/framework/bundles/org.eclipse.ecf.remoteservice/src/org/eclipse/ecf/remoteservice/client/AbstractRSAClientService.java
+++ b/framework/bundles/org.eclipse.ecf.remoteservice/src/org/eclipse/ecf/remoteservice/client/AbstractRSAClientService.java
@@ -10,9 +10,10 @@
package org.eclipse.ecf.remoteservice.client;
import java.lang.reflect.Method;
+import java.util.concurrent.*;
import org.eclipse.ecf.core.util.ECFException;
-import org.eclipse.ecf.remoteservice.IRemoteCall;
-import org.eclipse.ecf.remoteservice.RemoteCall;
+import org.eclipse.ecf.remoteservice.*;
+import org.eclipse.ecf.remoteservice.events.IRemoteCallCompleteEvent;
import org.osgi.framework.ServiceException;
/**
@@ -67,7 +68,9 @@ public abstract class AbstractRSAClientService extends AbstractClientService {
* @return Object. Should return a non-null instance of {@link org.eclipse.equinox.concurrent.future.IFuture}, {@link java.util.concurrent.Future}, or {@link java.util.concurrent.CompletableFuture}
* @throws ECFException if async cannot be invoked
*/
- protected abstract Object invokeAsync(RSARemoteCall remoteCall) throws ECFException;
+ protected Object invokeAsync(RSARemoteCall remoteCall) throws ECFException {
+ return callFuture(remoteCall, remoteCall.getReflectMethod().getReturnType());
+ }
/**
* Invoke a remote call synchronously. This method should block until a value may be returned, or the remote
@@ -77,7 +80,23 @@ public abstract class AbstractRSAClientService extends AbstractClientService {
* @return the result (of appropriate type)
* @throws ECFException if some exception occurred during invocation
*/
- protected abstract Object invokeSync(RSARemoteCall remoteCall) throws ECFException;
+ protected Object invokeSync(RSARemoteCall remoteCall) throws ECFException {
+ if (remoteCall.getClass().isAssignableFrom(RSARemoteCall.class)) {
+ Callable<Object> c = createSyncCallable(remoteCall);
+ if (c == null)
+ throw new ECFException("invokeSync failed on method=" + remoteCall.getMethod(), new NullPointerException("createSyncCallable() must not return null. It's necessary for distribution provider to override createSyncCallable.")); //$NON-NLS-1$ //$NON-NLS-2$
+ try {
+ return callSync(remoteCall, c);
+ } catch (InterruptedException e) {
+ throw new ECFException("invokeSync interrupted on method=" + remoteCall.getMethod(), e); //$NON-NLS-1$
+ } catch (ExecutionException e) {
+ throw new ECFException("invokeSync exception on method=" + remoteCall.getMethod(), e.getCause()); //$NON-NLS-1$
+ } catch (TimeoutException e) {
+ throw new ECFException("invokeSync timeout on method=" + remoteCall.getMethod(), e); //$NON-NLS-1$
+ }
+ }
+ return super.invokeSync(remoteCall);
+ }
protected RSARemoteCall createRemoteCall(Object proxy, Method method, String methodName, Object[] parameters, long timeout) {
return new RSARemoteCall(proxy, method, methodName, parameters, timeout);
@@ -113,4 +132,35 @@ public abstract class AbstractRSAClientService extends AbstractClientService {
throw new ServiceException("Service exception on remote service proxy rsid=" + getRemoteServiceID(), ServiceException.REMOTE, t); //$NON-NLS-1$
}
}
+
+ @Override
+ protected ExecutorService getFutureExecutorService(IRemoteCall call) {
+ return super.getFutureExecutorService(call);
+ }
+
+ @Override
+ protected void callAsync(IRemoteCall call, IRemoteCallable callable, IRemoteCallListener listener) {
+ if (call.getClass().isAssignableFrom(RSARemoteCall.class)) {
+ Callable<IRemoteCallCompleteEvent> c = createAsyncCallable((RSARemoteCall) call);
+ if (c == null)
+ throw new NullPointerException("createAsyncCallable returns null. Distribution provider must override createAsyncCallable"); //$NON-NLS-1$
+ callAsyncWithTimeout(call, c, listener);
+ }
+ super.callAsync(call, callable, listener);
+ }
+
+ /**
+ * @since 8.13
+ */
+ protected Callable<IRemoteCallCompleteEvent> createAsyncCallable(final RSARemoteCall call) {
+ return null;
+ }
+
+ /**
+ * @since 8.13
+ */
+ protected Callable<Object> createSyncCallable(final RSARemoteCall call) {
+ return null;
+ }
+
}
diff --git a/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceImpl.java b/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceImpl.java
index 8202abdb6..d99820017 100644
--- a/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceImpl.java
+++ b/providers/bundles/org.eclipse.ecf.provider.remoteservice/src/org/eclipse/ecf/provider/remoteservice/generic/RemoteServiceImpl.java
@@ -8,7 +8,7 @@
******************************************************************************/
package org.eclipse.ecf.provider.remoteservice.generic;
-import java.util.concurrent.TimeoutException;
+import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicReference;
import org.eclipse.ecf.core.util.ECFException;
import org.eclipse.ecf.remoteservice.*;
@@ -44,59 +44,28 @@ public class RemoteServiceImpl extends AbstractRemoteService {
* @see org.eclipse.ecf.remoteservice.IRemoteService#callAsync(org.eclipse.ecf.remoteservice.IRemoteCall, org.eclipse.ecf.remoteservice.IRemoteCallListener)
*/
public void callAsync(final IRemoteCall call, final IRemoteCallListener listener) {
- getFutureExecutorService(call).submit(new Runnable() {
- public void run() {
- final AtomicReference<IRemoteCallEvent> l = new AtomicReference<IRemoteCallEvent>();
+ callAsyncWithTimeout(call, new Callable<IRemoteCallCompleteEvent>() {
+ public IRemoteCallCompleteEvent call() throws Exception {
+ final AtomicReference<IRemoteCallCompleteEvent> ar = new AtomicReference<IRemoteCallCompleteEvent>();
sharedObject.sendCallRequestWithListener(registration, call, new IRemoteCallListener() {
public void handleEvent(IRemoteCallEvent event) {
- if (event instanceof IRemoteCallCompleteEvent) {
- synchronized (l) {
- l.set(event);
- l.notify();
+ if (event instanceof IRemoteCallCompleteEvent)
+ synchronized (ar) {
+ ar.set((IRemoteCallCompleteEvent) event);
+ ar.notify();
}
- }
}
});
- long timeout = call.getTimeout();
- Exception exception = null;
- IRemoteCallEvent rce = null;
- long sysTimeout = System.currentTimeMillis() + timeout;
- synchronized (l) {
- try {
- while (rce == null && System.currentTimeMillis() < sysTimeout) {
- l.wait(timeout / 10);
- rce = l.get();
- }
- } catch (InterruptedException e) {
- exception = e;
+ synchronized (ar) {
+ while (true) {
+ IRemoteCallCompleteEvent result = ar.get();
+ if (result != null)
+ return result;
+ ar.wait(call.getTimeout());
}
}
- if (rce != null)
- listener.handleEvent(rce);
- else {
- if (exception == null)
- exception = new TimeoutException("remote call method=" + call.getMethod() + " timed out after " + timeout + "ms"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- final Exception except = exception;
- listener.handleEvent(new IRemoteCallCompleteEvent() {
- public long getRequestId() {
- return 0;
- }
-
- public Object getResponse() {
- return null;
- }
-
- public boolean hadException() {
- return true;
- }
-
- public Throwable getException() {
- return except;
- }
- });
- }
}
- });
+ }, listener);
}
/**

Back to the top