1 29 30 package com.caucho.server.cluster; 31 32 import com.caucho.management.server.AbstractManagedObject; 33 import com.caucho.management.server.ClusterMXBean; 34 import com.caucho.management.server.PortMXBean; 35 import com.caucho.management.server.ServerMXBean; 36 import com.caucho.management.server.ThreadPoolMXBean; 37 import com.caucho.server.port.Port; 38 import com.caucho.server.resin.ThreadPoolAdmin; 39 import com.caucho.server.util.CauchoSystem; 40 41 import java.util.Collection ; 42 import java.util.Date ; 43 44 public class ServerAdmin extends AbstractManagedObject 45 implements ServerMXBean 46 { 47 private Server _server; 48 49 ServerAdmin(Server server) 50 { 51 _server = server; 52 53 registerSelf(); 54 } 55 56 public String getName() 57 { 58 return null; 59 } 60 61 public String getType() 62 { 63 return "Server"; 64 } 65 66 public String getId() 67 { 68 return _server.getServerId(); 69 } 70 71 75 78 public ClusterMXBean getCluster() 79 { 80 return _server.getCluster().getAdmin(); 81 } 82 83 86 public PortMXBean []getPorts() 87 { 88 Collection <Port> portList = _server.getPorts(); 89 90 PortMXBean []ports = new PortMXBean[portList.size()]; 91 92 int i = 0; 93 for (Port port : portList) { 94 ports[i++] = port.getAdmin(); 95 } 96 97 return ports; 98 } 99 100 103 public ThreadPoolMXBean getThreadPool() 104 { 105 return ThreadPoolAdmin.create(); 106 } 107 108 111 public PortMXBean getClusterPort() 112 { 113 return null; 114 } 115 116 120 123 public boolean isSelectManagerEnabled() 124 { 125 return false; 127 } 128 129 132 public boolean isDetailedStatistics() 133 { 134 return false; 135 } 136 137 141 144 public String getState() 145 { 146 return _server.getState(); 147 } 148 149 152 public Date getStartTime() 153 { 154 return new Date (_server.getStartTime()); 155 } 156 157 161 164 public int getThreadActiveCount() 165 { 166 int activeThreadCount = -1; 167 168 for (Port port : _server.getPorts()) { 169 if (port.getActiveThreadCount() >= 0) { 170 if (activeThreadCount == -1) 171 activeThreadCount = 0; 172 173 activeThreadCount += port.getActiveThreadCount(); 174 } 175 } 176 177 return activeThreadCount; 178 } 179 180 184 public int getThreadKeepaliveCount() 185 { 186 int keepaliveThreadCount = -1; 187 188 for (Port port : _server.getPorts()) { 189 if (port.getKeepaliveConnectionCount() >= 0) { 190 if (keepaliveThreadCount == -1) 191 keepaliveThreadCount = 0; 192 193 keepaliveThreadCount += port.getKeepaliveConnectionCount(); 194 } 195 } 196 197 return keepaliveThreadCount; 198 } 199 200 204 public int getSelectKeepaliveCount() 205 { 206 return -1; 207 } 208 209 213 public long getRequestCountTotal() 214 { 215 long lifetimeRequestCount = 0; 216 217 for (Port port : _server.getPorts()) 218 lifetimeRequestCount += port.getLifetimeRequestCount(); 219 220 return lifetimeRequestCount; 221 } 222 223 227 public long getKeepaliveCountTotal() 228 { 229 return -1; 230 } 231 232 236 public long getClientDisconnectCountTotal() 237 { 238 long lifetimeClientDisconnectCount = 0; 239 240 for (Port port : _server.getPorts()) 241 lifetimeClientDisconnectCount += port.getLifetimeClientDisconnectCount(); 242 243 return lifetimeClientDisconnectCount; 244 } 245 246 250 public long getRequestTimeTotal() 251 { 252 return -1; 253 } 254 255 259 public long getRequestReadBytesTotal() 260 { 261 return -1; 262 } 263 264 268 public long getRequestWriteBytesTotal() 269 { 270 return -1; 271 } 272 273 276 public long getInvocationCacheHitCountTotal() 277 { 278 return _server.getInvocationCacheHitCount(); 279 } 280 281 284 public long getInvocationCacheMissCountTotal() 285 { 286 return _server.getInvocationCacheMissCount(); 287 } 288 289 292 public long getRuntimeMemory() 293 { 294 return Runtime.getRuntime().totalMemory(); 295 } 296 297 300 public long getRuntimeMemoryFree() 301 { 302 return Runtime.getRuntime().freeMemory(); 303 } 304 305 308 public double getCpuLoadAvg() 309 { 310 try { 311 return CauchoSystem.getLoadAvg(); 312 } catch (Exception e) { 313 return 0; 314 } 315 } 316 317 321 324 public void restart() 325 { 326 _server.destroy(); 327 } 328 } 329 | Popular Tags |