-terminate automake session when project is disposed rubymine/112.662
authorEugene Zhuravlev <jeka@intellij.com>
Wed, 1 Feb 2012 11:01:55 +0000 (12:01 +0100)
committerEugene Zhuravlev <jeka@intellij.com>
Wed, 1 Feb 2012 11:08:30 +0000 (12:08 +0100)
-server side: cancel compile session when connection is closed

java/compiler/impl/src/com/intellij/compiler/CompileServerManager.java
jps/jps-builders/src/org/jetbrains/jps/server/ServerMessageHandler.java

index d2862e6289eadceb4b724b2be0096d327d369905..2e5f1dff121982c7ae66d5d20ea3e35176f9c7d9 100644 (file)
@@ -673,6 +673,9 @@ public class CompileServerManager implements ApplicationComponent{
 
     @Override
     public boolean handleBuildEvent(JpsRemoteProto.Message.Response.BuildEvent event) {
+      if (myProject.isDisposed()) {
+        return true;
+      }
       switch (event.getEventType()) {
         case BUILD_COMPLETED:
           if (event.hasCompletionStatus()) {
@@ -696,6 +699,9 @@ public class CompileServerManager implements ApplicationComponent{
 
     @Override
     public void handleCompileMessage(JpsRemoteProto.Message.Response.CompileMessage compileResponse) {
+      if (myProject.isDisposed()) {
+        return;
+      }
       final JpsRemoteProto.Message.Response.CompileMessage.Kind kind = compileResponse.getKind();
       if (kind == JpsRemoteProto.Message.Response.CompileMessage.Kind.ERROR) {
         informWolf(myProject, compileResponse);
index 0b49fee14964088239a921026542ec96953be2ac..5afd8908e8f8c388797ad1a4fb1ecab6bd075756 100644 (file)
@@ -63,18 +63,7 @@ class ServerMessageHandler extends SimpleChannelHandler {
         case CANCEL_BUILD_COMMAND:
           final JpsRemoteProto.Message.Request.CancelBuildCommand cancelCommand = request.getCancelBuildCommand();
           final UUID targetSessionId = ProtoUtil.fromProtoUUID(cancelCommand.getTargetSessionId());
-          synchronized (myBuildsInProgress) {
-            for (Iterator<Pair<RunnableFuture, CompilationTask>> it = myBuildsInProgress.iterator(); it.hasNext(); ) {
-              final Pair<RunnableFuture, CompilationTask> pair = it.next();
-              final CompilationTask task = pair.second;
-              if (task.getSessionId().equals(targetSessionId)) {
-                it.remove();
-                task.cancel();
-                pair.first.cancel(true);
-                break;
-              }
-            }
-          }
+          cancelSession(targetSessionId);
           reply = ProtoUtil.toMessage(sessionId, ProtoUtil.createCommandCompletedEvent(null));
           break;
         case SETUP_COMMAND:
@@ -158,6 +147,30 @@ class ServerMessageHandler extends SimpleChannelHandler {
     }
   }
 
+  private void cancelSession(UUID targetSessionId) {
+    synchronized (myBuildsInProgress) {
+      for (Iterator<Pair<RunnableFuture, CompilationTask>> it = myBuildsInProgress.iterator(); it.hasNext(); ) {
+        final Pair<RunnableFuture, CompilationTask> pair = it.next();
+        final CompilationTask task = pair.second;
+        if (task.getSessionId().equals(targetSessionId)) {
+          it.remove();
+          task.cancel();
+          pair.first.cancel(true);
+          break;
+        }
+      }
+    }
+  }
+
+  @Override
+  public void channelDisconnected(ChannelHandlerContext ctx, ChannelStateEvent e) throws Exception {
+    final Object attachment = ctx.getAttachment();
+    if (attachment instanceof UUID) {
+      cancelSession((UUID)attachment);
+    }
+    super.channelDisconnected(ctx, e);
+  }
+
   @Nullable
   private JpsRemoteProto.Message startBuild(UUID sessionId, final ChannelHandlerContext channelContext, JpsRemoteProto.Message.Request.CompilationRequest compileRequest) {
     if (!compileRequest.hasProjectId()) {
@@ -172,6 +185,7 @@ class ServerMessageHandler extends SimpleChannelHandler {
       case MAKE:
       case FORCED_COMPILATION:
       case REBUILD: {
+        channelContext.setAttachment(sessionId);
         final BuildType buildType = convertCompileType(compileType);
         final CompilationTask task = new CompilationTask(
           sessionId, channelContext, projectId, buildType, compileRequest.getModuleNameList(), compileRequest.getFilePathList()