Skip to content

Commit

Permalink
Merge pull request playframework#462 from amasiakiewicz/lighthouse-14…
Browse files Browse the repository at this point in the history
…28-patch

[playframework#1428] Fix to manage db stuff and have JPA context in @OnApplicationStop jobs
  • Loading branch information
pepite committed Feb 21, 2012
2 parents f46ce5b + 2be86c1 commit 8351f3e
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion framework/src/play/plugins/PluginCollection.java
Expand Up @@ -24,11 +24,15 @@
import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.net.URL;
import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.Set;

Expand Down Expand Up @@ -386,6 +390,41 @@ public void updatePlayPluginsList(){
public List<PlayPlugin> getEnabledPlugins(){
return enabledPlugins_readOnlyCopy;
}

/**
* Returns readonly view of all enabled plugins in reversed order
* @return
*/
public Collection<PlayPlugin> getReversedEnabledPlugins() {
return new AbstractCollection<PlayPlugin>() {

@Override public Iterator<PlayPlugin> iterator() {
final ListIterator<PlayPlugin> enabledPluginsListIt = enabledPlugins.listIterator(size() - 1);
return new Iterator<PlayPlugin>() {

@Override
public boolean hasNext() {
return enabledPluginsListIt.hasPrevious();
}

@Override
public PlayPlugin next() {
return enabledPluginsListIt.previous();
}

@Override
public void remove() {
enabledPluginsListIt.remove();
}};
}

@Override public int size() {
return enabledPlugins.size();
}


};
}

/**
* Returns new readonly list of all plugins
Expand Down Expand Up @@ -494,7 +533,7 @@ public void afterApplicationStart(){
}

public void onApplicationStop(){
for( PlayPlugin plugin : getEnabledPlugins() ){
for( PlayPlugin plugin : getReversedEnabledPlugins() ){
plugin.onApplicationStop();
}
}
Expand Down

0 comments on commit 8351f3e

Please sign in to comment.