1 29 30 package com.caucho.server.resin; 31 32 import com.caucho.management.server.ClusterMXBean; 33 import com.caucho.management.server.HostMXBean; 34 import com.caucho.management.server.PortMXBean; 35 import com.caucho.management.server.ThreadPoolMXBean; 36 import com.caucho.server.cluster.Cluster; 37 import com.caucho.server.cluster.Server; 38 import com.caucho.server.host.HostController; 39 import com.caucho.server.port.AbstractSelectManager; 40 import com.caucho.server.port.Port; 41 import com.caucho.server.util.CauchoSystem; 42 import com.caucho.util.L10N; 43 import com.caucho.vfs.Path; 44 45 import java.util.ArrayList ; 46 import java.util.Date ; 47 48 public class ServerAdmin 49 { 50 private static final L10N L = new L10N(ServerAdmin.class); 51 52 private final Server _server; 53 54 ServerAdmin(Server server) 55 { 56 _server = server; 57 } 58 59 public String getName() 60 { 61 return null; 62 } 63 64 public String getRootDirectory() 65 { 66 Path path = _server.getRootDirectory(); 67 68 if (path != null) 69 return path.getNativePath(); 70 else 71 return null; 72 } 73 74 public boolean isSelectManagerEnabled() 75 { 76 AbstractSelectManager manager = _server.getSelectManager(); 77 78 return manager != null; 79 } 80 81 84 public String getId() 85 { 86 return _server.getServerId(); 87 } 88 89 public ThreadPoolMXBean getThreadPool() 90 { 91 throw new UnsupportedOperationException (); 93 } 94 95 public PortMXBean []getPorts() 96 { 97 Server server = _server; 98 99 if (server == null) 100 return new PortMXBean[0]; 101 102 ArrayList <PortMXBean> portList = new ArrayList <PortMXBean>(); 103 104 for (Port port : server.getPorts()) { 105 PortMXBean admin = port.getAdmin(); 106 107 if (admin != null) 108 portList.add(admin); 109 } 110 111 return portList.toArray(new PortMXBean[portList.size()]); 112 } 113 114 public PortMXBean getClusterPort() 115 { 116 return null; 117 } 118 119 public ClusterMXBean getCluster() 120 { 121 if (_server == null) 122 return null; 123 else { 124 Cluster cluster = _server.getCluster(); 125 126 if (cluster != null) 127 return cluster.getAdmin(); 128 else 129 return null; 130 } 131 } 132 133 public String getLocalHost() 134 { 135 return CauchoSystem.getLocalHost(); 136 } 137 138 public boolean isDetailedStatistics() 139 { 140 return CauchoSystem.isDetailedStatistics(); 141 } 142 143 public HostMXBean []getHosts() 144 { 145 if (_server == null) 146 return new HostMXBean[0]; 147 148 ArrayList <HostMXBean> hostList = new ArrayList <HostMXBean>(); 149 150 for (HostController host : _server.getHostControllers()) { 151 HostMXBean admin = host.getAdmin(); 152 153 if (admin != null) 154 hostList.add(admin); 155 } 156 157 159 return hostList.toArray(new HostMXBean[hostList.size()]); 160 } 161 162 public String getState() 163 { 164 throw new UnsupportedOperationException (); 166 } 167 168 public Date getInitialStartTime() 169 { 170 throw new UnsupportedOperationException (); 172 } 173 174 public Date getStartTime() 175 { 176 throw new UnsupportedOperationException (); 178 } 179 180 public int getThreadActiveCount() 181 { 182 Server server = _server; 183 184 if (server == null) 185 return -1; 186 187 int activeThreadCount = -1; 188 189 for (Port port : server.getPorts()) { 190 if (port.getActiveThreadCount() >= 0) { 191 if (activeThreadCount == -1) 192 activeThreadCount = 0; 193 194 activeThreadCount += port.getActiveThreadCount(); 195 } 196 } 197 198 return activeThreadCount; 199 } 200 201 public int getThreadKeepaliveCount() 202 { 203 Server server = _server; 204 205 if (server == null) 206 return -1; 207 208 int keepaliveThreadCount = -1; 209 210 for (Port port : server.getPorts()) { 211 if (port.getKeepaliveConnectionCount() >= 0) { 212 if (keepaliveThreadCount == -1) 213 keepaliveThreadCount = 0; 214 215 keepaliveThreadCount += port.getKeepaliveConnectionCount(); 216 } 217 } 218 219 return keepaliveThreadCount; 220 } 221 222 public int getSelectKeepaliveCount() 223 { 224 Server server = _server; 225 226 if (server == null) 227 return -1; 228 229 int keepaliveSelectCount = -1; 230 231 for (Port port : server.getPorts()) { 232 if (port.getSelectConnectionCount() >= 0) { 233 if (keepaliveSelectCount == -1) 234 keepaliveSelectCount = 0; 235 236 keepaliveSelectCount += port.getSelectConnectionCount(); 237 } 238 } 239 240 return keepaliveSelectCount; 241 } 242 243 public long getRequestCountTotal() 244 { 245 Server server = _server; 246 247 if (server == null) 248 return -1; 249 250 long lifetimeRequestCount = 0; 251 252 for (Port port : server.getPorts()) 253 lifetimeRequestCount += port.getLifetimeRequestCount(); 254 255 return lifetimeRequestCount; 256 } 257 258 public long getRequestTimeTotal() 259 { 260 Server server = _server; 261 262 if (server == null) 263 return -1; 264 265 long lifetimeRequestTime = 0; 266 267 for (Port port : server.getPorts()) 268 lifetimeRequestTime += port.getLifetimeRequestTime(); 269 270 return lifetimeRequestTime; 271 } 272 273 public long getRequestReadBytesTotal() 274 { 275 Server server = _server; 276 277 if (server == null) 278 return -1; 279 280 long lifetimeReadBytes = 0; 281 282 for (Port port : server.getPorts()) 283 lifetimeReadBytes += port.getLifetimeReadBytes(); 284 285 return lifetimeReadBytes; 286 } 287 288 public long getRequestWriteBytesTotal() 289 { 290 Server server = _server; 291 292 if (server == null) 293 return -1; 294 295 long lifetimeWriteBytes = 0; 296 297 for (Port port : server.getPorts()) 298 lifetimeWriteBytes += port.getLifetimeWriteBytes(); 299 300 return lifetimeWriteBytes; 301 } 302 303 public long getClientDisconnectCountTotal() 304 { 305 Server server = _server; 306 307 if (server == null) 308 return -1; 309 310 long lifetimeClientDisconnectCount = 0; 311 312 for (Port port : server.getPorts()) 313 lifetimeClientDisconnectCount += port.getLifetimeClientDisconnectCount(); 314 315 return lifetimeClientDisconnectCount; 316 } 317 318 public long getKeepaliveCountTotal() 319 { 320 Server server = _server; 321 322 if (server == null) 323 return -1; 324 325 long lifetimeKeepaliveCount = 0; 326 327 for (Port port : server.getPorts()) 328 lifetimeKeepaliveCount += port.getLifetimeKeepaliveCount(); 329 330 return lifetimeKeepaliveCount; 331 } 332 333 public long getRuntimeMemory() 334 { 335 return Runtime.getRuntime().totalMemory(); 336 } 337 338 public long getRuntimeMemoryFree() 339 { 340 return Runtime.getRuntime().freeMemory(); 341 } 342 343 public void restart() 344 { 345 _server.restart(); 346 } 347 348 public void clearCache() 349 { 350 Server server = _server; 351 352 if (server != null) 353 server.clearCache(); 354 } 355 356 public void clearCacheByPattern(String hostRegexp, String urlRegexp) 357 { 358 Server server = _server; 359 360 if (server != null) 361 server.clearCacheByPattern(hostRegexp, urlRegexp); 362 } 363 364 public long getInvocationCacheHitCountTotal() 365 { 366 Server server = _server; 367 368 if (server != null) 369 return server.getInvocationCacheHitCount(); 370 else 371 return -1; 372 } 373 374 public long getInvocationCacheMissCountTotal() 375 { 376 Server server = _server; 377 378 if (server != null) 379 return server.getInvocationCacheMissCount(); 380 else 381 return -1; 382 } 383 384 public long getProxyCacheHitCount() 385 { 386 Server server = _server; 387 388 if (server != null) 389 return server.getProxyCacheHitCount(); 390 else 391 return -1; 392 } 393 394 public long getProxyCacheMissCount() 395 { 396 Server server = _server; 397 398 if (server != null) 399 return server.getProxyCacheMissCount(); 400 else 401 return -1; 402 } 403 } 404 | Popular Tags |