Browse Source

Merge pull request #585 from csmith/master

Remove some more AppErrorEvents.
pull/586/head
Greg Holmes 9 years ago
parent
commit
1777aad85e

+ 12
- 14
src/com/dmdirc/config/ConfigBinder.java View File

@@ -22,12 +22,9 @@
22 22
 
23 23
 package com.dmdirc.config;
24 24
 
25
-import com.dmdirc.DMDircMBassador;
26
-import com.dmdirc.events.AppErrorEvent;
27 25
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
28 26
 import com.dmdirc.interfaces.config.ConfigChangeListener;
29 27
 import com.dmdirc.interfaces.config.ReadOnlyConfigProvider;
30
-import com.dmdirc.logger.ErrorLevel;
31 28
 
32 29
 import com.google.common.collect.ArrayListMultimap;
33 30
 import com.google.common.collect.Multimap;
@@ -43,31 +40,33 @@ import java.util.Optional;
43 40
 
44 41
 import javax.annotation.Nonnull;
45 42
 
43
+import org.slf4j.Logger;
44
+import org.slf4j.LoggerFactory;
45
+
46
+import static com.dmdirc.util.LogUtils.APP_ERROR;
47
+
46 48
 /**
47 49
  * Facilitates automatically binding fields or methods annotated with a {@link ConfigBinding}
48 50
  * element to a configuration value.
49 51
  */
