KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > server > cluster > ServerAdmin


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

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 JavaDoc;
42 import java.util.Date JavaDoc;
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 JavaDoc getName()
57   {
58     return null;
59   }
60
61   public String JavaDoc getType()
62   {
63     return "Server";
64   }
65
66   public String JavaDoc getId()
67   {
68     return _server.getServerId();
69   }
70
71   //
72
// Hierarchy
73
//
74

75   /**
76    * Returns the cluster owning this server
77    */

78   public ClusterMXBean getCluster()
79   {
80     return _server.getCluster().getAdmin();
81   }
82
83   /**
84    * Returns the array of ports.
85    */

86   public PortMXBean []getPorts()
87   {
88     Collection JavaDoc<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   /**
101    * Returns the server's thread pool administration
102    */

103   public ThreadPoolMXBean getThreadPool()
104   {
105     return ThreadPoolAdmin.create();
106   }
107
108   /**
109    * Returns the cluster port
110    */

111   public PortMXBean getClusterPort()
112   {
113     return null;
114   }
115
116   //
117
// Configuration attributes
118
//
119

120   /**
121    * Returns true if a {@link com.caucho.server.port.AbstractSelectManager} is enabled and active
122    */

123   public boolean isSelectManagerEnabled()
124   {
125     // return _server.isSelectManagedEnabled();
126
return false;
127   }
128
129   /**
130    * Returns true if detailed statistics are being kept.
131    */

132   public boolean isDetailedStatistics()
133   {
134     return false;
135   }
136
137   //
138
// state
139
//
140

141   /**
142    * The current lifecycle state.
143    */

144   public String JavaDoc getState()
145   {
146     return _server.getState();
147   }
148
149   /**
150    * Returns the last start time.
151    */

152   public Date JavaDoc getStartTime()
153   {
154     return new Date JavaDoc(_server.getStartTime());
155   }
156
157   //
158
// statistics
159
//
160

161   /**
162    * Returns the current number of threads that are servicing requests.
163    */

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   /**
181    * Returns the current number of connections that are in the keepalive
182    * state and are using a thread to maintain the connection.
183    */

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   /**
201    * Returns the current number of connections that are in the keepalive
202    * state and are using select to maintain the connection.
203    */

204   public int getSelectKeepaliveCount()
205   {
206     return -1;
207   }
208
209   /**
210    * Returns the total number of requests serviced by the server
211    * since it started.
212    */

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   /**
224    * Returns the number of requests that have ended up in the keepalive state
225    * for this server in it's lifetime.
226    */

227   public long getKeepaliveCountTotal()
228   {
229     return -1;
230   }
231
232   /**
233    * The total number of connections that have terminated with
234    * {@link com.caucho.vfs.ClientDisconnectException}.
235    */

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   /**
247    * Returns the total duration in milliseconds that requests serviced by
248    * this server have taken.
249    */

250   public long getRequestTimeTotal()
251   {
252     return -1;
253   }
254
255   /**
256    * Returns the total number of bytes that requests serviced by this
257    * server have read.
258    */

259   public long getRequestReadBytesTotal()
260   {
261     return -1;
262   }
263
264   /**
265    * Returns the total number of bytes that requests serviced by this
266    * server have written.
267    */

268   public long getRequestWriteBytesTotal()
269   {
270     return -1;
271   }
272
273   /**
274    * Returns the invocation cache hit count.
275    */

276   public long getInvocationCacheHitCountTotal()
277   {
278     return _server.getInvocationCacheHitCount();
279   }
280
281   /**
282    * Returns the invocation cache miss count.
283    */

284   public long getInvocationCacheMissCountTotal()
285   {
286     return _server.getInvocationCacheMissCount();
287   }
288
289   /**
290    * Returns the current total amount of memory available for the JVM, in bytes.
291    */

292   public long getRuntimeMemory()
293   {
294     return Runtime.getRuntime().totalMemory();
295   }
296
297   /**
298    * Returns the current free amount of memory available for the JVM, in bytes.
299    */

300   public long getRuntimeMemoryFree()
301   {
302     return Runtime.getRuntime().freeMemory();
303   }
304
305   /**
306    * Returns the CPU load average.
307    */

308   public double getCpuLoadAvg()
309   {
310     try {
311       return CauchoSystem.getLoadAvg();
312     } catch (Exception JavaDoc e) {
313       return 0;
314     }
315   }
316
317   //
318
// Operations
319
//
320

321   /**
322    * Restart this Resin server.
323    */

324   public void restart()
325   {
326     _server.destroy();
327   }
328 }
329
Popular Tags