1 |
< |
//---PACKAGE DECLARATION--- |
2 |
< |
|
3 |
< |
//---IMPORTS--- |
4 |
< |
import uk.ac.ukc.iscream.core.*; |
5 |
< |
import java.util.*; |
6 |
< |
import java.io.*; |
7 |
< |
import java.text.DateFormat; |
8 |
< |
|
9 |
< |
/** |
10 |
< |
* An implementation of the Configuration IDL |
11 |
< |
* This class allows i-scream modules to read and even |
12 |
< |
* set their configuration from a central location. |
13 |
< |
* |
14 |
< |
* When classes want their configuration, they contact |
15 |
< |
* the Configurator, which will locate their config, |
16 |
< |
* open it and pass it to a Configuration object which is |
17 |
< |
* then passed back to the calling class. |
18 |
< |
* |
19 |
< |
* Essentially this class behaves in a similar fashion |
20 |
< |
* to the java.util.Properties class. |
21 |
< |
* |
22 |
< |
* @author $Author$ |
23 |
< |
* @version $Id$ |
24 |
< |
*/ |
25 |
< |
class ConfigurationServant extends ConfigurationPOA { |
26 |
< |
|
27 |
< |
//---FINAL ATTRIBUTES--- |
28 |
< |
|
29 |
< |
/** |
30 |
< |
* The current CVS revision of this class |
31 |
< |
*/ |
32 |
< |
public final String REVISION = "$Revision$"; |
33 |
< |
|
34 |
< |
//---STATIC METHODS--- |
35 |
< |
|
36 |
< |
//---CONSTRUCTORS--- |
37 |
< |
|
38 |
< |
/** |
39 |
< |
* Creates a new ConfigurationServant taking a hook |
40 |
< |
* to a file containing the configuration. |
41 |
< |
* |
42 |
< |
* @param propertiesStream an InputStream connected to the configuration |
43 |
< |
*/ |
44 |
< |
ConfigurationServant(Properties properties, long lastModified, Logger logRef) { |
45 |
< |
_properties = properties; |
46 |
< |
_lastModified = lastModified; |
47 |
< |
_logRef = logRef; |
48 |
< |
_logRef.write(this.toString(), Logger.SYSINIT, "created"); |
49 |
< |
String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date(getLastModified())); |
50 |
< |
_logRef.write(this.toString(), Logger.SYSMSG, "last modified - " + date); |
51 |
< |
} |
52 |
< |
|
53 |
< |
//---PUBLIC METHODS--- |
54 |
< |
|
55 |
< |
/** |
56 |
< |
* A wrapper for java.util.Properties.getProperty |
57 |
< |
* When given a key it returns the value of that key |
58 |
< |
* ie, key = value |
59 |
< |
* |
60 |
< |
* @param key the key the value of which is wanted |
61 |
< |
*/ |
62 |
< |
public String getProperty(String key) { |
63 |
< |
return _properties.getProperty(key); |
64 |
< |
} |
65 |
< |
|
66 |
< |
/** |
67 |
< |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
68 |
< |
* method to provide clean logging (every class should have this). |
69 |
< |
* |
70 |
< |
* @return the name of this class and its CVS revision |
71 |
< |
*/ |
72 |
< |
public String toString() { |
73 |
< |
return this.getClass().getName() + "(" + REVISION.substring(11, REVISION.length() - 2) + ")"; |
74 |
< |
} |
75 |
< |
|
76 |
< |
//---PRIVATE METHODS--- |
77 |
< |
|
78 |
< |
protected void finalize() throws Throwable { |
79 |
< |
_logRef.write(this.toString(), Logger.DEBUG, "finalized (ick, us english!)"); |
80 |
< |
} |
81 |
< |
|
82 |
< |
//---ACCESSOR/MUTATOR METHODS--- |
83 |
< |
|
84 |
< |
/** |
85 |
< |
* Returns the date stamp of the configuration file |
86 |
< |
* this object is using. |
87 |
< |
* |
88 |
< |
* @return the last modified time for the file |
89 |
< |
*/ |
90 |
< |
public long getLastModified() { |
91 |
< |
return _lastModified; |
92 |
< |
} |
93 |
< |
|
94 |
< |
//---ATTRIBUTES--- |
95 |
< |
|
96 |
< |
/** |
97 |
< |
* The properties object that this class provides a CORBA interface to |
98 |
< |
*/ |
99 |
< |
private Properties _properties = new Properties(); |
100 |
< |
|
101 |
< |
/** |
102 |
< |
* Reference to a Logger |
103 |
< |
*/ |
104 |
< |
private Logger _logRef; |
105 |
< |
|
106 |
< |
/** |
107 |
< |
* The date stamp of the configuration file |
108 |
< |
* this object is using |
109 |
< |
*/ |
110 |
< |
private long _lastModified; |
111 |
< |
|
112 |
< |
//---STATIC ATTRIBUTES--- |
113 |
< |
|
114 |
< |
} |
1 |
> |
//---PACKAGE DECLARATION--- |
2 |
> |
package uk.ac.ukc.iscream.core; |
3 |
> |
|
4 |
> |
//---IMPORTS--- |
5 |
> |
import uk.ac.ukc.iscream.util.*; |
6 |
> |
import uk.ac.ukc.iscream.componentmanager.*; |
7 |
> |
import java.util.Properties; |
8 |
> |
import java.util.Date; |
9 |
> |
import java.text.DateFormat; |
10 |
> |
|
11 |
> |
/** |
12 |
> |
* An implementation of the Configuration IDL |
13 |
> |
* This class allows i-scream modules to read and even |
14 |
> |
* set their configuration from a central location. |
15 |
> |
* |
16 |
> |
* When classes want their configuration, they contact |
17 |
> |
* the ConfigurationManager, which will locate their config, |
18 |
> |
* open it and pass it to a Configuration object which is |
19 |
> |
* then passed back to the calling class. |
20 |
> |
* |
21 |
> |
* Essentially this class behaves in a similar fashion |
22 |
> |
* to the java.util.Properties class. |
23 |
> |
* |
24 |
> |
* @author $Author$ |
25 |
> |
* @version $Id$ |
26 |
> |
*/ |
27 |
> |
class ConfigurationServant extends ConfigurationPOA { |
28 |
> |
|
29 |
> |
//---FINAL ATTRIBUTES--- |
30 |
> |
|
31 |
> |
/** |
32 |
> |
* The current CVS revision of this class |
33 |
> |
*/ |
34 |
> |
public final String REVISION = "$Revision$"; |
35 |
> |
|
36 |
> |
//---STATIC METHODS--- |
37 |
> |
|
38 |
> |
//---CONSTRUCTORS--- |
39 |
> |
|
40 |
> |
/** |
41 |
> |
* Creates a new ConfigurationServant taking a hook |
42 |
> |
* to a Properties object containing the configuration. |
43 |
> |
* |
44 |
> |
* @param properties a Properties object that contains the full properties for this configuration |
45 |
> |
* @param fileList the list of config files used to build this configuration |
46 |
> |
* @param lastModified the most recent last modified value for the file list |
47 |
> |
* @param logRef a reference to the logger system |
48 |
> |
*/ |
49 |
> |
ConfigurationServant(Properties properties, String fileList, long lastModified) { |
50 |
> |
// assign local variables |
51 |
> |
_properties = properties; |
52 |
> |
_lastModified = lastModified; |
53 |
> |
_fileList = fileList; |
54 |
> |
_logger.write(toString(), Logger.SYSINIT, "created"); |
55 |
> |
String date = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM).format(new Date(getLastModified())); |
56 |
> |
_logger.write(toString(), Logger.SYSMSG, "last modified - " + date); |
57 |
> |
_logger.write(toString(), Logger.DEBUG, "file list - " + _fileList); |
58 |
> |
} |
59 |
> |
|
60 |
> |
//---PUBLIC METHODS--- |
61 |
> |
|
62 |
> |
/** |
63 |
> |
* A wrapper for java.util.Properties.getProperty |
64 |
> |
* When given a key it returns the value of that key |
65 |
> |
* ie, key = value |
66 |
> |
* |
67 |
> |
* @param key the key the value of which is wanted |
68 |
> |
*/ |
69 |
> |
public String getProperty(String key) { |
70 |
> |
return _properties.getProperty(key); |
71 |
> |
} |
72 |
> |
|
73 |
> |
/** |
74 |
> |
* Overrides the {@link java.lang.Object#toString() Object.toString()} |
75 |
> |
* method to provide clean logging (every class should have this). |
76 |
> |
* |
77 |
> |
* This uses the uk.ac.ukc.iscream.util.FormatName class |
78 |
> |
* to format the toString() |
79 |
> |
* |
80 |
> |
* @return the name of this class and its CVS revision |
81 |
> |
*/ |
82 |
> |
public String toString() { |
83 |
> |
return FormatName.getName( |
84 |
> |
_name, |
85 |
> |
getClass().getName(), |
86 |
> |
REVISION); |
87 |
> |
} |
88 |
> |
|
89 |
> |
/** |
90 |
> |
* Unhooks this Configuration object from the ORB |
91 |
> |
*/ |
92 |
> |
public void disconnect() { |
93 |
> |
try { |
94 |
> |
byte[] oid = _refman.getRootPOA().servant_to_id(this); |
95 |
> |
_refman.getRootPOA().deactivate_object(oid); |
96 |
> |
} catch(Exception e) { |
97 |
> |
_logger.write(this.toString(), Logger.ERROR, "disconnect failed: "+e); |
98 |
> |
} |
99 |
> |
} |
100 |
> |
|
101 |
> |
|
102 |
> |
//---PRIVATE METHODS--- |
103 |
> |
|
104 |
> |
/** |
105 |
> |
* Overridden for debugging purposes |
106 |
> |
* to see when an instance of this class |
107 |
> |
* is destroyed |
108 |
> |
*/ |
109 |
> |
protected void finalize() throws Throwable { |
110 |
> |
_logger.write(this.toString(), Logger.DEBUG, "finalized"); |
111 |
> |
} |
112 |
> |
|
113 |
> |
//---ACCESSOR/MUTATOR METHODS--- |
114 |
> |
|
115 |
> |
/** |
116 |
> |
* Returns the date stamp of the configuration file |
117 |
> |
* this object is using. |
118 |
> |
* |
119 |
> |
* @return the last modified time for the file |
120 |
> |
*/ |
121 |
> |
public long getLastModified() { |
122 |
> |
return _lastModified; |
123 |
> |
} |
124 |
> |
|
125 |
> |
/** |
126 |
> |
* Returns the list of files used to build the Properties |
127 |
> |
* this object is using. |
128 |
> |
* |
129 |
> |
* @return the list of files |
130 |
> |
*/ |
131 |
> |
public String getFileList() { |
132 |
> |
return _fileList; |
133 |
> |
} |
134 |
> |
|
135 |
> |
//---ATTRIBUTES--- |
136 |
> |
|
137 |
> |
/** |
138 |
> |
* The properties object that this class provides a CORBA interface to |
139 |
> |
*/ |
140 |
> |
private Properties _properties = new Properties(); |
141 |
> |
|
142 |
> |
/** |
143 |
> |
* This holds a reference to the |
144 |
> |
* system logger that is being used. |
145 |
> |
*/ |
146 |
> |
private Logger _logger = ReferenceManager.getInstance().getLogger(); |
147 |
> |
|
148 |
> |
/** |
149 |
> |
* A reference to the reference manager in use |
150 |
> |
*/ |
151 |
> |
private ReferenceManager _refman = ReferenceManager.getInstance(); |
152 |
> |
|
153 |
> |
/** |
154 |
> |
* This is the friendly identifier of the |
155 |
> |
* component this class is running in. |
156 |
> |
* eg, a Filter may be called "filter1", |
157 |
> |
* If this class does not have an owning |
158 |
> |
* component, a name from the configuration |
159 |
> |
* can be placed here. This name could also |
160 |
> |
* be changed to null for utility classes. |
161 |
> |
*/ |
162 |
> |
private String _name = Core.NAME; |
163 |
> |
|
164 |
> |
/** |
165 |
> |
* The date stamp of the configuration file |
166 |
> |
* this object is using |
167 |
> |
*/ |
168 |
> |
private long _lastModified; |
169 |
> |
|
170 |
> |
/** |
171 |
> |
* The list of files that were used to build this configuration |
172 |
> |
*/ |
173 |
> |
private String _fileList; |
174 |
> |
|
175 |
> |
//---STATIC ATTRIBUTES--- |
176 |
> |
|
177 |
> |
} |