--- experimental/server/SampleConfigObtainer/SampleConfigObtainer.java 2000/11/13 16:36:03 1.3 +++ experimental/server/SampleConfigObtainer/SampleConfigObtainer.java 2000/11/21 15:08:42 1.4 @@ -1,115 +1,122 @@ -//---PACKAGE DECLARATION--- - -//---IMPORTS--- -import uk.ac.ukc.iscream.core.*; -import org.omg.CORBA.*; -import org.omg.CosNaming.*; - -/** - * A quick class to test the Configurator and Configuration implementations - * - * @author $Author: tdb $ - * @version $Id: SampleConfigObtainer.java,v 1.3 2000/11/13 16:36:03 tdb Exp $ - */ -class SampleConfigObtainer { - -//---FINAL ATTRIBUTES--- - - /** - * The current CVS revision of this class - */ - public static final String REVISION = "$Revision: 1.3 $"; - -//---STATIC METHODS--- - - public static void main(String[] args) { - try { - ORB orb = ORB.init(args, null); - - // something to hold objects - org.omg.CORBA.Object objRef = null; - - // get the Root POA - //objRef = orb.resolve_initial_references("RootPOA"); - //POA poa = POAHelper.narrow(objRef); - - // get a hook to the name service - objRef = orb.resolve_initial_references("NameService"); - NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); - - // get a ref to the Configurator - objRef = ncRef.resolve(ncRef.to_name("iscream.Configurator")); - Configurator configurator = ConfiguratorHelper.narrow(objRef); - - // start the POA off - //poa.the_POAManager().activate(); - - // the name of the test config - String config = "myconfig"; - - // a test property to get - String testProperty = "test"; - - System.out.println("Started:" + REVISION); - System.out.println("Trying to get Configuration " + config); - - // get the config - Configuration myConfig = configurator.getConfiguration(config); - - // did we? - if (myConfig == null) { - System.out.println("Failed: is it there?, can you read it?"); - } else { - - System.out.println("Success."); - System.out.println("Trying to get property " + testProperty); - - // get the property - try { - System.out.println("Response:" + myConfig.getProperty(testProperty)); - } catch (org.omg.CORBA.MARSHAL e) { - System.out.println("Caught org.omg.CORBA.MARSHAL, must be a null we got back"); - } - } - - System.out.println("Testing configuration change system."); - System.out.println("Waiting for configuration change on 1 second intervals"); - - // get our last modified - long myLastModified = myConfig.getLastModified(); - - // get a ref to the last modified of file NOW... - boolean changed = configurator.isModified(config,myLastModified); - - // keep checking, every second until it changes - while (!changed) { - Thread.sleep(1000); - changed = configurator.isModified(config,myLastModified); - } - - // get the config again and print out the new time to compare - just to check ;-) - myConfig = configurator.getConfiguration(config); - System.out.println("Configuration changed: " + myLastModified + " -> " + myConfig.getLastModified()); - - // done testing - System.out.println("Finished"); - - } catch (Exception e) { - System.err.println("TESTER ERROR: " + e); - e.printStackTrace(System.out); - } - } - -//---CONSTRUCTORS--- - -//---PUBLIC METHODS--- - -//---PRIVATE METHODS--- - -//---ACCESSOR/MUTATOR METHODS--- - -//---ATTRIBUTES--- - -//---STATIC ATTRIBUTES--- - +//---PACKAGE DECLARATION--- + +//---IMPORTS--- +import uk.ac.ukc.iscream.core.*; +import org.omg.CORBA.*; +import org.omg.CosNaming.*; + +/** + * A quick class to test the Configurator and Configuration implementations + * + * @author $Author: tdb $ + * @version $Id: SampleConfigObtainer.java,v 1.4 2000/11/21 15:08:42 tdb Exp $ + */ +class SampleConfigObtainer { + +//---FINAL ATTRIBUTES--- + + /** + * The current CVS revision of this class + */ + public static final String REVISION = "$Revision: 1.4 $"; + +//---STATIC METHODS--- + + public static void main(String[] args) { + try { + ORB orb = ORB.init(args, null); + + // something to hold objects + org.omg.CORBA.Object objRef = null; + + // get the Root POA + //objRef = orb.resolve_initial_references("RootPOA"); + //POA poa = POAHelper.narrow(objRef); + + // get a hook to the name service + objRef = orb.resolve_initial_references("NameService"); + NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef); + + // get a ref to the Configurator + objRef = ncRef.resolve(ncRef.to_name("iscream.ConfigurationManager")); + ConfigurationManager configMan = ConfigurationManagerHelper.narrow(objRef); + + // start the POA off + //poa.the_POAManager().activate(); + + // the name of the test config + String config = "myconfig"; + + System.out.println("Started:" + REVISION); + System.out.println("Trying to get Configuration " + config); + + // get the config + Configuration myConfig = configMan.getConfiguration(config); + + // did we? + if (myConfig == null) { + System.out.println("Failed: is it there?, can you read it?"); + } else { + + System.out.println("Success."); + System.out.println("Trying to get property tests:"); + + // get the property + try { + System.out.println("Response (for config file):" + myConfig.getProperty("test")); + System.out.println("Response (for system file):" + myConfig.getProperty("system")); + System.out.println("Response (for web include):" + myConfig.getProperty("web")); + System.out.println("Response (for web->web1 include):" + myConfig.getProperty("web1")); + System.out.println("Response (for server include):" + myConfig.getProperty("server")); + System.out.println("Response (for server->server1 include):" + myConfig.getProperty("server1")); + System.out.println("Response (for server->server1->server1a include):" + myConfig.getProperty("server1a")); + System.out.println("Response (for server->server2 include):" + myConfig.getProperty("server2")); + System.out.println("Response (override):" + myConfig.getProperty("overridetest")); + } catch (org.omg.CORBA.MARSHAL e) { + System.out.println("Caught org.omg.CORBA.MARSHAL, must be a null we got back"); + } + } + + System.out.println("Testing configuration change system."); + System.out.println("Waiting for configuration change on 1 second intervals"); + + // get our last modified + long myLastModified = myConfig.getLastModified(); + String myFileList = myConfig.getFileList(); + // get a ref to the last modified of file NOW... + boolean changed = configMan.isModified(myFileList,myLastModified); + + System.out.println("Config tree: " + myFileList); + System.out.println("Most recent change: " + myLastModified); + // keep checking, every second until it changes + while (!changed) { + Thread.sleep(1000); + changed = configMan.isModified(myFileList,myLastModified); + } + + // get the config again and print out the new time to compare - just to check ;-) + myConfig = configMan.getConfiguration(config); + System.out.println("Configuration changed: " + myLastModified + " -> " + myConfig.getLastModified()); + + // done testing + System.out.println("Finished"); + + } catch (Exception e) { + System.err.println("TESTER ERROR: " + e); + e.printStackTrace(System.out); + } + } + +//---CONSTRUCTORS--- + +//---PUBLIC METHODS--- + +//---PRIVATE METHODS--- + +//---ACCESSOR/MUTATOR METHODS--- + +//---ATTRIBUTES--- + +//---STATIC ATTRIBUTES--- + } \ No newline at end of file