Browse Source

Improve logic a bit, rename field.

pull/373/head
Greg Holmes 9 years ago
parent
commit
b519349754
2 changed files with 22 additions and 12 deletions
  1. 6
    4
      src/com/dmdirc/logger/ErrorManager.java
  2. 16
    8
      src/com/dmdirc/ui/FatalErrorDialog.java

+ 6
- 4
src/com/dmdirc/logger/ErrorManager.java View File

@@ -74,8 +74,8 @@ public class ErrorManager {
74 74
     private final List<ProgramError> errors;
75 75
     /** Listener list. */
76 76
     private final ListenerList errorListeners = new ListenerList();
77
-    /** Semaphore used to wait for fatal error to report. */
78
-    private final CountDownLatch errorSemaphore = new CountDownLatch(2);
77
+    /** Countdown latch to wait for FED with. */
78
+    private final CountDownLatch countDownLatch;
79 79
     /** Event bus to subscribe and publish errors on. */
80 80
     private DMDircMBassador eventBus;
81 81
     /** Whether or not to send error reports. */
@@ -98,6 +98,7 @@ public class ErrorManager {
98 98
     @Inject
99 99
     public ErrorManager() {
100 100
         errors = new LinkedList<>();
101
+        countDownLatch = new CountDownLatch(2);
101 102
     }
102 103
 
103 104
     /**
@@ -408,10 +409,11 @@ public class ErrorManager {
408 409
             }
409 410
             restart = false;
410 411
         } else {
411
-            final FatalErrorDialog fed = new FatalErrorDialog(event.getError(), this, errorSemaphore);
412
+            final FatalErrorDialog fed = new FatalErrorDialog(event.getError(), this,
413
+                    countDownLatch, sendReports);
412 414
             fed.setVisible(true);
413 415
             try {
414
-                errorSemaphore.await();
416
+                countDownLatch.await();
415 417
             } catch (InterruptedException ex) {
416 418
                 //Nevermind, carry on
417 419
             }

+ 16
- 8
src/com/dmdirc/ui/FatalErrorDialog.java View File

@@ -63,12 +63,14 @@ public final class FatalErrorDialog extends JDialog implements ActionListener,
63 63
 
64 64
     /** Serialisation version ID. */
65 65
     private static final long serialVersionUID = 3;
66
-    /** Do we need to restart? Else we quit. */
67
-    private boolean restart = true;
68 66
     /** Fatal error to be shown in this dialog. */
69 67
     private final ProgramError error;
70 68
     /** Error manager to report the error to. */
71 69
     private final ErrorManager errorManager;
70
+    /** Countdown latch. */
71
+    private final CountDownLatch countDownLatch;
72
+    /** Are we auto sending errors? */
73
+    private final boolean sendReports;
72 74
     /** Restart client Button. */
73 75
     private JButton restartButton;
74 76
     /** Quit client button. */
@@ -83,8 +85,8 @@ public final class FatalErrorDialog extends JDialog implements ActionListener,
83 85
     private ImageIcon icon;
84 86
     /** Stack trace scroll pane. */
85 87
     private JScrollPane scrollPane;
86
-    /** Error status semaphore. */
87
-    private final CountDownLatch errorSemaphore;
88
+    /** Do we need to restart? Else we quit. */
89
+    private boolean restart = true;
88 90
 
89 91
     /**
90 92
      * Creates a new fatal error dialog.
@@ -92,14 +94,15 @@ public final class FatalErrorDialog extends JDialog implements ActionListener,
92 94
      * @param error Error
93 95
      */
94 96
     public FatalErrorDialog(final ProgramError error, final ErrorManager errorManager,
95
-            final CountDownLatch errorSemaphore) {
97
+            final CountDownLatch countDownLatch, final boolean sendReports) {
96 98
         super(null, Dialog.ModalityType.TOOLKIT_MODAL);
97 99
 
98 100
         setModal(true);
99 101
 
100 102
         this.error = error;
101 103
         this.errorManager = errorManager;
102
-        this.errorSemaphore = errorSemaphore;
104
+        this.countDownLatch = countDownLatch;
105
+        this.sendReports = sendReports;
103 106
 
104 107
         initComponents();
105 108
         layoutComponents();
@@ -236,7 +239,12 @@ public final class FatalErrorDialog extends JDialog implements ActionListener,
236 239
         } else {
237 240
             dispose();
238 241
         }
239
-        errorSemaphore.countDown();
242
+        if (!sendReports) {
243
+            countDownLatch.countDown();
244
+            countDownLatch.countDown();
245
+        } else {
246
+            countDownLatch.countDown();
247
+        }
240 248
     }
241 249
 
242 250
     /**
@@ -305,7 +313,7 @@ public final class FatalErrorDialog extends JDialog implements ActionListener,
305 313
                 restartButton.setEnabled(status.isTerminal());
306 314
                 updateSendButtonText(status);
307 315
             });
308
-            errorSemaphore.countDown();
316
+            countDownLatch.countDown();
309 317
         }
310 318
     }
311 319
 

Loading…
Cancel
Save