ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/experimental/server/SampleConfigObtainer/SampleConfigObtainer.java
(Generate patch)

Comparing experimental/server/SampleConfigObtainer/SampleConfigObtainer.java (file contents):
Revision 1.3 by tdb, Mon Nov 13 16:36:03 2000 UTC vs.
Revision 1.4 by tdb, Tue Nov 21 15:08:42 2000 UTC

# Line 1 | Line 1
1 < //---PACKAGE DECLARATION---
2 <
3 < //---IMPORTS---
4 < import uk.ac.ukc.iscream.core.*;
5 < import org.omg.CORBA.*;
6 < import org.omg.CosNaming.*;
7 <
8 < /**
9 < * A quick class to test the Configurator and Configuration implementations
10 < *
11 < * @author  $Author$
12 < * @version $Id$
13 < */
14 < class SampleConfigObtainer {
15 <
16 < //---FINAL ATTRIBUTES---
17 <
18 <    /**
19 <     * The current CVS revision of this class
20 <     */
21 <    public static final String REVISION = "$Revision$";
22 <    
23 < //---STATIC METHODS---
24 <
25 <    public static void main(String[] args) {
26 <        try {        
27 <            ORB orb = ORB.init(args, null);
28 <            
29 <            // something to hold objects
30 <            org.omg.CORBA.Object objRef = null;    
31 <            
32 <            // get the Root POA
33 <            //objRef = orb.resolve_initial_references("RootPOA");
34 <            //POA poa = POAHelper.narrow(objRef);
35 <              
36 <            // get a hook to the name service
37 <            objRef = orb.resolve_initial_references("NameService");
38 <            NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
39 <                
40 <            // get a ref to the Configurator
41 <            objRef = ncRef.resolve(ncRef.to_name("iscream.Configurator"));
42 <            Configurator configurator = ConfiguratorHelper.narrow(objRef);
43 <                
44 <            // start the POA off
45 <            //poa.the_POAManager().activate();
46 <            
47 <            // the name of the test config
48 <            String config = "myconfig";
49 <            
50 <            // a test property to get
51 <            String testProperty = "test";
52 <            
53 <            System.out.println("Started:" + REVISION);
54 <            System.out.println("Trying to get Configuration " + config);
55 <            
56 <            // get the config
57 <            Configuration myConfig = configurator.getConfiguration(config);
58 <            
59 <            // did we?
60 <            if (myConfig == null) {
61 <                System.out.println("Failed: is it there?, can you read it?");
62 <            } else {
63 <                
64 <                System.out.println("Success.");
65 <                System.out.println("Trying to get property " + testProperty);
66 <                
67 <                // get the property
68 <                try {
69 <                    System.out.println("Response:" + myConfig.getProperty(testProperty));
70 <                } catch (org.omg.CORBA.MARSHAL e) {
71 <                    System.out.println("Caught org.omg.CORBA.MARSHAL, must be a null we got back");
72 <                }
73 <            }
74 <            
75 <            System.out.println("Testing configuration change system.");
76 <            System.out.println("Waiting for configuration change on 1 second intervals");
77 <            
78 <            // get our last modified
79 <            long myLastModified = myConfig.getLastModified();
80 <            
81 <            // get a ref to the last modified of file NOW...
82 <            boolean changed = configurator.isModified(config,myLastModified);
83 <            
84 <            // keep checking, every second until it changes
85 <            while (!changed) {
86 <                Thread.sleep(1000);
87 <                changed = configurator.isModified(config,myLastModified);
88 <            }
89 <            
90 <            // get the config again and print out the new time to compare - just to check ;-)
91 <            myConfig = configurator.getConfiguration(config);
92 <            System.out.println("Configuration changed: " + myLastModified + " -> " + myConfig.getLastModified());
93 <            
94 <            // done testing
95 <            System.out.println("Finished");
96 <
97 <        } catch (Exception e) {
98 <            System.err.println("TESTER ERROR: " + e);
99 <            e.printStackTrace(System.out);
100 <        }
101 <    }
102 <
103 < //---CONSTRUCTORS---
104 <
105 < //---PUBLIC METHODS---
106 <
107 < //---PRIVATE METHODS---
108 <
109 < //---ACCESSOR/MUTATOR METHODS---
110 <
111 < //---ATTRIBUTES---
112 <
113 < //---STATIC ATTRIBUTES---
114 <
1 > //---PACKAGE DECLARATION---
2 >
3 > //---IMPORTS---
4 > import uk.ac.ukc.iscream.core.*;
5 > import org.omg.CORBA.*;
6 > import org.omg.CosNaming.*;
7 >
8 > /**
9 > * A quick class to test the Configurator and Configuration implementations
10 > *
11 > * @author  $Author$
12 > * @version $Id$
13 > */
14 > class SampleConfigObtainer {
15 >
16 > //---FINAL ATTRIBUTES---
17 >
18 >    /**
19 >     * The current CVS revision of this class
20 >     */
21 >    public static final String REVISION = "$Revision$";
22 >    
23 > //---STATIC METHODS---
24 >
25 >    public static void main(String[] args) {
26 >        try {        
27 >            ORB orb = ORB.init(args, null);
28 >            
29 >            // something to hold objects
30 >            org.omg.CORBA.Object objRef = null;    
31 >            
32 >            // get the Root POA
33 >            //objRef = orb.resolve_initial_references("RootPOA");
34 >            //POA poa = POAHelper.narrow(objRef);
35 >              
36 >            // get a hook to the name service
37 >            objRef = orb.resolve_initial_references("NameService");
38 >            NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
39 >                
40 >            // get a ref to the Configurator
41 >            objRef = ncRef.resolve(ncRef.to_name("iscream.ConfigurationManager"));
42 >            ConfigurationManager configMan = ConfigurationManagerHelper.narrow(objRef);
43 >                
44 >            // start the POA off
45 >            //poa.the_POAManager().activate();
46 >            
47 >            // the name of the test config
48 >            String config = "myconfig";
49 >            
50 >            System.out.println("Started:" + REVISION);
51 >            System.out.println("Trying to get Configuration " + config);
52 >            
53 >            // get the config
54 >            Configuration myConfig = configMan.getConfiguration(config);
55 >            
56 >            // did we?
57 >            if (myConfig == null) {
58 >                System.out.println("Failed: is it there?, can you read it?");
59 >            } else {
60 >                
61 >                System.out.println("Success.");
62 >                System.out.println("Trying to get property tests:");
63 >                
64 >                // get the property
65 >                try {
66 >                    System.out.println("Response (for config file):" + myConfig.getProperty("test"));
67 >                    System.out.println("Response (for system file):" + myConfig.getProperty("system"));
68 >                    System.out.println("Response (for web include):" + myConfig.getProperty("web"));
69 >                    System.out.println("Response (for web->web1 include):" + myConfig.getProperty("web1"));
70 >                    System.out.println("Response (for server include):" + myConfig.getProperty("server"));
71 >                    System.out.println("Response (for server->server1 include):" + myConfig.getProperty("server1"));
72 >                    System.out.println("Response (for server->server1->server1a include):" + myConfig.getProperty("server1a"));
73 >                    System.out.println("Response (for server->server2 include):" + myConfig.getProperty("server2"));
74 >                    System.out.println("Response (override):" + myConfig.getProperty("overridetest"));
75 >                } catch (org.omg.CORBA.MARSHAL e) {
76 >                    System.out.println("Caught org.omg.CORBA.MARSHAL, must be a null we got back");
77 >                }
78 >            }
79 >            
80 >            System.out.println("Testing configuration change system.");
81 >            System.out.println("Waiting for configuration change on 1 second intervals");
82 >            
83 >            // get our last modified
84 >            long myLastModified = myConfig.getLastModified();
85 >            String myFileList = myConfig.getFileList();
86 >            // get a ref to the last modified of file NOW...
87 >            boolean changed = configMan.isModified(myFileList,myLastModified);
88 >            
89 >            System.out.println("Config tree: " + myFileList);
90 >            System.out.println("Most recent change: " + myLastModified);
91 >            // keep checking, every second until it changes
92 >            while (!changed) {
93 >                Thread.sleep(1000);
94 >                changed = configMan.isModified(myFileList,myLastModified);
95 >            }
96 >            
97 >            // get the config again and print out the new time to compare - just to check ;-)
98 >            myConfig = configMan.getConfiguration(config);
99 >            System.out.println("Configuration changed: " + myLastModified + " -> " + myConfig.getLastModified());
100 >            
101 >            // done testing
102 >            System.out.println("Finished");
103 >
104 >        } catch (Exception e) {
105 >            System.err.println("TESTER ERROR: " + e);
106 >            e.printStackTrace(System.out);
107 >        }
108 >    }
109 >
110 > //---CONSTRUCTORS---
111 >
112 > //---PUBLIC METHODS---
113 >
114 > //---PRIVATE METHODS---
115 >
116 > //---ACCESSOR/MUTATOR METHODS---
117 >
118 > //---ATTRIBUTES---
119 >
120 > //---STATIC ATTRIBUTES---
121 >
122   }            

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines