31
31
32
32
package org .scijava .plugin ;
33
33
34
- import java .util .ArrayList ;
35
34
import java .util .Collections ;
36
35
import java .util .List ;
37
36
@@ -58,15 +57,12 @@ public abstract class AbstractSingletonService<PT extends SingletonPlugin>
58
57
// TODO: Listen for PluginsAddedEvent and PluginsRemovedEvent
59
58
// and update the list of singletons accordingly.
60
59
61
- /** List of singleton plugin instances. */
62
- private List <PT > instances ;
63
-
64
60
// -- SingletonService methods --
65
61
66
62
@ Override
67
63
public List <PT > getInstances () {
68
- if ( instances == null ) initInstances ( );
69
- return instances ;
64
+ final List < PT > plugins = objectService . getObjects ( getPluginType () );
65
+ return Collections . unmodifiableList ( plugins ) ;
70
66
}
71
67
72
68
@ Override
@@ -84,7 +80,7 @@ public void initialize() {
84
80
85
81
@ Override
86
82
public List <PT > get () {
87
- return new ArrayList < PT >( getInstances () );
83
+ return createInstances ( );
88
84
}
89
85
90
86
@ Override
@@ -97,15 +93,14 @@ public Class<?> getType() {
97
93
98
94
// -- Helper methods --
99
95
100
- private synchronized void initInstances () {
101
- if (instances != null ) return ;
102
-
103
- instances =
104
- Collections .unmodifiableList (filterInstances (getPluginService ()
105
- .createInstancesOfType (getPluginType ())));
96
+ private List <PT > createInstances () {
97
+ final List <PT > instances =
98
+ filterInstances (getPluginService ().createInstancesOfType (getPluginType ()));
106
99
107
100
log .info ("Found " + instances .size () + " " +
108
101
getPluginType ().getSimpleName () + " plugins." );
102
+
103
+ return instances ;
109
104
}
110
105
111
106
/**
0 commit comments