ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/i-scream/projects/cms/source/server/uk/org/iscream/cms/server/core/ConfigurationServant.java
(Generate patch)

Comparing projects/cms/source/server/uk/org/iscream/cms/server/core/ConfigurationServant.java (file contents):
Revision 1.10 by ajm, Mon Nov 20 17:11:44 2000 UTC vs.
Revision 1.21 by tdb, Sat May 18 18:16:01 2002 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines