Преглед изворни кода

Merge pull request #105 from csmith/whois

Update to MBassador 1.2.4.
pull/106/head
Greg Holmes пре 8 година
родитељ
комит
be32186481

+ 1
- 1
build.gradle Прегледај датотеку

@@ -94,7 +94,7 @@ subprojects {
94 94
         compile group: 'com.squareup.dagger', name: 'dagger', version: '1.2.1'
95 95
         compile group: 'com.google.guava', name:'guava', version: '18.0'
96 96
 
97
-        compile group: 'net.engio', name: 'mbassador', version: '1.2.0'
97
+        compile group: 'net.engio', name: 'mbassador', version: '1.2.4'
98 98
         compile group: 'de.odysseus.juel', name: 'juel-api', version: '2.2.7'
99 99
         compile group: 'de.odysseus.juel', name: 'juel-impl', version: '2.2.7'
100 100
         compile group: 'de.odysseus.juel', name: 'juel-spi', version: '2.2.7'

+ 27
- 1
common/src/com/dmdirc/parser/common/BaseParser.java Прегледај датотеку

@@ -22,6 +22,7 @@
22 22
 
23 23
 package com.dmdirc.parser.common;
24 24
 
25
+import com.dmdirc.parser.events.ParserErrorEvent;
25 26
 import com.dmdirc.parser.interfaces.ChannelInfo;
26 27
 import com.dmdirc.parser.interfaces.ClientInfo;
27 28
 
@@ -31,8 +32,11 @@ import java.net.ProxySelector;
31 32
 import java.net.SocketAddress;
32 33
 import java.net.URI;
33 34
 import java.net.URISyntaxException;
35
+import java.util.Date;
34 36
 import java.util.List;
35 37
 
38
+import net.engio.mbassy.bus.error.PublicationError;
39
+
36 40
 /**
37 41
  * Implements common base functionality for parsers.
38 42
  * <p>
@@ -41,6 +45,8 @@ import java.util.List;
41 45
  */
42 46
 public abstract class BaseParser extends ThreadedParser {
43 47
 
48
+    private final Object errorHandlerLock = new Object();
49
+
44 50
     /** The URI that this parser was constructed for. */
45 51
     private final URI uri;
46 52
 
@@ -76,7 +82,27 @@ public abstract class BaseParser extends ThreadedParser {
76 82
     public BaseParser(final URI uri) {
77 83
         this.uri = uri;
78 84
 
79
-        callbackManager = new CallbackManager(this);
85
+        callbackManager = new CallbackManager(this::handleCallbackError);
86
+    }
87
+
88
+    @SuppressWarnings({
89
+            "ThrowableResultOfMethodCallIgnored",
90
+            "CallToPrintStackTrace",
91
+            "UseOfSystemOutOrSystemErr"
92
+    })
93
+    private void handleCallbackError(final PublicationError e) {
94
+        if (Thread.holdsLock(errorHandlerLock)) {
95
+            // ABORT ABORT ABORT - we're publishing an error on the same thread we just tried
96
+            // to publish an error on. Something in the error reporting pipeline must be
97
+            // breaking, so don't try adding any more errors.
98
+            System.err.println("ERROR: Error when reporting error");
99
+            e.getCause().printStackTrace();
100
+            return;
101
+        }
102
+
103
+        synchronized (errorHandlerLock) {
104
+            callbackManager.publish(new ParserErrorEvent(this, new Date(), e.getCause()));
105
+        }
80 106
     }
81 107
 
82 108
     @Override

+ 5
- 41
common/src/com/dmdirc/parser/common/CallbackManager.java Прегледај датотеку

@@ -22,15 +22,12 @@
22 22
 
23 23
 package com.dmdirc.parser.common;
24 24
 
25
-import com.dmdirc.parser.events.ParserErrorEvent;
26 25
 import com.dmdirc.parser.events.ParserEvent;
27
-import com.dmdirc.parser.interfaces.Parser;
28
-
29
-import java.util.Date;
30 26
 
31 27
 import net.engio.mbassy.bus.MBassador;
32 28
 import net.engio.mbassy.bus.config.BusConfiguration;
33 29
 import net.engio.mbassy.bus.config.Feature;
30
+import net.engio.mbassy.bus.error.IPublicationErrorHandler;
34 31
 
35 32
 /**
36 33
  * Parser Callback Manager.
@@ -38,44 +35,11 @@ import net.engio.mbassy.bus.config.Feature;
38 35
  */
39 36
 public class CallbackManager extends MBassador<ParserEvent> {
40 37
 
41
-    private final Object errorHandlerLock = new Object();
42
-    private final Parser parser;
43
-
44
-    public CallbackManager(final Parser parser) {
38
+    public CallbackManager(final IPublicationErrorHandler errorHandler) {
45 39
         super(new BusConfiguration().addFeature(Feature.SyncPubSub.Default())
46
-                .addFeature(Feature.AsynchronousHandlerInvocation.Default(1, 1)).addFeature(
47
-                        Feature.AsynchronousMessageDispatch.Default()
48
-                                .setNumberOfMessageDispatchers(1)));
49
-        this.parser = parser;
50
-        setupErrorHandler();
51
-    }
52
-
53
-    @SuppressWarnings("TypeMayBeWeakened")
54
-    public CallbackManager(final BusConfiguration configuration, final Parser parser) {
55
-        super(configuration);
56
-        setupErrorHandler();
57
-        this.parser = parser;
40
+                .addFeature(Feature.AsynchronousHandlerInvocation.Default(1, 1))
41
+                .addFeature(Feature.AsynchronousMessageDispatch.Default()
42
+                        .setNumberOfMessageDispatchers(1)));
58 43
     }
59 44
 
60
-    @SuppressWarnings({
61
-            "ThrowableResultOfMethodCallIgnored",
62
-            "CallToPrintStackTrace",
63
-            "UseOfSystemOutOrSystemErr"
64
-    })
65
-    private void setupErrorHandler() {
66
-        addErrorHandler(e -> {
67
-            if (Thread.holdsLock(errorHandlerLock)) {
68
-                // ABORT ABORT ABORT - we're publishing an error on the same thread we just tried
69
-                // to publish an error on. Something in the error reporting pipeline must be
70
-                // breaking, so don't try adding any more errors.
71
-                System.err.println("ERROR: Error when reporting error");
72
-                e.getCause().printStackTrace();
73
-                return;
74
-            }
75
-
76
-            synchronized (errorHandlerLock) {
77
-                publish(new ParserErrorEvent(parser, new Date(), e.getCause()));
78
-            }
79
-        });
80
-    }
81 45
 }

Loading…
Откажи
Сачувај