01: /*
02: Copyright (C) 2004 David Bucciarelli (davibu@interfree.it)
03:
04: This program is free software; you can redistribute it and/or
05: modify it under the terms of the GNU General Public License
06: as published by the Free Software Foundation; either version 2
07: of the License, or (at your option) any later version.
08:
09: This program is distributed in the hope that it will be useful,
10: but WITHOUT ANY WARRANTY; without even the implied warranty of
11: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: GNU General Public License for more details.
13:
14: You should have received a copy of the GNU General Public License
15: along with this program; if not, write to the Free Software
16: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17: */
18:
19: package org.homedns.dade.jcgrid.server;
20:
21: import java.io.*;
22: import java.net.*;
23: import java.util.*;
24:
25: import org.apache.log4j.*;
26:
27: import org.homedns.dade.jcgrid.*;
28: import org.homedns.dade.jcgrid.message.*;
29: import org.homedns.dade.jcgrid.util.*;
30:
31: public class AdminHandlerThread extends HandlerThread {
32: public AdminHandlerThread(GridServer server, Socket socket)
33: throws IOException {
34: super (GridNodeConfig.TYPE_ADMIN, server, socket);
35:
36: if (log.isDebugEnabled())
37: log.debug("Start AdminHandlerThread(" + server + ","
38: + socket + ")");
39: if (log.isDebugEnabled())
40: log.debug("End AdminHandlerThread()");
41: }
42:
43: protected void handleMsg(GridMessage msg) throws Exception {
44: if (log.isDebugEnabled())
45: log.debug("Start handleMsg()");
46:
47: if (msg instanceof GridMessageAdminGetWorkerStats) {
48: if (log.isDebugEnabled())
49: log
50: .debug(" Received work request AdminGetWorkerStats");
51:
52: HandlerThreads whs = gridServer.getWorkerHandlers();
53: GridMessageAdminWorkerStats ws = new GridMessageAdminWorkerStats();
54: for (Iterator i = whs.getSessionNames().iterator(); i
55: .hasNext();) {
56: String name = (String) i.next();
57:
58: WorkerHandlerThread wht = (WorkerHandlerThread) whs
59: .getConnectedHandler(name);
60: if (wht != null) {
61: if (log.isDebugEnabled())
62: log.debug(" Session name: "
63: + wht.getSessionName());
64:
65: WorkerStats wstat = wht.getStats();
66:
67: if (wstat != null)
68: ws.addStats(wstat);
69: }
70: }
71:
72: handlerChannel.send(ws);
73: } else if (msg instanceof GridMessageAdminGetGridStats) {
74: if (log.isDebugEnabled())
75: log.debug(" Received work request AdminGetGridStats");
76:
77: int workerCount = gridServer.getWorkerHandlers()
78: .getConnectedHandlerCount();
79: int queueSize = gridServer.getRequestQueueSize();
80:
81: GridStats s = new GridStats(workerCount, queueSize);
82: GridMessageAdminGridStats gs = new GridMessageAdminGridStats(
83: s);
84: handlerChannel.send(gs);
85: } else
86: log
87: .warn("Unknown message in AdminHandlerThread.handleMsg(): "
88: + msg);
89: }
90: }
|