1 23 24 29 30 package com.sun.enterprise.admin.servermgmt; 31 32 import com.sun.enterprise.admin.common.Status; 33 34 import com.sun.enterprise.server.logging.FileandSyslogHandler; 35 import com.sun.enterprise.admin.servermgmt.InstancesManager; 36 import com.sun.enterprise.admin.servermgmt.InstanceException; 37 38 import java.io.Serializable ; 39 import java.util.Vector ; 40 import com.sun.enterprise.util.LocalStrings; 41 import com.sun.enterprise.util.LocalStringsImpl; 42 43 47 public class RuntimeStatus implements Serializable { 48 49 private boolean _restartNeeded; 50 private Status _status; 51 private Vector _recentErrorMessages; 52 private String _name; 53 54 public static RuntimeStatus getRuntimeStatus( 55 String name, 56 InstancesManager manager) throws InstanceException 57 { 58 int status = manager.getInstanceStatus(); 59 return new RuntimeStatus(name, manager.isRestartNeeded(), 60 new Status(status, Status.getStatusString(status)), 61 FileandSyslogHandler.getRecentErrorMessages()); 62 } 63 64 public static void clearRuntimeStatus() 65 { 66 FileandSyslogHandler.clearRecentErrorMessages(); 67 } 68 69 public RuntimeStatus() { 70 this ("", true, new Status(Status.kInstanceNotRunningCode, 71 Status.kInstanceNotRunningMsg), new Vector ()); 72 } 73 74 public RuntimeStatus(String name) { 75 this(); 76 _name = name; 77 } 78 79 public RuntimeStatus(String name, boolean restartNeeded, 80 Status status, Vector recentErrors) 81 { 82 _name = name; 83 _restartNeeded = restartNeeded; 84 _status = status; 85 _recentErrorMessages = recentErrors; 86 } 87 88 public boolean isRestartNeeded() 89 { 90 return _restartNeeded; 91 } 92 93 public String getName() 94 { 95 return _name; 96 } 97 98 public void setStatus(Status status) 99 { 100 _status = status; 101 } 102 103 public Status getStatus() 104 { 105 return _status; 106 } 107 108 public Vector getRecentErrorMessages() 109 { 110 return _recentErrorMessages; 111 } 112 113 114 public boolean isRunning() 115 { 116 return getStatus().getStatusCode() == Status.kInstanceRunningCode ? true : false; 117 } 118 119 public boolean isStopped() 120 { 121 return getStatus().getStatusCode() == Status.kInstanceNotRunningCode ? true : false; 122 } 123 124 public String toShortString() 125 { 126 String result = getStatus().getStatusString(); 127 if (isRunning()) { 128 if (isRestartNeeded()) { 129 result = LocalStrings.get("requiresRestartYes"); 130 } 131 } 132 return result; 133 } 134 135 public String toString() 136 { 137 LocalStringsImpl stringy = new LocalStringsImpl(); 138 String result = stringy.get("runtimeStatusToString", getName(), getStatus().getStatusString()); 139 if (isRestartNeeded()) { 140 result += ", " + stringy.get("requiresRestartYes"); 141 } else { 142 result += ", " + stringy.get("requiresRestartNo"); 143 } 144 145 Vector messages = getRecentErrorMessages(); 146 for (int i = 0; i < messages.size(); i++) { 147 result += "\n" + stringy.get("error") + " " + i + " " + (String )messages.get(i); 148 } 149 150 return result; 151 } 152 153 } 154 155 | Popular Tags |