001: /*
002: Copyright (C) 2004 David Bucciarelli (davibu@interfree.it)
003:
004: This program is free software; you can redistribute it and/or
005: modify it under the terms of the GNU General Public License
006: as published by the Free Software Foundation; either version 2
007: of the License, or (at your option) any later version.
008:
009: This program is distributed in the hope that it will be useful,
010: but WITHOUT ANY WARRANTY; without even the implied warranty of
011: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: GNU General Public License for more details.
013:
014: You should have received a copy of the GNU General Public License
015: along with this program; if not, write to the Free Software
016: Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: */
018:
019: package org.homedns.dade.jcgrid.admin;
020:
021: import java.io.*;
022: import java.util.*;
023: import java.net.*;
024: import javax.net.ssl.*;
025:
026: import org.apache.log4j.*;
027:
028: import org.homedns.dade.jcgrid.*;
029: import org.homedns.dade.jcgrid.message.*;
030: import org.homedns.dade.jcgrid.server.*;
031: import org.homedns.dade.jcgrid.vfs.*;
032: import org.homedns.dade.jcgrid.util.*;
033:
034: public class GridAdmin extends GridNodeGeneric {
035: private final static String className = GridAdmin.class.getName();
036: private static Logger log = Logger.getLogger(className);
037: private static Logger logDetail = Logger.getLogger("DETAIL."
038: + className);
039:
040: private vfsSession session;
041:
042: public GridAdmin() {
043: super (new GridNodeAdminConfig());
044:
045: if (log.isDebugEnabled())
046: log.debug("Start GridAdmin()");
047:
048: session = null;
049:
050: super .getNodeConfig().setWorkingDir(
051: System.getProperty("user.dir"));
052:
053: if (log.isDebugEnabled())
054: log.debug("End GridAdmin()");
055: }
056:
057: public long ping() throws Exception {
058: if (log.isDebugEnabled())
059: log.debug("Start ping()");
060:
061: long res;
062: long t1 = System.currentTimeMillis();
063:
064: super .getGridMessageChannel().send(new GridMessagePing());
065: GridMessage msg = super .getGridMessageChannel().recv(30 * 1000);
066:
067: if ((msg == null) || (!(msg instanceof GridMessagePingAck)))
068: res = -1;
069: else
070: res = System.currentTimeMillis() - t1;
071:
072: if (log.isDebugEnabled())
073: log.debug("End ping(" + res + ")");
074:
075: return res;
076: }
077:
078: public Vector getWorkerStats() throws Exception {
079: if (log.isDebugEnabled())
080: log.debug("Start getWorkerStats()");
081:
082: Vector res;
083: super .getGridMessageChannel().send(
084: new GridMessageAdminGetWorkerStats());
085: GridMessage msg = super .getGridMessageChannel().recv(30 * 1000);
086:
087: if ((msg == null)
088: || (!(msg instanceof GridMessageAdminWorkerStats)))
089: res = null;
090: else
091: res = ((GridMessageAdminWorkerStats) msg).getStats();
092:
093: if (log.isDebugEnabled())
094: log.debug("End getWorkerStats(" + res + ")");
095:
096: return res;
097: }
098:
099: public GridStats getGridStats() throws Exception {
100: if (log.isDebugEnabled())
101: log.debug("Start getGridStats()");
102:
103: GridStats res;
104: super .getGridMessageChannel().send(
105: new GridMessageAdminGetGridStats());
106: GridMessage msg = super .getGridMessageChannel().recv(30 * 1000);
107:
108: if ((msg == null)
109: || (!(msg instanceof GridMessageAdminGridStats)))
110: res = null;
111: else
112: res = ((GridMessageAdminGridStats) msg).getStats();
113:
114: if (log.isDebugEnabled())
115: log.debug("End getGridStats(" + res + ")");
116:
117: return res;
118: }
119: }
|