diff options
author | slewis | 2013-10-25 19:08:00 +0000 |
---|---|---|
committer | slewis | 2013-10-25 19:08:00 +0000 |
commit | 70aa545dc4edc139f6fc87d0fe142b9cbb71a7a0 (patch) | |
tree | d7fa3adb37634c31de04dec835e5a2683d8ddabb /framework | |
parent | 8e6b43960011b511ec45e615c995f1747212450e (diff) | |
download | org.eclipse.ecf-70aa545dc4edc139f6fc87d0fe142b9cbb71a7a0.tar.gz org.eclipse.ecf-70aa545dc4edc139f6fc87d0fe142b9cbb71a7a0.tar.xz org.eclipse.ecf-70aa545dc4edc139f6fc87d0fe142b9cbb71a7a0.zip |
Greator support for provider customization of ExecutorService/Future and
IExecutor/IFuture usage in asynchronous proxies. For bug 420290
Diffstat (limited to 'framework')
-rw-r--r-- | framework/bundles/org.eclipse.ecf.remoteservice/src/org/eclipse/ecf/remoteservice/AbstractRemoteService.java | 96 |
1 files changed, 70 insertions, 26 deletions
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 fe0d519a7..462d5f637 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 @@ -16,8 +16,7 @@ import org.eclipse.core.runtime.*; import org.eclipse.ecf.core.jobs.JobsExecutor; import org.eclipse.ecf.core.util.ECFException; import org.eclipse.ecf.internal.remoteservice.Activator; -import org.eclipse.equinox.concurrent.future.IFuture; -import org.eclipse.equinox.concurrent.future.IProgressRunnable; +import org.eclipse.equinox.concurrent.future.*; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceException; import org.osgi.util.tracker.ServiceTracker; @@ -33,6 +32,57 @@ public abstract class AbstractRemoteService implements IRemoteService, Invocatio protected static final Object[] EMPTY_ARGS = new Object[0]; + /** + * @since 8.2 + */ + protected int futureExecutorServiceMaxThreads = Integer.parseInt(System.getProperty("ecf.remoteservice.futureExecutorServiceMaxThreads", "10")); //$NON-NLS-1$ //$NON-NLS-2$ + + /** + * @since 8.2 + */ + protected ExecutorService futureExecutorService; + + /** + * @since 8.2 + */ + protected ExecutorService getFutureExecutorService(IRemoteCall call) { + synchronized (this) { + if (futureExecutorService == null) + futureExecutorService = Executors.newFixedThreadPool(futureExecutorServiceMaxThreads); + } + return futureExecutorService; + } + + /** + * @since 8.2 + */ + protected void setFutureExecutorService(ExecutorService executorService) { + this.futureExecutorService = executorService; + } + + /** + * @since 8.2 + */ + protected IExecutor iFutureExecutor; + + /** + * @since 8.2 + */ + protected IExecutor getIFutureExecutor(IRemoteCall call) { + synchronized (this) { + if (iFutureExecutor == null) + iFutureExecutor = new JobsExecutor("RSJobs[rsID=" + getRemoteServiceID() + "]"); //$NON-NLS-1$ //$NON-NLS-2$ + } + return iFutureExecutor; + } + + /** + * @since 8.2 + */ + protected void setIFutureExecutor(IExecutor executor) { + this.iFutureExecutor = executor; + } + protected abstract String[] getInterfaceClassNames(); protected abstract IRemoteServiceID getRemoteServiceID(); @@ -59,7 +109,9 @@ public abstract class AbstractRemoteService implements IRemoteService, Invocatio } public IFuture callAsync(final IRemoteCall call) { - JobsExecutor executor = new JobsExecutor("callAsynch " + call.getMethod()); //$NON-NLS-1$ + IExecutor executor = getIFutureExecutor(call); + if (executor == null) + throw new ServiceException("iFuture executor is null. Cannot callAsync remote method=" + call.getMethod()); //$NON-NLS-1$ return executor.execute(new IProgressRunnable() { public Object run(IProgressMonitor monitor) throws Exception { return callSync(call); @@ -384,9 +436,9 @@ public abstract class AbstractRemoteService implements IRemoteService, Invocatio * @since 8.2 */ protected Future callFutureAsync(final IRemoteCall call) { - ExecutorService executorService = getFutureExecutorService(); + ExecutorService executorService = getFutureExecutorService(call); if (executorService == null) - throw new ServiceException("Future executor service is null. Cannot call method=" + call.getMethod()); //$NON-NLS-1$ + throw new ServiceException("future executor service is null. . Cannot callAsync remote method=" + call.getMethod()); //$NON-NLS-1$ return executorService.submit(new Callable() { public Object call() throws Exception { return callSync(call); @@ -395,27 +447,6 @@ public abstract class AbstractRemoteService implements IRemoteService, Invocatio } /** - * @since 8.2 - */ - protected int futureExecutorServiceMaxThreads = 10; - - /** - * @since 8.2 - */ - protected ExecutorService futureExecutorService; - - /** - * @since 8.2 - */ - protected ExecutorService getFutureExecutorService() { - synchronized (this) { - if (futureExecutorService == null) - futureExecutorService = Executors.newFixedThreadPool(futureExecutorServiceMaxThreads); - } - return futureExecutorService; - } - - /** * @since 3.3 */ protected AsyncArgs getAsyncArgs(Method method, Object[] args) { @@ -467,4 +498,17 @@ public abstract class AbstractRemoteService implements IRemoteService, Invocatio if (a != null) a.log(new Status(IStatus.WARNING, Activator.PLUGIN_ID, string, e)); } + + /** + * @since 8.2 + */ + public void close() { + synchronized (this) { + if (futureExecutorService != null) { + futureExecutorService.shutdownNow(); + futureExecutorService = null; + } + iFutureExecutor = null; + } + } } |