KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > server > resin > 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.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 JavaDoc;
46 import java.util.Date JavaDoc;
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 JavaDoc getName()
60   {
61     return null;
62   }
63
64   public String JavaDoc 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   /**
82    * Returns the id
83    */

84   public String JavaDoc getId()
85   {
86     return _server.getServerId();
87   }
88   
89   public ThreadPoolMXBean getThreadPool()
90   {
91     //return _server.getThreadPool();
92
throw new UnsupportedOperationException JavaDoc();
93   }
94
95   public PortMXBean []getPorts()
96   {
97     Server server = _server;
98
99     if (server == null)
100       return new PortMXBean[0];
101
102     ArrayList JavaDoc<PortMXBean> portList = new ArrayList JavaDoc<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 JavaDoc 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 JavaDoc<HostMXBean> hostList = new ArrayList JavaDoc<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     // XXX: sort
158

159     return hostList.toArray(new HostMXBean[hostList.size()]);
160   }
161
162   public String JavaDoc getState()
163   {
164     // return _server.getState();
165
throw new UnsupportedOperationException JavaDoc();
166   }
167
168   public Date JavaDoc getInitialStartTime()
169   {
170     // return new Date(_server.getStartTime());
171
throw new UnsupportedOperationException JavaDoc();
172   }
173
174   public Date JavaDoc getStartTime()
175   {
176     // return new Date(_server.getStartTime());
177
throw new UnsupportedOperationException JavaDoc();
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 JavaDoc hostRegexp, String JavaDoc 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