Source Code Cross Referenced for ReconfiguratorProp.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » management » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.management 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * Initial developer(s): Adriana Danes
022:         * Contributor(s):
023:         *
024:         * --------------------------------------------------------------------------
025:         * $Id: ReconfiguratorProp.java 6661 2005-04-28 08:43:27Z benoitf $
026:         * --------------------------------------------------------------------------
027:         */
028:
029:        package org.objectweb.jonas.management;
030:
031:        // general Java imports
032:        import java.io.FileNotFoundException;
033:        import java.io.FileOutputStream;
034:        import java.io.IOException;
035:        import java.util.Enumeration;
036:        import java.util.Properties;
037:        import java.util.StringTokenizer;
038:
039:        import org.objectweb.util.monolog.api.BasicLevel;
040:
041:        /**
042:         * This class allows for persistent reconfiguration of a JOnAS service or of a JOnAS resource
043:         * being configured by a .properties file.
044:         * @author Adriana Danes
045:         */
046:        public class ReconfiguratorProp extends AbsReconfigurator {
047:
048:            /**
049:             * Initial configuration values, than saved reconfigured values
050:             */
051:            private Properties stableConfig;
052:
053:            /**
054:             * Reconfigured values (non yet saved)
055:             */
056:            private Properties currentConfig;
057:
058:            /**
059:             * Construct a reconfigurator for a JOnAS service or a JOnAS resource
060:             * @param name the name of the .properties configuration file to be updated. It may be 'jonas.properties' if the Reconfigurator
061:             * is associated to a JOnAS service, or a 'resource.properties' if the Reconfigurator is associated to a
062:             * data source or a mail factory.
063:             * @param conf the initial content of the .properties configuration file
064:             */
065:            public ReconfiguratorProp(String name, String configFileName,
066:                    Properties config) {
067:                super (name, configFileName);
068:                stableConfig = config;
069:                currentConfig = new Properties();
070:            }
071:
072:            /**
073:             * Updates the configuration file
074:             * @param key the modified property name
075:             * @param value the new value
076:             * @param sequence the sequence number of management notification producing the update
077:             */
078:            public void updateConfig(String key, String value, long sequence) {
079:                if (sequence > lastSequence) {
080:                    currentConfig.setProperty(key, value);
081:                    lastSequence = sequence;
082:                    if (logger.isLoggable(BasicLevel.DEBUG)) {
083:                        logger.log(BasicLevel.DEBUG, "- " + sequence
084:                                + " - Recufigured property to update " + key
085:                                + " with value : " + value);
086:                    }
087:                } else {
088:                    logger.log(BasicLevel.WARN,
089:                            "Received out of order reconfiguration message !");
090:                    logger.log(BasicLevel.WARN,
091:                            "Reconfiguration value for property " + key + " : "
092:                                    + value + " lost!");
093:                }
094:            }
095:
096:            /**
097:             * Updates the configuration file
098:             * @param key the modified property name
099:             * @param value the new value
100:             * @param add if true, the value has to be appended to the old value, if false, it has to be removed from the old value
101:             * @param sequence the sequence number of management notification producing the update
102:             */
103:            void updateConfig(String key, String value, boolean add,
104:                    long sequence) {
105:                if (sequence > lastSequence) {
106:                    String oldValue = currentConfig.getProperty(key);
107:                    if (oldValue == null)
108:                        oldValue = stableConfig.getProperty(key);
109:                    if (logger.isLoggable(BasicLevel.DEBUG)) {
110:                        logger.log(BasicLevel.DEBUG, "- " + sequence
111:                                + " - Recufigured property to update " + key
112:                                + " having value : " + oldValue);
113:                    }
114:                    String newValue = updateValue(oldValue, value, add);
115:                    currentConfig.setProperty(key, newValue);
116:                    lastSequence = sequence;
117:                    if (logger.isLoggable(BasicLevel.DEBUG)) {
118:                        logger.log(BasicLevel.DEBUG, "- " + sequence
119:                                + " - Updated property " + key
120:                                + " with value : " + newValue);
121:                    }
122:                } else {
123:                    logger.log(BasicLevel.WARN,
124:                            "Received out of order reconfiguration message !");
125:                    logger.log(BasicLevel.WARN,
126:                            "Reconfiguration value for property " + key + " : "
127:                                    + value + " lost!");
128:                }
129:            }
130:
131:            /**
132:             * Updates the configuration file
133:             * @param props set of modified properties with their associated values
134:             * @param sequence the sequence number of management notification producing the update
135:             */
136:            void updateConfig(Properties props, long sequence) {
137:                if (sequence > lastSequence) {
138:                    for (Enumeration pNames = props.propertyNames(); pNames
139:                            .hasMoreElements();) {
140:                        String aName = (String) pNames.nextElement();
141:                        String aValue = (String) props.getProperty(aName);
142:                        if (aValue != null) {
143:                            currentConfig.setProperty(aName, aValue);
144:                            if (logger.isLoggable(BasicLevel.DEBUG)) {
145:                                logger.log(BasicLevel.DEBUG, "- " + sequence
146:                                        + " - Updated property " + aName
147:                                        + " with value : " + aValue);
148:                            }
149:                        }
150:                    }
151:                    lastSequence = sequence;
152:                } else {
153:                    logger.log(BasicLevel.WARN,
154:                            "Received out of order reconfiguration message !");
155:                }
156:            }
157:
158:            String updateValue(String oldValue, String value, boolean add) {
159:                value = value.trim();
160:                oldValue = oldValue.trim();
161:                String returnValue;
162:                if (add) {
163:                    returnValue = new String(oldValue);
164:                    returnValue = returnValue + ',' + value;
165:                } else {
166:                    if (logger.isLoggable(BasicLevel.DEBUG)) {
167:                        logger.log(BasicLevel.DEBUG, "Remove " + value
168:                                + " from " + oldValue);
169:                    }
170:                    returnValue = new String();
171:                    boolean firstToken = true;
172:                    StringTokenizer st = new StringTokenizer(oldValue, ",");
173:                    while (st.hasMoreTokens()) {
174:                        String token = st.nextToken().trim();
175:                        if (!token.equals(value)) {
176:                            // add the token
177:                            if (firstToken) {
178:                                returnValue = new String(token);
179:                                firstToken = false;
180:                            } else {
181:                                returnValue = returnValue + ',' + token;
182:                            }
183:                        }
184:                    }
185:                }
186:                return returnValue;
187:            }
188:
189:            /**
190:             * Saves the updated configuration
191:             * @param sequence the sequence number of management notification producing the save (in fact store) operation
192:             */
193:            public void saveConfig(long sequence) throws ReconfigException {
194:                if (logger.isLoggable(BasicLevel.DEBUG)) {
195:                    logger.log(BasicLevel.DEBUG, "");
196:                }
197:                if (sequence > lastSequence) {
198:                    // Update stableConfig with properties in currentConfig
199:                    for (Enumeration props = currentConfig.keys(); props
200:                            .hasMoreElements();) {
201:                        String reconfiguredProp = (String) props.nextElement();
202:                        String reconfiguredPropValue = currentConfig
203:                                .getProperty(reconfiguredProp);
204:                        stableConfig.setProperty(reconfiguredProp,
205:                                reconfiguredPropValue);
206:                    }
207:                    try {
208:                        // Store stableConfig
209:                        FileOutputStream fo = new FileOutputStream(
210:                                configFileName);
211:                        stableConfig.store(fo, "Saved configuration file at ");
212:                        fo.close();
213:                        lastSequence = sequence;
214:                        if (logger.isLoggable(BasicLevel.DEBUG)) {
215:                            logger.log(BasicLevel.DEBUG, "Configuration file "
216:                                    + configFileName + " updated");
217:                        }
218:                    } catch (FileNotFoundException e) {
219:                        throw new ReconfigException(
220:                                "Cant' save configuration file: "
221:                                        + e.toString());
222:                    } catch (IOException ioe) {
223:                        throw new ReconfigException(
224:                                "Cant' save configuration file: "
225:                                        + ioe.toString());
226:                    }
227:                } else {
228:                    logger.log(BasicLevel.WARN,
229:                            "Received out of order save reconfiguration message for "
230:                                    + name + " !");
231:                    logger.log(BasicLevel.WARN, "Can not save !!");
232:                    logger.log(BasicLevel.WARN,
233:                            "Please reconfigure and than save !!");
234:                    currentConfig = new Properties();
235:                }
236:            }
237:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.