ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/experimental/server/SampleConfigObtainer/SampleConfigObtainer.java
Revision: 1.3
Committed: Mon Nov 13 16:36:03 2000 UTC (24 years ago) by tdb
Branch: MAIN
Changes since 1.2: +4 -4 lines
Log Message:
Modified imports of all existing classes to use the new package structure introduced by iscream.idl

File Contents

# User Rev Content
1 ajm 1.1 //---PACKAGE DECLARATION---
2    
3     //---IMPORTS---
4 tdb 1.3 import uk.ac.ukc.iscream.core.*;
5 ajm 1.1 import org.omg.CORBA.*;
6     import org.omg.CosNaming.*;
7    
8     /**
9     * A quick class to test the Configurator and Configuration implementations
10     *
11 tdb 1.3 * @author $Author: tdb1 $
12     * @version $Id: SampleConfigObtainer.java,v 1.2 2000/11/13 16:11:03 tdb1 Exp $
13 ajm 1.1 */
14     class SampleConfigObtainer {
15    
16     //---FINAL ATTRIBUTES---
17    
18     /**
19     * The current CVS revision of this class
20     */
21 tdb 1.3 public static final String REVISION = "$Revision: 1.2 $";
22 ajm 1.1
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 tdb 1.2 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 ajm 1.1 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    
115     }