1 22 package org.jboss.system; 23 24 import java.io.Serializable ; 25 import java.util.Iterator ; 26 import java.util.LinkedList ; 27 import java.util.List ; 28 import javax.management.ObjectName ; 29 30 41 public class ServiceContext implements Serializable 42 { 43 44 private static final long serialVersionUID = 7461263042948325633L; 45 46 47 private static final String [] stateNames = { 48 "INSTALLED", 49 "CONFIGURED", 50 "CREATED", 51 "RUNNING", 52 "FAILED", 53 "STOPPED", 54 "DESTROYED", 55 "NOTYETINSTALLED" 56 }; 57 58 59 public static final int INSTALLED = 0; 60 public static final int CONFIGURED = 1; 61 public static final int CREATED = 2; 62 public static final int RUNNING = 3; 63 public static final int FAILED = 4; 64 public static final int STOPPED = 5; 65 public static final int DESTROYED = 6; 66 public static final int NOTYETINSTALLED = 7; 67 68 69 public ObjectName objectName; 70 71 72 public int state = NOTYETINSTALLED; 73 74 75 public List <ServiceContext> iDependOn = new LinkedList <ServiceContext>(); 76 77 78 public List <ServiceContext> dependsOnMe = new LinkedList <ServiceContext>(); 79 80 81 public transient Service proxy; 82 83 84 public Throwable problem; 85 86 public String getStateString() 87 { 88 return getStateString(state); 89 } 90 91 public static String getStateString(int stateInt) 92 { 93 return stateNames[stateInt]; 94 } 95 96 public String toString() 97 { 98 StringBuffer sbuf = new StringBuffer (512); 99 100 sbuf.append("ObjectName: ").append(objectName); 101 sbuf.append("\n State: ").append(stateNames[state]); 102 103 if (state == FAILED && problem != null) 104 { 105 sbuf.append("\n Reason: ").append(problem.toString()); 106 } 107 printList(sbuf, "\n I Depend On:", iDependOn); 108 printList(sbuf, "\n Depends On Me:", dependsOnMe); 109 110 sbuf.append("\n"); 112 113 return sbuf.toString(); 114 } 115 116 private void printList(StringBuffer sbuf, String msg, List ctxs) 117 { 118 if (ctxs.size() > 0) 119 { 120 sbuf.append(msg); 122 for (Iterator i = ctxs.iterator(); i.hasNext(); ) 123 { 124 ServiceContext sc = (ServiceContext) i.next(); 125 sbuf.append("\n "); 126 sbuf.append(sc.objectName); 127 } 128 } 129 } 130 } 131 | Popular Tags |