Making AppLifeCycle binding lazy to allow for multiple xml configuration

scenario.  Cleaning up GraphOutputDot to sort 'undeployed' at top of
graph for readabilities sake.

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1134 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Joakim Erdfelt 2009-12-08 22:17:33 +00:00
parent 07d9656136
commit 5c48784e86
2 changed files with 72 additions and 44 deletions

View File

@ -36,6 +36,8 @@ import org.eclipse.jetty.util.log.Log;
*/
public class AppLifeCycle extends Graph
{
private static final String ALL_NODES = "*";
public static interface Binding
{
/**
@ -68,7 +70,7 @@ public class AppLifeCycle extends Graph
private static final String NODE_STARTED = "started";
private static final String NODE_STOPPING = "stopping";
private static final String NODE_UNDEPLOYING = "undeploying";
private Map<Node, List<Binding>> lifecyclebindings = new HashMap<Node, List<Binding>>();
private Map<String, List<Binding>> lifecyclebindings = new HashMap<String, List<Binding>>();
public AppLifeCycle()
{
@ -95,35 +97,17 @@ public class AppLifeCycle extends Graph
{
for (String nodeName : binding.getBindingTargets())
{
if (nodeName.equals("*"))
List<Binding> bindings = lifecyclebindings.get(nodeName);
if (bindings == null)
{
// Special Case: Bind to all Nodes
for (Node node : getNodes())
{
bindToNode(node,binding);
}
}
else
{
// Bind to specific node
Node node = getNodeByName(nodeName);
bindToNode(node,binding);
bindings = new ArrayList<Binding>();
}
bindings.add(binding);
lifecyclebindings.put(nodeName,bindings);
}
}
private void bindToNode(Node node, AppLifeCycle.Binding binding)
{
List<Binding> bindings = lifecyclebindings.get(node);
if (bindings == null)
{
bindings = new ArrayList<Binding>();
}
bindings.add(binding);
lifecyclebindings.put(node,bindings);
}
/**
* Get all {@link Node} bound objects.
*
@ -147,10 +131,20 @@ public class AppLifeCycle extends Graph
* @return Set of Object(s) for specific lifecycle bindings. never null.
*/
public Set<AppLifeCycle.Binding> getBindings(Node node)
{
return getBindings(node.getName());
}
/**
* Get all objects bound to a specific {@link Node}
*
* @return Set of Object(s) for specific lifecycle bindings. never null.
*/
public Set<AppLifeCycle.Binding> getBindings(String nodeName)
{
Set<Binding> boundset = new HashSet<Binding>();
List<Binding> bindings = lifecyclebindings.get(node);
List<Binding> bindings = lifecyclebindings.get(nodeName);
if (bindings == null)
{
return boundset;
@ -161,19 +155,11 @@ public class AppLifeCycle extends Graph
return boundset;
}
public Set<Binding> getBindings(String nodeName)
{
Node node = getNodeByName(nodeName);
return getBindings(node);
}
public void runBindings(Node node, App app, DeploymentManager deploymentManager) throws Throwable
{
List<Binding> bindings = this.lifecyclebindings.get(node);
if (bindings == null)
{
return;
}
List<Binding> bindings = new ArrayList<Binding>();
bindings.addAll(getBindings(ALL_NODES)); // Bindings (special) All Nodes
bindings.addAll(getBindings(node)); // Specific Node
for (Binding binding : bindings)
{

View File

@ -19,6 +19,11 @@ import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.CollationKey;
import java.text.Collator;
import java.util.Comparator;
import java.util.Set;
import java.util.TreeSet;
import org.eclipse.jetty.util.IO;
@ -31,7 +36,41 @@ public class GraphOutputDot
{
}
public static void write(Graph graph,File outputFile) throws IOException
private static final String TOPNODE = "undeployed";
/**
* Comparator that makes the 'undeployed' node the first node in the sort list.
*
* This makes the 'undeployed' node show up at the top of the generated graph.
*/
private static class TopNodeSort implements Comparator<Node>
{
private Collator collator = Collator.getInstance();
public int compare(Node o1, Node o2)
{
if (o1.getName().equals(TOPNODE))
{
return -1;
}
if (o2.getName().equals(TOPNODE))
{
return 1;
}
CollationKey key1 = toKey(o1);
CollationKey key2 = toKey(o2);
return key1.compareTo(key2);
}
private CollationKey toKey(Node node)
{
return collator.getCollationKey(node.getName());
}
}
public static void write(Graph graph, File outputFile) throws IOException
{
FileWriter writer = null;
PrintWriter out = null;
@ -48,7 +87,10 @@ public class GraphOutputDot
writeNodeDefaults(out);
writeEdgeDefaults(out);
for (Node node : graph.getNodes())
Set<Node> nodes = new TreeSet<Node>(new TopNodeSort());
nodes.addAll(graph.getNodes());
for (Node node : nodes)
{
writeNode(out,node);
}
@ -72,8 +114,8 @@ public class GraphOutputDot
out.println();
out.println(" // Edge");
out.printf(" \"%s\" -> \"%s\" [%n",toId(edge.getFrom()),toId(edge.getTo()));
out.printf(" arrowtail=none,%n");
out.printf(" arrowhead=normal%n");
out.println(" arrowtail=none,");
out.println(" arrowhead=normal");
out.println(" ];");
}
@ -85,10 +127,10 @@ public class GraphOutputDot
out.printf(" label=\"%s\",%n",node.getName());
if (node.getName().endsWith("ed"))
{
out.printf(" color=\"#ddddff\",%n");
out.printf(" style=filled,%n");
out.println(" color=\"#ddddff\",");
out.println(" style=filled,");
}
out.printf(" shape=box%n");
out.println(" shape=box");
out.println(" ];");
}