--- projects/cms/source/host/java/JavaHost.java 2000/11/27 19:48:03 1.1 +++ projects/cms/source/host/java/JavaHost.java 2002/05/21 16:47:12 1.9 @@ -1,28 +1,148 @@ -/* Java Host for i-scream -* Written by Ash Beeson ab11 -* Version History: -* 1.0 12/11/00 Inital working version -*/ +/* + * i-scream central monitoring system + * http://www.i-scream.org.uk + * Copyright (C) 2000-2002 i-scream + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +//---PACKAGE DECLARATION--- + +//---IMPORTS--- + +/** + * A small efficient JavaHost + * Designed to be used as a working design to build the C++ hosts on. + * Hopefully fully functional and thus can be used as part of a test rig. + * + * @author $Author: tdb $ + * @version $Id: JavaHost.java,v 1.9 2002/05/21 16:47:12 tdb Exp $ + */ class JavaHost { - - public JavaHost( String serverName, int port ){ - // create a connection to the configurator - Config config = new Config(serverName, port); - // the config class knows what values it wants to get from - // the configurator - - // create a SystemMonitor object and pass the confifurator - // as a param so it knows what to do! - SystemMonitor sysMon = new SystemMonitor(config); - - while ( true ){ - // keep going for ever and ever ;) - // send a udp packet to the filter declared in config - // send it the xml packet created by getInfo() - LowLevelNet.sendUDPPacket(config, sysMon.getInfo()); - } - - } // public javahost - -} // class \ No newline at end of file + +//---FINAL ATTRIBUTES--- + +//---STATIC METHODS--- + +//---CONSTRUCTORS--- + + /** + * Constructor for the class. Takes in the hostname and port number + * of the Filter Manager. + * + */ + public JavaHost( String serverName, int port ){ + // create a connection to the filter manager + System.out.println("Creating connection with Filter Manager"); + Config config = new Config(serverName, port); + // the config class knows what values it wants to get from + // the configuration system + + // create a SystemMonitor object and pass the config + // as a param so it knows what to do! + System.out.println("Creating System Monitor"); + SystemMonitor sysMon = new SystemMonitor(config); + + try { + udpcheckInterval = Long.parseLong(config.getProperty("UDPUpdateTime")) * 1000; + System.out.println("Configured UDPUpdateTime"); + } + catch ( NumberFormatException e ){ + System.out.println("The value for UDPUpdateTime is invalid, using a default"); + // 1 mins + udpcheckInterval = 1000 * 60; // 1 minute + } + + try { + tcpcheckInterval = Long.parseLong(config.getProperty("TCPUpdateTime")) * 1000; + System.out.println("Configured TCPUpdateTime"); + } + catch ( NumberFormatException e ){ + System.out.println("The value for UDPUpdateTime is invalid, using a default"); + // 10 mins + tcpcheckInterval = 10000 * 60; // 5 minutes + } + + // the current time.. + long currentTime = System.currentTimeMillis(); + long nextUDP = currentTime + udpcheckInterval; + long nextTCP = currentTime + tcpcheckInterval; + + while ( true ){ + currentTime = System.currentTimeMillis(); + // keep going for ever and ever ;) + + if ( nextTCP < nextUDP ){ + try { + long sleeptime = nextTCP - currentTime; + if ( sleeptime > 0 ){ + Thread.sleep(sleeptime); + } + nextTCP += tcpcheckInterval; + // send a heartbeat + //System.out.println("Sending Heartbeat"); + System.out.print("+"); + config.sendHeartBeat(); + if ( config.reloadConfig() ){ + System.out.println("\nRestarting System"); + break; + } + } + catch ( InterruptedException e ){ + // do nothing + } + } + else { + try { + long sleeptime = nextUDP - currentTime; + if ( sleeptime > 0 ){ + Thread.sleep(sleeptime); + } + nextUDP += udpcheckInterval; + // send a heartbeat + //System.out.println("Sending UDP Packet"); + System.out.print("."); + LowLevelNet.sendUDPPacket(config, sysMon.getInfo()); + + } + catch ( InterruptedException e ){ + // do nothing + } + } + + + + } // while + + + } // public javahost + + +//---PUBLIC METHODS--- + +//---PRIVATE METHODS--- + +//---ACCESSOR/MUTATOR METHODS--- + +//---ATTRIBUTES--- + + private long udpcheckInterval; + private long tcpcheckInterval; + private final long defaultUpdateTime = 60000; + + +//---STATIC ATTRIBUTES--- + +} // class