@Override
public Iterator<AddonContextListener> getAddonContextListeners() {
- // Called once for init and once for destroy, so it's probably not worth
- // the effort caching the ServiceLoader instance
+ // Called once for init and then no more, so there's no point in caching
+ // the instance
ServiceLoader<AddonContextListener> contextListenerLoader = ServiceLoader
.load(AddonContextListener.class, getClassLoader());
return contextListenerLoader.iterator();
private List<BootstrapListener> bootstrapListeners = new ArrayList<BootstrapListener>();
+ private List<AddonContextListener> initedListeners = new ArrayList<AddonContextListener>();
+
public AddonContext(DeploymentConfiguration deploymentConfiguration) {
this.deploymentConfiguration = deploymentConfiguration;
deploymentConfiguration.setAddonContext(this);
while (listeners.hasNext()) {
AddonContextListener listener = listeners.next();
listener.contextCreated(event);
+ initedListeners.add(listener);
}
}
public void destroy() {
AddonContextEvent event = new AddonContextEvent(this);
- Iterator<AddonContextListener> listeners = deploymentConfiguration
- .getAddonContextListeners();
- while (listeners.hasNext()) {
- AddonContextListener listener = listeners.next();
+ for (AddonContextListener listener : initedListeners) {
listener.contextDestoryed(event);
}
}