001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.server.cluster;
031:
032: import com.caucho.management.server.AbstractEmitterObject;
033: import com.caucho.management.server.ClusterMXBean;
034: import com.caucho.management.server.PortMXBean;
035: import com.caucho.management.server.ServerMXBean;
036: import com.caucho.management.server.ThreadPoolMXBean;
037: import com.caucho.server.port.Port;
038: import com.caucho.server.util.CauchoSystem;
039: import com.caucho.util.Alarm;
040:
041: import java.util.Collection;
042: import java.util.Date;
043:
044: public class ServerAdmin extends AbstractEmitterObject implements
045: ServerMXBean {
046: private Server _server;
047:
048: ServerAdmin(Server server) {
049: _server = server;
050:
051: registerSelf();
052: }
053:
054: public String getName() {
055: return null;
056: }
057:
058: public String getType() {
059: return "Server";
060: }
061:
062: public String getId() {
063: return _server.getServerId();
064: }
065:
066: //
067: // Hierarchy
068: //
069:
070: /**
071: * Returns the cluster owning this server
072: */
073: public ClusterMXBean getCluster() {
074: return _server.getCluster().getAdmin();
075: }
076:
077: /**
078: * Returns the array of ports.
079: */
080: public PortMXBean[] getPorts() {
081: Collection<Port> portList = _server.getPorts();
082:
083: PortMXBean[] ports = new PortMXBean[portList.size()];
084:
085: int i = 0;
086: for (Port port : portList) {
087: ports[i++] = port.getAdmin();
088: }
089:
090: return ports;
091: }
092:
093: /**
094: * Returns the server's thread pool administration
095: */
096: public ThreadPoolMXBean getThreadPool() {
097: return _server.getCluster().getResin().getThreadPoolAdmin();
098: }
099:
100: /**
101: * Returns the cluster port
102: */
103: public PortMXBean getClusterPort() {
104: return null;
105: }
106:
107: //
108: // Configuration attributes
109: //
110:
111: /**
112: * Returns true if a {@link com.caucho.server.port.AbstractSelectManager} is enabled and active
113: */
114: public boolean isSelectManagerEnabled() {
115: return _server.isSelectManagerEnabled();
116: }
117:
118: /**
119: * Returns true if detailed statistics are being kept.
120: */
121: public boolean isDetailedStatistics() {
122: return false;
123: }
124:
125: //
126: // state
127: //
128:
129: /**
130: * The current lifecycle state.
131: */
132: public String getState() {
133: return _server.getState();
134: }
135:
136: /**
137: * Returns the current time according to the server.
138: */
139: public Date getCurrentTime() {
140: return new Date(Alarm.getExactTime());
141: }
142:
143: /**
144: * Returns the last start time.
145: */
146: public Date getStartTime() {
147: return new Date(_server.getStartTime());
148: }
149:
150: //
151: // statistics
152: //
153:
154: /**
155: * Returns the current number of threads that are servicing requests.
156: */
157: public int getThreadActiveCount() {
158: int activeThreadCount = -1;
159:
160: for (Port port : _server.getPorts()) {
161: if (port.getActiveThreadCount() >= 0) {
162: if (activeThreadCount == -1)
163: activeThreadCount = 0;
164:
165: activeThreadCount += port.getActiveThreadCount();
166: }
167: }
168:
169: return activeThreadCount;
170: }
171:
172: /**
173: * Returns the current number of connections that are in the keepalive
174: * state and are using a thread to maintain the connection.
175: */
176: public int getThreadKeepaliveCount() {
177: int keepaliveThreadCount = -1;
178:
179: for (Port port : _server.getPorts()) {
180: if (port.getKeepaliveConnectionCount() >= 0) {
181: if (keepaliveThreadCount == -1)
182: keepaliveThreadCount = 0;
183:
184: keepaliveThreadCount += port
185: .getKeepaliveConnectionCount();
186: }
187: }
188:
189: return keepaliveThreadCount;
190: }
191:
192: /**
193: * Returns the current number of connections that are in the keepalive
194: * state and are using select to maintain the connection.
195: */
196: public int getSelectKeepaliveCount() {
197: return _server.getKeepaliveSelectCount();
198: }
199:
200: /**
201: * Returns the total number of requests serviced by the server
202: * since it started.
203: */
204: public long getRequestCountTotal() {
205: long lifetimeRequestCount = 0;
206:
207: for (Port port : _server.getPorts())
208: lifetimeRequestCount += port.getLifetimeRequestCount();
209:
210: return lifetimeRequestCount;
211: }
212:
213: /**
214: * Returns the number of requests that have ended up in the keepalive state
215: * for this server in its lifetime.
216: */
217: public long getKeepaliveCountTotal() {
218: return -1;
219: }
220:
221: /**
222: * The total number of connections that have terminated with
223: * {@link com.caucho.vfs.ClientDisconnectException}.
224: */
225: public long getClientDisconnectCountTotal() {
226: long lifetimeClientDisconnectCount = 0;
227:
228: for (Port port : _server.getPorts())
229: lifetimeClientDisconnectCount += port
230: .getLifetimeClientDisconnectCount();
231:
232: return lifetimeClientDisconnectCount;
233: }
234:
235: /**
236: * Returns the total duration in milliseconds that requests serviced by
237: * this server have taken.
238: */
239: public long getRequestTimeTotal() {
240: return -1;
241: }
242:
243: /**
244: * Returns the total number of bytes that requests serviced by this
245: * server have read.
246: */
247: public long getRequestReadBytesTotal() {
248: return -1;
249: }
250:
251: /**
252: * Returns the total number of bytes that requests serviced by this
253: * server have written.
254: */
255: public long getRequestWriteBytesTotal() {
256: return -1;
257: }
258:
259: /**
260: * Returns the invocation cache hit count.
261: */
262: public long getInvocationCacheHitCountTotal() {
263: return _server.getInvocationCacheHitCount();
264: }
265:
266: /**
267: * Returns the invocation cache miss count.
268: */
269: public long getInvocationCacheMissCountTotal() {
270: return _server.getInvocationCacheMissCount();
271: }
272:
273: /**
274: * Returns the current total amount of memory available for the JVM, in bytes.
275: */
276: public long getRuntimeMemory() {
277: return Runtime.getRuntime().totalMemory();
278: }
279:
280: /**
281: * Returns the current free amount of memory available for the JVM, in bytes.
282: */
283: public long getRuntimeMemoryFree() {
284: return Runtime.getRuntime().freeMemory();
285: }
286:
287: /**
288: * Returns the CPU load average.
289: */
290: public double getCpuLoadAvg() {
291: try {
292: if (Alarm.isTest())
293: return 0;
294: else
295: return CauchoSystem.getLoadAvg();
296: } catch (Exception e) {
297: return 0;
298: }
299: }
300:
301: //
302: // Operations
303: //
304:
305: /**
306: * Restart this Resin server.
307: */
308: public void restart() {
309: _server.destroy();
310: }
311: }
|