50 52
 public class ConfigBinder {
51 53
 
54
+    private static final Logger LOG = LoggerFactory.getLogger(ConfigBinder.class);
55
+
52 56
     /** A map of instances to created listeners. */
53 57
     private final Multimap<Object, ConfigChangeListener> listeners = ArrayListMultimap.create();
54 58
     /** The default domain to use. */
55 59
     private final Optional<String> defaultDomain;
56 60
     /** The configuration manager to use to retrieve settings. */
57 61
     private final AggregateConfigProvider manager;
58
-    /** The event but used to raise error events. */
59
-    private final DMDircMBassador eventBus;
60 62
 
61
-    ConfigBinder(final AggregateConfigProvider manager, final DMDircMBassador eventBus) {
63
+    ConfigBinder(final AggregateConfigProvider manager) {
62 64
         this.manager = manager;
63
-        this.eventBus = eventBus;
64 65
         this.defaultDomain = Optional.empty();
65 66
     }
66 67
 
67
-    ConfigBinder(final AggregateConfigProvider manager, final DMDircMBassador eventBus,
68
-            @Nonnull final String domain) {
68
+    ConfigBinder(final AggregateConfigProvider manager, @Nonnull final String domain) {
69 69
         this.manager = manager;
70
-        this.eventBus = eventBus;
71 70
         this.defaultDomain = Optional.of(domain);
72 71
     }
73 72
 
@@ -148,8 +147,7 @@ public class ConfigBinder {
148 147
         try {
149 148
             binding.invocation().newInstance().invoke(element, instance, value);
150 149
         } catch (ReflectiveOperationException ex) {
151
-            eventBus.publish(new AppErrorEvent(ErrorLevel.HIGH, ex,
152
-                    "Exception when updating bound setting", ""));
150
+            LOG.error(APP_ERROR, "Exception when updating bound setting", ex);
153 151
         }
154 152
     }
155 153
 
@@ -219,7 +217,7 @@ public class ConfigBinder {
219 217
      * @param newListeners The listeners to be added
220 218
      */
221 219
     private void addListeners(final Object instance,
222
-            final Collection<ConfigChangeListener> newListeners) {
220
+            final Iterable<ConfigChangeListener> newListeners) {
223 221
         synchronized (listeners) {
224 222
             listeners.putAll(instance, newListeners);
225 223
         }
@@ -244,7 +242,7 @@ public class ConfigBinder {
244 242
      * @return A config binder with the specified default domain.
245 243
      */
246 244
     public ConfigBinder withDefaultDomain(@Nonnull final String domain) {
247
-        return new ConfigBinder(manager, eventBus, domain);
245
+        return new ConfigBinder(manager, domain);
248 246
     }
249 247
 
250 248
 }

+ 8
- 16
src/com/dmdirc/config/ConfigFileBackedConfigProvider.java View File

@@ -22,11 +22,8 @@
22 22
 
23 23
 package com.dmdirc.config;
24 24
 
25
-import com.dmdirc.DMDircMBassador;
26
-import com.dmdirc.events.UserErrorEvent;
27 25
 import com.dmdirc.interfaces.config.ConfigChangeListener;
28 26
 import com.dmdirc.interfaces.config.ConfigProvider;
29
-import com.dmdirc.logger.ErrorLevel;
30 27
 import com.dmdirc.util.io.ConfigFile;
31 28
 import com.dmdirc.util.io.InvalidConfigFileException;
32 29
 import com.dmdirc.util.validators.Validator;
@@ -50,6 +47,8 @@ import javax.annotation.Nullable;
50 47
 import org.slf4j.Logger;
51 48
 import org.slf4j.LoggerFactory;
52 49
 
50
+import static com.dmdirc.util.LogUtils.USER_ERROR;
51
+
53 52
 /**
54 53
  * Provides configuration settings from a {@link ConfigFile}.
55 54
  */
@@ -72,8 +71,6 @@ public class ConfigFileBackedConfigProvider implements ConfigProvider {
72 71
     /** The config change listeners for this source. */
73 72
     protected final List<WeakReference<ConfigChangeListener>> listeners =
74 73
             new CopyOnWriteArrayList<>();
75
-    /** The event bus to post error events to. */
76
-    private final DMDircMBassador eventBus;
77 74
     /** Whether this identity needs to be saved. */
78 75
     protected boolean needSave;
79 76
 
@@ -87,13 +84,12 @@ public class ConfigFileBackedConfigProvider implements ConfigProvider {
87 84
      * @throws InvalidIdentityFileException Missing required properties
88 85
      * @throws IOException                  Input/output exception
89 86
      */
90
-    public ConfigFileBackedConfigProvider(@Nullable final IdentityManager identityManager,
91
-            final DMDircMBassador eventBus, final Path file, final boolean forceDefault)
92
-            throws IOException, InvalidIdentityFileException {
87
+    public ConfigFileBackedConfigProvider(
88
+            @Nullable final IdentityManager identityManager, final Path file,
89
+            final boolean forceDefault) throws IOException, InvalidIdentityFileException {
93 90
         this.identityManager = identityManager;
94 91
         this.file = new ConfigFile(file);
95 92
         this.file.setAutomake(true);
96
-        this.eventBus = eventBus;
97 93
         initFile(forceDefault);
98 94
         myTarget = getTarget(forceDefault);
99 95
     }
@@ -107,12 +103,11 @@ public class ConfigFileBackedConfigProvider implements ConfigProvider {
107 103
      * @throws InvalidIdentityFileException Missing required properties
108 104
      * @throws IOException                  Input/output exception
109 105
      */
110
-    public ConfigFileBackedConfigProvider(final DMDircMBassador eventBus, final InputStream stream,
106
+    public ConfigFileBackedConfigProvider(final InputStream stream,
111 107
             final boolean forceDefault) throws IOException, InvalidIdentityFileException {
112 108
         this.identityManager = null;
113 109
         this.file = new ConfigFile(stream);
114 110
         this.file.setAutomake(true);
115
-        this.eventBus = eventBus;
116 111
         initFile(forceDefault);
117 112
         myTarget = getTarget(forceDefault);
118 113
     }
@@ -125,11 +120,9 @@ public class ConfigFileBackedConfigProvider implements ConfigProvider {
125 120
      * @param target          The target of this identity
126 121
      */
127 122
     public ConfigFileBackedConfigProvider(@Nullable final IdentityManager identityManager,
128
-            final DMDircMBassador eventBus, final ConfigFile configFile,
129
-            final ConfigTarget target) {
123
+            final ConfigFile configFile, final ConfigTarget target) {
130 124
         this.identityManager = identityManager;
131 125
         this.file = configFile;
132
-        this.eventBus = eventBus;
133 126
         this.file.setAutomake(true);
134 127
         this.myTarget = target;
135 128
     }
@@ -470,8 +463,7 @@ public class ConfigFileBackedConfigProvider implements ConfigProvider {
470 463
 
471 464
                 needSave = false;
472 465
             } catch (IOException ex) {
473
-                eventBus.publish(new UserErrorEvent(ErrorLevel.MEDIUM, ex,
474
-                        "Unable to save identity file: " + ex.getMessage(), ""));
466
+                LOG.warn(USER_ERROR, "Unable to save identity file", ex);
475 467
             }
476 468
         }
477 469
     }

+ 1
- 1
src/com/dmdirc/config/ConfigManager.java View File

@@ -127,7 +127,7 @@ class ConfigManager implements ConfigChangeListener, ConfigProviderListener,
127 127
         this.server = server;
128 128
         this.channel = chanName;
129 129
 
130
-        binder = new ConfigBinder(this, eventBus);
130
+        binder = new ConfigBinder(this);
131 131
     }
132 132
 
133 133
     @Override

+ 7
- 9
src/com/dmdirc/config/IdentityManager.java View File

@@ -24,7 +24,6 @@ package com.dmdirc.config;
24 24
 
25 25
 import com.dmdirc.DMDircMBassador;
26 26
 import com.dmdirc.Precondition;
27
-import com.dmdirc.events.AppErrorEvent;
28 27
 import com.dmdirc.events.UserErrorEvent;
29 28
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
30 29
 import com.dmdirc.interfaces.config.ConfigProvider;
@@ -60,6 +59,7 @@ import java.util.stream.Collectors;
60 59
 import org.slf4j.Logger;
61 60
 import org.slf4j.LoggerFactory;
62 61
 
62
+import static com.dmdirc.util.LogUtils.FATAL_APP_ERROR;
63 63
 import static com.google.common.base.Preconditions.checkArgument;
64 64
 import static com.google.common.base.Preconditions.checkNotNull;
65 65
 
@@ -144,7 +144,7 @@ public class IdentityManager implements IdentityFactory, IdentityController {
144 144
         addonSettings.put("name", "Addon defaults");
145 145
         addonConfigFile.addDomain("identity", addonSettings);
146 146
 
147
-        addonConfig = new ConfigFileBackedConfigProvider(this, eventBus, addonConfigFile, target);
147
+        addonConfig = new ConfigFileBackedConfigProvider(this, addonConfigFile, target);
148 148
         addConfigProvider(addonConfig);
149 149
     }
150 150
 
@@ -156,8 +156,7 @@ public class IdentityManager implements IdentityFactory, IdentityController {
156 156
             loadIdentity(FileUtils.getPathForResource(getClass().getResource(
157 157
                     "defaults/default/formatter")));
158 158
         } catch (URISyntaxException ex) {
159
-            eventBus.publishAsync(new AppErrorEvent(ErrorLevel.FATAL, ex,
160
-                    "Unable to load settings", ""));
159
+            LOG.error(FATAL_APP_ERROR, "Unable to load settings", ex);
161 160
         }
162 161
 
163 162
         final Path file = identitiesDirectory.resolve("modealiases");
@@ -265,8 +264,7 @@ public class IdentityManager implements IdentityFactory, IdentityController {
265 264
         }
266 265
 
267 266
         try {
268
-            final ConfigProvider provider = new ConfigFileBackedConfigProvider(this, eventBus,
269
-                    file, false);
267
+            final ConfigProvider provider = new ConfigFileBackedConfigProvider(this, file, false);
270 268
             addConfigProvider(provider);
271 269
             configProvidersByPath.put(file, provider);
272 270
         } catch (InvalidIdentityFileException ex) {
@@ -307,7 +305,7 @@ public class IdentityManager implements IdentityFactory, IdentityController {
307 305
     @Override
308 306
     public void loadVersionIdentity() {
309 307
         try {
310
-            versionConfig = new ConfigFileBackedConfigProvider(eventBus, IdentityManager.class.
308
+            versionConfig = new ConfigFileBackedConfigProvider(IdentityManager.class.
311 309
                     getResourceAsStream("/com/dmdirc/version.config"), false);
312 310
             addConfigProvider(versionConfig);
313 311
         } catch (IOException | InvalidIdentityFileException ex) {
@@ -329,7 +327,7 @@ public class IdentityManager implements IdentityFactory, IdentityController {
329 327
                 Files.createFile(file);
330 328
             }
331 329
 
332
-            config = new ConfigFileBackedConfigProvider(this, eventBus, file, true);
330
+            config = new ConfigFileBackedConfigProvider(this, file, true);
333 331
             config.setOption("identity", "name", "Global config");
334 332
             configProvidersByPath.put(file, config);
335 333
             addConfigProvider(config);
@@ -653,7 +651,7 @@ public class IdentityManager implements IdentityFactory, IdentityController {
653 651
         configFile.write();
654 652
 
655 653
         final ConfigFileBackedConfigProvider identity = new ConfigFileBackedConfigProvider(this,
656
-                eventBus, file, false);
654
+                file, false);
657 655
         addConfigProvider(identity);
658 656
 
659 657
         return identity;

+ 1
- 1
src/com/dmdirc/plugins/PluginInfo.java View File

@@ -267,7 +267,7 @@ public class PluginInfo implements ServiceProvider {
267 267
         try (final InputStream stream = Files.newInputStream(path)) {
268 268
             synchronized (configProviders) {
269 269
                 final ConfigProvider configProvider =
270
-                        new ConfigFileBackedConfigProvider(eventBus, stream, false);
270
+                        new ConfigFileBackedConfigProvider(stream, false);
271 271
                 identityController.addConfigProvider(configProvider);
272 272
                 configProviders.add(configProvider);
273 273
             }

+ 1
- 1
src/com/dmdirc/ui/themes/Theme.java View File

@@ -110,7 +110,7 @@ public class Theme implements Comparable<Theme> {
110 110
 
111 111
         if (stream != null) {
112 112
             try {
113
-                identity = new ThemeIdentity(eventBus, stream, this);
113
+                identity = new ThemeIdentity(stream, this);
114 114
                 identityController.addConfigProvider(identity);
115 115
             } catch (InvalidIdentityFileException | IOException ex) {
116 116
                 eventBus.publish(new UserErrorEvent(ErrorLevel.MEDIUM,

+ 3
- 4
src/com/dmdirc/ui/themes/ThemeIdentity.java View File

@@ -22,7 +22,6 @@
22 22
 
23 23
 package com.dmdirc.ui.themes;
24 24
 
25
-import com.dmdirc.DMDircMBassador;
26 25
 import com.dmdirc.config.ConfigFileBackedConfigProvider;
27 26
 import com.dmdirc.config.InvalidIdentityFileException;
28 27
 import com.dmdirc.util.validators.Validator;
@@ -47,9 +46,9 @@ public class ThemeIdentity extends ConfigFileBackedConfigProvider {
47 46
      * @throws InvalidIdentityFileException Missing required properties
48 47
      * @throws IOException                  Input/output exception
49 48
      */
50
-    public ThemeIdentity(final DMDircMBassador eventBus, final InputStream stream,
51
-            final Theme theme) throws IOException, InvalidIdentityFileException {
52
-        super(eventBus, stream, true);
49
+    public ThemeIdentity(final InputStream stream, final Theme theme)
50
+            throws IOException, InvalidIdentityFileException {
51
+        super(stream, true);
53 52
 
54 53
         myTarget.setTheme();
55 54
         this.theme = theme;

+ 1
- 3
test/com/dmdirc/config/ConfigBinderTest.java View File

@@ -22,7 +22,6 @@
22 22
 
23 23
 package com.dmdirc.config;
24 24
 
25
-import com.dmdirc.DMDircMBassador;
26 25
 import com.dmdirc.interfaces.config.AggregateConfigProvider;
27 26
 
28 27
 import org.junit.Before;
@@ -41,12 +40,11 @@ import static org.mockito.Mockito.when;
41 40
 public class ConfigBinderTest {
42 41
 
43 42
     @Mock private AggregateConfigProvider configProvider;
44
-    @Mock private DMDircMBassador eventBus;
45 43
     private ConfigBinder binder;
46 44
 
47 45
     @Before
48 46
     public void setup() {
49
-        binder = new ConfigBinder(configProvider, eventBus);
47
+        binder = new ConfigBinder(configProvider);
50 48
     }
51 49
 
52 50
     @Test

+ 4
- 8
test/com/dmdirc/config/ConfigFileBackedConfigProviderTest.java View File

@@ -22,7 +22,6 @@
22 22
 
23 23
 package com.dmdirc.config;
24 24
 
25
-import com.dmdirc.DMDircMBassador;
26 25
 import com.dmdirc.interfaces.config.ConfigChangeListener;
27 26
 import com.dmdirc.interfaces.config.ConfigProvider;
28 27
 import com.dmdirc.util.io.InvalidConfigFileException;
@@ -65,7 +64,6 @@ public class ConfigFileBackedConfigProviderTest {
65 64
 
66 65
     @Mock private IdentityManager identityManager;
67 66
     @Mock private ConfigChangeListener changeListener;
68
-    @Mock private DMDircMBassador eventBus;
69 67
 
70 68
     private FileSystem fs;
71 69
 
@@ -80,18 +78,17 @@ public class ConfigFileBackedConfigProviderTest {
80 78
 
81 79
     @Test(expected = InvalidIdentityFileException.class)
82 80
     public void testNoName() throws IOException, InvalidIdentityFileException {
83
-        new ConfigFileBackedConfigProvider(identityManager, eventBus, fs.getPath("no-name"), false);
81
+        new ConfigFileBackedConfigProvider(identityManager, fs.getPath("no-name"), false);
84 82
     }
85 83
 
86 84
     @Test(expected = InvalidIdentityFileException.class)
87 85
     public void testNoTarget() throws IOException, InvalidIdentityFileException {
88
-        new ConfigFileBackedConfigProvider(identityManager,  eventBus,fs.getPath("no-target"), false);
86
+        new ConfigFileBackedConfigProvider(identityManager, fs.getPath("no-target"), false);
89 87
     }
90 88
 
91 89
     @Test(expected = InvalidIdentityFileException.class)
92 90
     public void testInvalidConfigFile() throws IOException, InvalidIdentityFileException {
93
-        new ConfigFileBackedConfigProvider(identityManager, eventBus,
94
-                fs.getPath("invalid-config-file"), false);
91
+        new ConfigFileBackedConfigProvider(identityManager, fs.getPath("invalid-config-file"), false);
95 92
     }
96 93
 
97 94
     @Test
@@ -321,8 +318,7 @@ public class ConfigFileBackedConfigProviderTest {
321 318
 
322 319
     private ConfigFileBackedConfigProvider getProvider(final String file)
323 320
             throws IOException, InvalidIdentityFileException {
324
-        return new ConfigFileBackedConfigProvider(identityManager, eventBus,
325
-                fs.getPath(file), false);
321
+        return new ConfigFileBackedConfigProvider(identityManager, fs.getPath(file), false);
326 322
     }
327 323
 
328 324
 }

Loading…
Cancel
Save