1 |
tdb |
1.4 |
//---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: tdb1 $ |
12 |
|
|
* @version $Id: SampleConfigObtainer.java,v 1.3 2000/11/13 16:36:03 tdb1 Exp $ |
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: 1.3 $"; |
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 |
ajm |
1.1 |
} |