debugger event queue: more robust command cancellation when queue is closed
authorEugene Zhuravlev <jeka@intellij.com>
Mon, 30 Jan 2012 15:43:58 +0000 (16:43 +0100)
committerEugene Zhuravlev <jeka@intellij.com>
Mon, 30 Jan 2012 15:55:25 +0000 (16:55 +0100)
java/debugger/impl/src/com/intellij/debugger/engine/DebuggerManagerThreadImpl.java
java/debugger/impl/src/com/intellij/debugger/impl/EventQueue.java
java/debugger/impl/src/com/intellij/debugger/impl/EventQueueClosedException.java
java/debugger/impl/src/com/intellij/debugger/impl/InvokeAndWaitThread.java
java/debugger/impl/src/com/intellij/debugger/impl/InvokeThread.java

index 027b82b25641fc1e7be06df2cc3541b30508c70a..f5569d5bdb1f54b4ae9bfcfb37b114926fe5bef7 100644 (file)
@@ -73,22 +73,20 @@ public class DebuggerManagerThreadImpl extends InvokeAndWaitThread<DebuggerComma
     }
   }
 
-  public void pushBack(DebuggerCommandImpl managerCommand) {
-    if(myEvents.isClosed()) {
+  public boolean pushBack(DebuggerCommandImpl managerCommand) {
+    final boolean pushed = super.pushBack(managerCommand);
+    if (!pushed) {
       managerCommand.notifyCancelled();
     }
-    else {
-      super.pushBack(managerCommand);
-    }
+    return pushed;
   }
 
-  public void schedule(DebuggerCommandImpl managerCommand) {
-    if(myEvents.isClosed()) {
+  public boolean schedule(DebuggerCommandImpl managerCommand) {
+    final boolean scheduled = super.schedule(managerCommand);
+    if (!scheduled) {
       managerCommand.notifyCancelled();
     }
-    else {
-      super.schedule(managerCommand);
-    }
+    return scheduled;
   }
 
   /**
index d222c97888d99534da56c8966b7d72ba28526938..a7bd73ae541a39293e2439de5a82cddf155332dc 100644 (file)
@@ -45,36 +45,42 @@ public class EventQueue<E> {
     }
   }
 
-  public void pushBack(@NotNull E event, int priority) {
+  public boolean pushBack(@NotNull E event, int priority) {
     if(LOG.isDebugEnabled()) {
       LOG.debug("pushBack event " + event);
     }
 
     myLock.lock();
     try {
-      assertOpen();
+      if (isClosed()) {
+        return false;
+      }
       getEventsList(priority).addFirst(event);
       myEventsAvailable.signalAll();
     }
     finally {
       myLock.unlock();
     }
+    return true;
   }
 
-  public void put(@NotNull E event, int priority) {
+  public boolean put(@NotNull E event, int priority) {
     if(LOG.isDebugEnabled()) {
       LOG.debug("put event " + event);
     }
 
     myLock.lock();
     try {
-      assertOpen();
+      if (isClosed()) {
+        return false;
+      }
       getEventsList(priority).offer(event);
       myEventsAvailable.signalAll();
     }
     finally {
       myLock.unlock();
     }
+    return true;
   }
 
   private LinkedList<E> getEventsList(final int priority) {
@@ -84,7 +90,6 @@ public class EventQueue<E> {
   public void close(){
     myLock.lock();
     try {
-      assertOpen();
       myIsClosed = true;
       myEventsAvailable.signalAll();
     }
@@ -93,10 +98,6 @@ public class EventQueue<E> {
     }
   }
 
-  private void assertOpen() {
-    if (myIsClosed) throw new AssertionError("Already closed");
-  }
-
   private E getEvent() throws EventQueueClosedException {
     myLock.lock();
     try {
index be0cd485b30bd22f48b4d060c43b8ea371425628..d58b663f522a70d0b17455255538565dd901e503 100644 (file)
@@ -19,4 +19,8 @@ package com.intellij.debugger.impl;
  * @author lex
  */
 public class EventQueueClosedException extends Exception {
+  @Override
+  public Throwable fillInStackTrace() {
+    return this;
+  }
 }
index 3278e59f1764cb32351f9790a8788bd2b2c9d812..3576c86b4f65052a0c2337c56f8b55d50865e674 100644 (file)
@@ -28,12 +28,12 @@ public abstract class InvokeAndWaitThread<E extends DebuggerTask> extends Invoke
    * !!! Do not remove this code !!!
    * Otherwise it will be impossible to override schedule method
    */
-  public void schedule(E e) {
-    super.schedule(e);
+  public boolean schedule(E e) {
+    return super.schedule(e);
   }
 
-  public void pushBack(E e) {
-    super.pushBack(e);
+  public boolean pushBack(E e) {
+    return super.pushBack(e);
   }
 
   public void invokeAndWait(final E runnable) {
index b3ddf3a90ed25e0adabdd4b37896ed3e49fa4195..e8835275f907f86126fb4f53df3455e8dde96149 100644 (file)
@@ -172,18 +172,18 @@ public abstract class InvokeThread<E extends PrioritizedTask> {
     return request != null? request.getOwner() : null;
   }
 
-  public void schedule(E r) {
+  public boolean schedule(E r) {
     if(LOG.isDebugEnabled()) {
       LOG.debug("schedule " + r + " in " + this);
     }
-    myEvents.put(r, r.getPriority().ordinal());
+    return myEvents.put(r, r.getPriority().ordinal());
   }
 
-  public void pushBack(E r) {
+  public boolean pushBack(E r) {
     if(LOG.isDebugEnabled()) {
       LOG.debug("pushBack " + r + " in " + this);
     }
-    myEvents.pushBack(r, r.getPriority().ordinal());
+    return myEvents.pushBack(r, r.getPriority().ordinal());
   }
 
   protected void switchToRequest(WorkerThreadRequest newWorkerThread) {