Browse Source

Add some synchronisation.

This should fix issue 4122, this should also fix issue 4123

Change-Id: Idd9b81f78bb6730505f342b4b027251917840490
Reviewed-on: http://gerrit.dmdirc.com/1227
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Chris Smith <chris@dmdirc.com>
tags/0.6.4rc1
Shane Mc Cormack 14 years ago
parent
commit
c8481c2c61
1 changed files with 35 additions and 21 deletions
  1. 35
    21
      src/com/dmdirc/plugins/PluginInfo.java

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

@@ -314,12 +314,14 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
314 314
                     continue;
315 315
                 }
316 316
 
317
-                try {
318
-                    final Identity thisIdentity = new Identity(stream, false);
319
-                    IdentityManager.addIdentity(thisIdentity);
320
-                    identities.add(thisIdentity);
321
-                } catch (final InvalidIdentityFileException ex) {
322
-                    Logger.userError(ErrorLevel.MEDIUM, "Error with identity file '" + name + "' in plugin '" + getName() + "'", ex);
317
+                synchronized (identities) {
318
+                    try {
319
+                        final Identity thisIdentity = new Identity(stream, false);
320
+                        IdentityManager.addIdentity(thisIdentity);
321
+                        identities.add(thisIdentity);
322
+                    } catch (final InvalidIdentityFileException ex) {
323
+                        Logger.userError(ErrorLevel.MEDIUM, "Error with identity file '" + name + "' in plugin '" + getName() + "'", ex);
324
+                    }
323 325
                 }
324 326
             }
325 327
         } catch (final IOException ioe) {
@@ -331,11 +333,13 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
331 333
      * Unload any identities loaded by this plugin.
332 334
      */
333 335
     private void unloadIdentities() {
334
-        for (Identity identity : identities) {
335
-            IdentityManager.removeIdentity(identity);
336
-        }
336
+        synchronized (identities) {
337
+            for (Identity identity : identities) {
338
+                IdentityManager.removeIdentity(identity);
339
+            }
337 340
 
338
-        identities.clear();
341
+            identities.clear();
342
+        }
339 343
     }
340 344
 
341 345
     /**
@@ -343,10 +347,12 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
343 347
      */
344 348
     private void updateProvides() {
345 349
         // Remove us from any existing provides lists.
346
-        for (Service service : provides) {
347
-            service.delProvider(this);
350
+        synchronized (provides) {
351
+            for (Service service : provides) {
352
+                service.delProvider(this);
353
+            }
354
+            provides.clear();
348 355
         }
349
-        provides.clear();
350 356
 
351 357
         // Get services provided by this plugin
352 358
         final List<String> providesList = metaData.getFlatDomain("provides");
@@ -358,8 +364,10 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
358 364
 
359 365
                 if (!name.equalsIgnoreCase("any") && !type.equalsIgnoreCase("export")) {
360 366
                     final Service service = PluginManager.getPluginManager().getService(type, name, true);
361
-                    service.addProvider(this);
362
-                    provides.add(service);
367
+                    synchronized (provides) {
368
+                        service.addProvider(this);
369
+                        provides.add(service);
370
+                    }
363 371
                 }
364 372
             }
365 373
         }
@@ -766,7 +774,9 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
766 774
      */
767 775
     @Override
768 776
     public List<Service> getServices() {
769
-        return new ArrayList<Service>(provides);
777
+        synchronized (provides) {
778
+            return new ArrayList<Service>(provides);
779
+        }
770 780
     }
771 781
 
772 782
     /**
@@ -1054,10 +1064,12 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
1054 1064
                     Logger.userError(ErrorLevel.MEDIUM, lastError, e);
1055 1065
                 }
1056 1066
                 ActionManager.processEvent(CoreActionType.PLUGIN_UNLOADED, null, this);
1057
-                for (Service service : provides) {
1058
-                    service.delProvider(this);
1067
+                synchronized (provides) {
1068
+                    for (Service service : provides) {
1069
+                        service.delProvider(this);
1070
+                    }
1071
+                    provides.clear();
1059 1072
                 }
1060
-                provides.clear();
1061 1073
             }
1062 1074
             unloadIdentities();
1063 1075
             tempLoaded = false;
@@ -1449,8 +1461,10 @@ public class PluginInfo implements Comparable<PluginInfo>, ServiceProvider {
1449 1461
 
1450 1462
                     // Add a provides for this
1451 1463
                     final Service service = PluginManager.getPluginManager().getService("export", serviceName, true);
1452
-                    service.addProvider(this);
1453
-                    provides.add(service);
1464
+                    synchronized (provides) {
1465
+                        service.addProvider(this);
1466
+                        provides.add(service);
1467
+                    }
1454 1468
                     // Add is as an export
1455 1469
                     exports.put(serviceName, new ExportInfo(methodName, methodClass, this));
1456 1470
                 }

Loading…
Cancel
Save