|
@@ -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
|
}
|