Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorslewis2014-03-24 16:21:55 +0000
committerslewis2014-03-24 16:21:55 +0000
commit4a28b10d002806219f531aebc19addeecb7459e0 (patch)
tree0f40c3681270b300c9f90004fe9b9750c8ec6214
parentc1107a6bb5f98c26d4d141f42fb7f9b12d4d3d37 (diff)
downloadorg.eclipse.ecf-4a28b10d002806219f531aebc19addeecb7459e0.tar.gz
org.eclipse.ecf-4a28b10d002806219f531aebc19addeecb7459e0.tar.xz
org.eclipse.ecf-4a28b10d002806219f531aebc19addeecb7459e0.zip
Further generalizations for
https://bugs.eclipse.org/bugs/show_bug.cgi?id=430963 Change-Id: I0000000000000000000000000000000000000000
-rw-r--r--framework/bundles/org.eclipse.ecf.remoteservice/META-INF/MANIFEST.MF2
-rw-r--r--framework/bundles/org.eclipse.ecf.remoteservice/src/org/eclipse/ecf/remoteservice/AbstractRemoteService.java87
2 files changed, 45 insertions, 44 deletions
diff --git a/framework/bundles/org.eclipse.ecf.remoteservice/META-INF/MANIFEST.MF b/framework/bundles/org.eclipse.ecf.remoteservice/META-INF/MANIFEST.MF
index 3d2b46166..1b52fcb33 100644
--- a/framework/bundles/org.eclipse.ecf.remoteservice/META-INF/MANIFEST.MF
+++ b/framework/bundles/org.eclipse.ecf.remoteservice/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %plugin.name
Bundle-SymbolicName: org.eclipse.ecf.remoteservice
-Bundle-Version: 8.3.0.qualifier
+Bundle-Version: 8.4.0.qualifier
Bundle-Activator: org.eclipse.ecf.internal.remoteservice.Activator
Bundle-Vendor: %plugin.provider
Bundle-Localization: plugin
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 b24ce6b50..2d65eed5b 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
@@ -395,17 +395,17 @@ public abstract class AbstractRemoteService implements IRemoteService, Invocatio
}
/**
- * @since 3.3
+ * @since 8.4
*/
- protected class AsyncArgs {
+ public class AsyncArgs {
private IRemoteCallListener listener;
private Object[] args;
- private boolean isIFuture;
+ private Class returnType;
- public AsyncArgs(Object[] originalArgs, boolean isIFuture) {
+ public AsyncArgs(Object[] originalArgs, Class returnType) {
this.listener = null;
this.args = originalArgs;
- this.isIFuture = isIFuture;
+ this.returnType = returnType;
}
public AsyncArgs(IRemoteCallListener listener, Object[] originalArgs) {
@@ -426,11 +426,8 @@ public abstract class AbstractRemoteService implements IRemoteService, Invocatio
return args;
}
- /**
- * @since 8.2
- */
- public boolean isIFuture() {
- return isIFuture;
+ public Class getReturnType() {
+ return returnType;
}
}
@@ -440,8 +437,7 @@ public abstract class AbstractRemoteService implements IRemoteService, Invocatio
protected Object invokeAsync(final Method method, final Object[] args) throws Throwable {
final String invokeMethodName = getAsyncInvokeMethodName(method);
final AsyncArgs asyncArgs = getAsyncArgs(method, args);
- IRemoteCallListener listener = asyncArgs.getListener();
- IRemoteCall call = new IRemoteCall() {
+ return callAsync(new IRemoteCall() {
public String getMethod() {
return invokeMethodName;
}
@@ -453,14 +449,23 @@ public abstract class AbstractRemoteService implements IRemoteService, Invocatio
public long getTimeout() {
return DEFAULT_TIMEOUT;
}
- };
- // IFuture or Future will have listener == null
- if (listener == null) {
- if (asyncArgs.isIFuture())
- return callAsync(call);
- return callFutureAsync(call);
- }
- return callAsyncWithResult(call, listener);
+ }, asyncArgs.getListener(), asyncArgs.getReturnType());
+ }
+
+ /**
+ * @since 8.4
+ */
+ protected Object callAsync(IRemoteCall call, IRemoteCallListener listener, Class returnType) {
+ return (listener != null) ? callAsyncWithResult(call, listener) : callFuture(call, returnType);
+ }
+
+ /**
+ * @since 8.4
+ */
+ protected Object callFuture(IRemoteCall call, Class returnType) {
+ if (IFuture.class.isAssignableFrom(returnType))
+ return callAsync(call);
+ return callFutureAsync(call);
}
/**
@@ -492,30 +497,26 @@ public abstract class AbstractRemoteService implements IRemoteService, Invocatio
IRemoteCallListener listener = null;
Class returnType = method.getReturnType();
// If the return type is of type java.util.concurrent.Future, then we return
- if (returnType.isAssignableFrom(Future.class)) {
- return new AsyncArgs(args, false);
- } else if (returnType.isAssignableFrom(IFuture.class)) {
- return new AsyncArgs(args, true);
- } else {
- // If the provided args do *not* include an IRemoteCallListener then we have a problem
- if (args == null || args.length == 0)
- throw new IllegalArgumentException("Async calls must include a IRemoteCallListener instance as the last argument"); //$NON-NLS-1$
- // Get the last arg
- Object lastArg = args[args.length - 1];
- // If it's an IRemoteCallListener implementer directly, then just cast and return
- if (lastArg instanceof IRemoteCallListener) {
- listener = (IRemoteCallListener) lastArg;
- }
- // If it's an implementation of IAsyncCallback, then create a new listener based upon
- // callback and return
- if (lastArg instanceof IAsyncCallback) {
- listener = new CallbackRemoteCallListener((IAsyncCallback) lastArg);
- }
- // If the last are is not an instance of IRemoteCallListener then there is a problem
- if (listener == null)
- throw new IllegalArgumentException("Last argument must be an instance of IRemoteCallListener"); //$NON-NLS-1$
- return new AsyncArgs(listener, args);
+ if (Future.class.isAssignableFrom(returnType) || IFuture.class.isAssignableFrom(returnType))
+ return new AsyncArgs(args, returnType);
+ // If the provided args do *not* include an IRemoteCallListener then we have a problem
+ if (args == null || args.length == 0)
+ throw new IllegalArgumentException("Async calls must include a IRemoteCallListener instance as the last argument"); //$NON-NLS-1$
+ // Get the last arg
+ Object lastArg = args[args.length - 1];
+ // If it's an IRemoteCallListener implementer directly, then just cast and return
+ if (lastArg instanceof IRemoteCallListener) {
+ listener = (IRemoteCallListener) lastArg;
+ }
+ // If it's an implementation of IAsyncCallback, then create a new listener based upon
+ // callback and return
+ if (lastArg instanceof IAsyncCallback) {
+ listener = new CallbackRemoteCallListener((IAsyncCallback) lastArg);
}
+ // If the last are is not an instance of IRemoteCallListener then there is a problem
+ if (listener == null)
+ throw new IllegalArgumentException("Last argument must be an instance of IRemoteCallListener"); //$NON-NLS-1$
+ return new AsyncArgs(listener, args);
}
/**

Back to the top