Ver código fonte

Introduce an event bus.

Change-Id: I64cbc0e0395e8c214d54742e2d25562d1ce325c4
Reviewed-on: http://gerrit.dmdirc.com/2955
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
tags/0.8rc1
Chris Smith 10 anos atrás
pai
commit
8388fc39ac

+ 15
- 0
src/com/dmdirc/ClientModule.java Ver arquivo

@@ -60,11 +60,15 @@ import com.dmdirc.updater.UpdaterModule;
60 60
 import com.dmdirc.updater.Version;
61 61
 import com.dmdirc.updater.manager.UpdateManager;
62 62
 
63
+import com.google.common.eventbus.AsyncEventBus;
64
+import com.google.common.eventbus.EventBus;
65
+
63 66
 import java.awt.GraphicsEnvironment;
64 67
 import java.io.File;
65 68
 import java.text.SimpleDateFormat;
66 69
 import java.util.Date;
67 70
 import java.util.Set;
71
+import java.util.concurrent.Executors;
68 72
 
69 73
 import javax.inject.Provider;
70 74
 import javax.inject.Qualifier;
@@ -398,6 +402,17 @@ public class ClientModule {
398 402
         return identityManager;
399 403
     }
400 404
 
405
+    /**
406
+     * Provides the event bus the client will use for dispatching events.
407
+     *
408
+     * @return An event bus for the client to use.
409
+     */
410
+    @Provides
411
+    @Singleton
412
+    public EventBus getEventBus() {
413
+        return new AsyncEventBus(Executors.newFixedThreadPool(1));
414
+    }
415
+
401 416
     /**
402 417
      * Sets the object graph that will be injected. Must be called before any provider method.
403 418
      *

+ 10
- 0
src/com/dmdirc/Main.java Ver arquivo

@@ -28,6 +28,7 @@ import com.dmdirc.actions.ColourActionComparison;
28 28
 import com.dmdirc.actions.CoreActionType;
29 29
 import com.dmdirc.commandline.CommandLineParser;
30 30
 import com.dmdirc.commandparser.CommandManager;
31
+import com.dmdirc.events.ClientOpenedEvent;
31 32
 import com.dmdirc.interfaces.CommandController.CommandDetails;
32 33
 import com.dmdirc.interfaces.config.IdentityController;
33 34
 import com.dmdirc.interfaces.ui.UIController;
@@ -42,6 +43,8 @@ import com.dmdirc.ui.WarningDialog;
42 43
 import com.dmdirc.ui.themes.ThemeManager;
43 44
 import com.dmdirc.util.URLBuilder;
44 45
 
46
+import com.google.common.eventbus.EventBus;
47
+
45 48
 import java.awt.GraphicsEnvironment;
46 49
 import java.util.Collection;
47 50
 import java.util.HashSet;
@@ -92,6 +95,9 @@ public class Main {
92 95
     /** The colour-based action comparisons. */
93 96
     private final ColourActionComparison colourActionComparison;
94 97
 
98
+    /** The event bus to dispatch events on. */
99
+    private final EventBus eventBus;
100
+
95 101
     /** The commands to load into the command manager. */
96 102
     private final Set<CommandDetails> commands;
97 103
 
@@ -110,6 +116,7 @@ public class Main {
110 116
      * @param urlBuilder URL builder to use as a singleton.
111 117
      * @param globalWindowManager Global window manager to use.
112 118
      * @param colourActionComparison The colour-based action comparisons.
119
+     * @param eventBus The event bus to dispatch events on.
113 120
      * @param commands The commands to be loaded into the command manager.
114 121
      */
115 122
     @Inject
@@ -126,6 +133,7 @@ public class Main {
126 133
             final URLBuilder urlBuilder,
127 134
             final GlobalWindowManager globalWindowManager,
128 135
             final ColourActionComparison colourActionComparison,
136
+            final EventBus eventBus,
129 137
             final Set<CommandDetails> commands) {
130 138
         this.identityManager = identityManager;
131 139
         this.serverManager = serverManager;
@@ -136,6 +144,7 @@ public class Main {
136 144
         this.commandManager = commandManager;
137 145
         this.globalWindowManager = globalWindowManager;
138 146
         this.colourActionComparison = colourActionComparison;
147
+        this.eventBus = eventBus;
139 148
         this.commands = commands;
140 149
         URLBuilder.setInstance(urlBuilder);
141 150
     }
@@ -179,6 +188,7 @@ public class Main {
179 188
         pluginManager.doAutoLoad();
180 189
         actionManager.loadUserActions();
181 190
         actionManager.triggerEvent(CoreActionType.CLIENT_OPENED, null);
191
+        eventBus.post(new ClientOpenedEvent());
182 192
 
183 193
         commandLineParser.processArguments(serverManager);
184 194
 

+ 30
- 0
src/com/dmdirc/events/ClientOpenedEvent.java Ver arquivo

@@ -0,0 +1,30 @@
1
+/*
2
+ * Copyright (c) 2006-2013 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.events;
24
+
25
+/**
26
+ * Fired when the client is first opened.
27
+ */
28
+public class ClientOpenedEvent extends DMDircEvent {
29
+
30
+}

+ 55
- 0
src/com/dmdirc/events/DMDircEvent.java Ver arquivo

@@ -0,0 +1,55 @@
1
+/*
2
+ * Copyright (c) 2006-2013 DMDirc Developers
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+
23
+package com.dmdirc.events;
24
+
25
+import lombok.Getter;
26
+
27
+/**
28
+ * Base class for all DMDirc events.
29
+ */
30
+@SuppressWarnings("PMD.UnusedPrivateField")
31
+public abstract class DMDircEvent {
32
+
33
+    /**
34
+     * The timestamp the event was triggered at, in milliseconds.
35
+     */
36
+    @Getter
37
+    private final long timestamp;
38
+
39
+    /**
40
+     * Creates a new event with the specified timestamp.
41
+     *
42
+     * @param timestamp The timestamp the event was triggered at, in milliseconds.
43
+     */
44
+    public DMDircEvent(final long timestamp) {
45
+        this.timestamp = timestamp;
46
+    }
47
+
48
+    /**
49
+     * Creates a new event with the current system timestamp.
50
+     */
51
+    public DMDircEvent() {
52
+        this.timestamp = System.currentTimeMillis();
53
+    }
54
+
55
+}

Carregando…
Cancelar
Salvar