Skip to content

Commit

Permalink
Lean on object service for singleton retrieval
Browse files Browse the repository at this point in the history
Instead of maintaining our own list of singletons, we should be using
the ObjectService.
  • Loading branch information
hinerm authored and ctrueden committed Jul 31, 2014
1 parent bfdc881 commit cbc827c
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions src/main/java/org/scijava/plugin/AbstractSingletonService.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

package org.scijava.plugin;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

Expand All @@ -58,15 +57,12 @@ public abstract class AbstractSingletonService<PT extends SingletonPlugin>
// TODO: Listen for PluginsAddedEvent and PluginsRemovedEvent
// and update the list of singletons accordingly.

/** List of singleton plugin instances. */
private List<PT> instances;

// -- SingletonService methods --

@Override
public List<PT> getInstances() {
if (instances == null) initInstances();
return instances;
final List<PT> plugins = objectService.getObjects(getPluginType());
return Collections.unmodifiableList(plugins);
}

@Override
Expand All @@ -84,7 +80,7 @@ public void initialize() {

@Override
public List<PT> get() {
return new ArrayList<PT>(getInstances());
return createInstances();
}

@Override
Expand All @@ -97,15 +93,14 @@ public Class<?> getType() {

// -- Helper methods --

private synchronized void initInstances() {
if (instances != null) return;

instances =
Collections.unmodifiableList(filterInstances(getPluginService()
.createInstancesOfType(getPluginType())));
private List<PT> createInstances() {
final List<PT> instances =
filterInstances(getPluginService().createInstancesOfType(getPluginType()));

log.info("Found " + instances.size() + " " +
getPluginType().getSimpleName() + " plugins.");

return instances;
}

/**
Expand Down

0 comments on commit cbc827c

Please sign in to comment.