From 8c9e4de9df0b5ef913fea63eb4c0f5f91d81e914 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 27 Apr 2016 13:23:05 +0300 Subject: [PATCH] IDEA-CR-10382 fixes --- .../impl/RemoteAgentThreadProxyCreator.java | 8 ++++++-- .../agent/impl/ThreadInvocationHandler.java | 20 +++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/agent/impl/RemoteAgentThreadProxyCreator.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/agent/impl/RemoteAgentThreadProxyCreator.java index 0bdc752f25f7..01babe3cb46e 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/agent/impl/RemoteAgentThreadProxyCreator.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/agent/impl/RemoteAgentThreadProxyCreator.java @@ -15,6 +15,7 @@ */ package com.intellij.remoteServer.agent.impl; +import com.intellij.util.concurrency.SequentialTaskExecutor; import org.jetbrains.annotations.Nullable; import java.lang.reflect.Proxy; @@ -38,7 +39,10 @@ public class RemoteAgentThreadProxyCreator { return agentInterface.cast(Proxy.newProxyInstance(callerClassLoader, new Class[]{agentInterface}, - new ThreadInvocationHandler(callerClassLoader, agentInstance, - myPreWrapperCreator))); + new ThreadInvocationHandler( + SequentialTaskExecutor.createSequentialApplicationPoolExecutor(), + callerClassLoader, agentInstance, + myPreWrapperCreator + ))); } } diff --git a/platform/remote-servers/impl/src/com/intellij/remoteServer/agent/impl/ThreadInvocationHandler.java b/platform/remote-servers/impl/src/com/intellij/remoteServer/agent/impl/ThreadInvocationHandler.java index 65699f0421e7..a133ae782340 100644 --- a/platform/remote-servers/impl/src/com/intellij/remoteServer/agent/impl/ThreadInvocationHandler.java +++ b/platform/remote-servers/impl/src/com/intellij/remoteServer/agent/impl/ThreadInvocationHandler.java @@ -41,9 +41,9 @@ public class ThreadInvocationHandler implements InvocationHandler { private final Object myTarget; private final ChildWrapperCreator myPreWrapperFactory; - public ThreadInvocationHandler(ClassLoader callerClassLoader, Object target, + public ThreadInvocationHandler(ExecutorService taskExecutor, ClassLoader callerClassLoader, Object target, @Nullable ChildWrapperCreator preWrapperCreator) { - myTaskExecutor = com.intellij.util.concurrency.SequentialTaskExecutor.createSequentialApplicationPoolExecutor(); + myTaskExecutor = taskExecutor; myCallerClassLoader = callerClassLoader; myTarget = target; myPreWrapperFactory = preWrapperCreator; @@ -74,7 +74,7 @@ public class ThreadInvocationHandler implements InvocationHandler { boolean childCall = method.getAnnotation(ChildCall.class) != null; if (childCall) { - Object child = immediateCall ? taskCallable.call() : execute(taskCallable); + Object child = immediateCall ? taskCallable.call() : executeAndWait(taskCallable); if (child == null) { return null; } @@ -118,7 +118,7 @@ public class ThreadInvocationHandler implements InvocationHandler { return null; } else { - return execute(taskCallable); + return executeAndWait(taskCallable); } } finally { @@ -129,8 +129,9 @@ public class ThreadInvocationHandler implements InvocationHandler { } } - private Object execute(Callable taskCallable) throws Throwable { - Object child;Future future = myTaskExecutor.submit(taskCallable); + private Object executeAndWait(Callable taskCallable) throws Throwable { + Object child; + Future future = myTaskExecutor.submit(taskCallable); try { child = future.get(); } @@ -168,7 +169,10 @@ public class ThreadInvocationHandler implements InvocationHandler { return Proxy.newProxyInstance(myCallerClassLoader, new Class[]{callerChildInterface}, - new ThreadInvocationHandler(myCallerClassLoader, preWrappedChild, - myPreWrapperFactory)); + new ThreadInvocationHandler( + myTaskExecutor, + myCallerClassLoader, preWrappedChild, + myPreWrapperFactory + )); } }