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
                     continue;
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
         } catch (final IOException ioe) {
327
         } catch (final IOException ioe) {
331
      * Unload any identities loaded by this plugin.
333
      * Unload any identities loaded by this plugin.
332
      */
334
      */
333
     private void unloadIdentities() {
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
      */
347
      */
344
     private void updateProvides() {
348
     private void updateProvides() {
345
         // Remove us from any existing provides lists.
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
         // Get services provided by this plugin
357
         // Get services provided by this plugin
352
         final List<String> providesList = metaData.getFlatDomain("provides");
358
         final List<String> providesList = metaData.getFlatDomain("provides");
358
 
364
 
359
                 if (!name.equalsIgnoreCase("any") && !type.equalsIgnoreCase("export")) {
365
                 if (!name.equalsIgnoreCase("any") && !type.equalsIgnoreCase("export")) {
360
                     final Service service = PluginManager.getPluginManager().getService(type, name, true);
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
      */
774
      */
767
     @Override
775
     @Override
768
     public List<Service> getServices() {
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
                     Logger.userError(ErrorLevel.MEDIUM, lastError, e);
1064
                     Logger.userError(ErrorLevel.MEDIUM, lastError, e);
1055
                 }
1065
                 }
1056
                 ActionManager.processEvent(CoreActionType.PLUGIN_UNLOADED, null, this);
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
             unloadIdentities();
1074
             unloadIdentities();
1063
             tempLoaded = false;
1075
             tempLoaded = false;
1449
 
1461
 
1450
                     // Add a provides for this
1462
                     // Add a provides for this
1451
                     final Service service = PluginManager.getPluginManager().getService("export", serviceName, true);
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
                     // Add is as an export
1468
                     // Add is as an export
1455
                     exports.put(serviceName, new ExportInfo(methodName, methodClass, this));
1469
                     exports.put(serviceName, new ExportInfo(methodName, methodClass, this));
1456
                 }
1470
                 }

Loading…
Cancel
Save