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
     private final List<ProgramError> errors;
74
     private final List<ProgramError> errors;
75
     /** Listener list. */
75
     /** Listener list. */
76
     private final ListenerList errorListeners = new ListenerList();
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
     /** Event bus to subscribe and publish errors on. */
79
     /** Event bus to subscribe and publish errors on. */
80
     private DMDircMBassador eventBus;
80
     private DMDircMBassador eventBus;
81
     /** Whether or not to send error reports. */
81
     /** Whether or not to send error reports. */
98
     @Inject
98
     @Inject
99
     public ErrorManager() {
99
     public ErrorManager() {
100
         errors = new LinkedList<>();
100
         errors = new LinkedList<>();
101
+        countDownLatch = new CountDownLatch(2);
101
     }
102
     }
102
 
103
 
103
     /**
104
     /**
408
             }
409
             }
409
             restart = false;
410
             restart = false;
410
         } else {
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
             fed.setVisible(true);
414
             fed.setVisible(true);
413
             try {
415
             try {
414
-                errorSemaphore.await();
416
+                countDownLatch.await();
415
             } catch (InterruptedException ex) {
417
             } catch (InterruptedException ex) {
416
                 //Nevermind, carry on
418
                 //Nevermind, carry on
417
             }
419
             }

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

63
 
63
 
64
     /** Serialisation version ID. */
64
     /** Serialisation version ID. */
65
     private static final long serialVersionUID = 3;
65
     private static final long serialVersionUID = 3;
66
-    /** Do we need to restart? Else we quit. */
67
-    private boolean restart = true;
68
     /** Fatal error to be shown in this dialog. */
66
     /** Fatal error to be shown in this dialog. */
69
     private final ProgramError error;
67
     private final ProgramError error;
70
     /** Error manager to report the error to. */
68
     /** Error manager to report the error to. */
71
     private final ErrorManager errorManager;
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
     /** Restart client Button. */
74
     /** Restart client Button. */
73
     private JButton restartButton;
75
     private JButton restartButton;
74
     /** Quit client button. */
76
     /** Quit client button. */
83
     private ImageIcon icon;
85
     private ImageIcon icon;
84
     /** Stack trace scroll pane. */
86
     /** Stack trace scroll pane. */
85
     private JScrollPane scrollPane;
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
      * Creates a new fatal error dialog.
92
      * Creates a new fatal error dialog.
92
      * @param error Error
94
      * @param error Error
93
      */
95
      */
94
     public FatalErrorDialog(final ProgramError error, final ErrorManager errorManager,
96
     public FatalErrorDialog(final ProgramError error, final ErrorManager errorManager,
95
-            final CountDownLatch errorSemaphore) {
97
+            final CountDownLatch countDownLatch, final boolean sendReports) {
96
         super(null, Dialog.ModalityType.TOOLKIT_MODAL);
98
         super(null, Dialog.ModalityType.TOOLKIT_MODAL);
97
 
99
 
98
         setModal(true);
100
         setModal(true);
99
 
101
 
100
         this.error = error;
102
         this.error = error;
101
         this.errorManager = errorManager;
103
         this.errorManager = errorManager;
102
-        this.errorSemaphore = errorSemaphore;
104
+        this.countDownLatch = countDownLatch;
105
+        this.sendReports = sendReports;
103
 
106
 
104
         initComponents();
107
         initComponents();
105
         layoutComponents();
108
         layoutComponents();
236
         } else {
239
         } else {
237
             dispose();
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
                 restartButton.setEnabled(status.isTerminal());
313
                 restartButton.setEnabled(status.isTerminal());
306
                 updateSendButtonText(status);
314
                 updateSendButtonText(status);
307
             });
315
             });
308
-            errorSemaphore.countDown();
316
+            countDownLatch.countDown();
309
         }
317
         }
310
     }
318
     }
311
 
319
 

Loading…
Cancel
Save