--- projects/cms/source/host/java/JavaHost.java 2000/11/30 04:08:25 1.3 +++ projects/cms/source/host/java/JavaHost.java 2000/12/08 15:44:56 1.5 @@ -8,7 +8,7 @@ * Hopefully fully functional and thus can be used as part of a test rig. * * @author $Author: ab11 $ - * @version $Id: JavaHost.java,v 1.3 2000/11/30 04:08:25 ab11 Exp $ + * @version $Id: JavaHost.java,v 1.5 2000/12/08 15:44:56 ab11 Exp $ */ class JavaHost { @@ -20,32 +20,88 @@ class JavaHost { /** * Constructor for the class. Takes in the hostname and port number - * of the Configuration Manager. + * of the Filter Manager. * */ public JavaHost( String serverName, int port ){ - // create a connection to the configurator - System.out.println("Creating connection with Configurtator"); + // 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 configurator + // the configuration system - // create a SystemMonitor object and pass the confifurator + // 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 ;) - // send a udp packet to the filter declared in config - // send it the xml packet created by getInfo() - System.out.println("Sending UDP Packet"); - LowLevelNet.sendUDPPacket(config, sysMon.getInfo()); - config.sendHeartBeat(); - if ( config.reloadConfig() ){ - System.out.println("Resarting System"); - break; + + if ( nextTCP < nextUDP ){ + try { + long sleeptime = nextTCP - currentTime; + if ( sleeptime > 0 ){ + Thread.sleep(sleeptime); + } + nextTCP += tcpcheckInterval; + // send a heartbeat + System.out.println("Sending Heartbeat"); + config.sendHeartBeat(); + if ( config.reloadConfig() ){ + System.out.println("Resarting 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"); + LowLevelNet.sendUDPPacket(config, sysMon.getInfo()); + + } + catch ( InterruptedException e ){ + // do nothing + } + } + + + } // while @@ -59,6 +115,11 @@ class JavaHost { //---ACCESSOR/MUTATOR METHODS--- //---ATTRIBUTES--- + + private long udpcheckInterval; + private long tcpcheckInterval; + private final long defaultUpdateTime = 60000; + //---STATIC ATTRIBUTES---