Source Code Cross Referenced for EnvironmentMutableConfig.java in  » JMX » je » com » sleepycat » je » 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 » JMX » je » com.sleepycat.je 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*-
002:         * See the file LICENSE for redistribution information.
003:         *
004:         * Copyright (c) 2002,2008 Oracle.  All rights reserved.
005:         *
006:         * $Id: EnvironmentMutableConfig.java,v 1.29.2.3 2008/01/07 15:14:08 cwl Exp $
007:         */
008:
009:        package com.sleepycat.je;
010:
011:        import java.util.Enumeration;
012:        import java.util.Iterator;
013:        import java.util.Properties;
014:
015:        import com.sleepycat.je.config.ConfigParam;
016:        import com.sleepycat.je.config.EnvironmentParams;
017:        import com.sleepycat.je.dbi.DbConfigManager;
018:        import com.sleepycat.je.dbi.EnvironmentImpl;
019:
020:        /**
021:         * Javadoc for this public class is generated
022:         * via the doc templates in the doc_src directory.
023:         */
024:        public class EnvironmentMutableConfig implements  Cloneable {
025:
026:            /*
027:             * Change copyHandlePropsTo and Environment.copyToHandleConfig
028:             * when adding fields here.
029:             */
030:            private boolean txnNoSync = false;
031:            private boolean txnWriteNoSync = false;
032:
033:            /*
034:             * Cache size is a category of property that is calculated within the
035:             * environment.  It is only supplied when returning the cache size to the
036:             * application and never used internally; internal code directly checks
037:             * with the MemoryBudget class;
038:             */
039:            protected long cacheSize;
040:
041:            /**
042:             * Note that in the implementation we choose not to extend Properties
043:             * in order to keep the configuration type safe.
044:             */
045:            protected Properties props;
046:
047:            /**
048:             * For unit testing, to prevent loading of je.properties.
049:             */
050:            private boolean loadPropertyFile = true;
051:
052:            /**
053:             * Internal boolean that says whether or not to validate params.  Setting
054:             * it to false means that parameter value validatation won't be performed
055:             * during setVal() calls.  Only should be set to false by unit tests using
056:             * DbInternal.
057:             */
058:            boolean validateParams = true;
059:
060:            /**
061:             * Javadoc for this public method is generated via
062:             * the doc templates in the doc_src directory.
063:             */
064:            public EnvironmentMutableConfig() {
065:                props = new Properties();
066:            }
067:
068:            /**
069:             * Used by EnvironmentConfig to construct from properties.
070:             */
071:            EnvironmentMutableConfig(Properties properties)
072:                    throws IllegalArgumentException {
073:
074:                DbConfigManager.validateProperties(properties, false, // forReplication
075:                        this .getClass().getName());
076:                /* For safety, copy the passed in properties. */
077:                props = new Properties();
078:                props.putAll(properties);
079:            }
080:
081:            /**
082:             * Javadoc for this public method is generated via
083:             * the doc templates in the doc_src directory.
084:             */
085:            public void setTxnNoSync(boolean noSync) {
086:                txnNoSync = noSync;
087:            }
088:
089:            /**
090:             * Javadoc for this public method is generated via
091:             * the doc templates in the doc_src directory.
092:             */
093:            public boolean getTxnNoSync() {
094:                return txnNoSync;
095:            }
096:
097:            /**
098:             * Javadoc for this public method is generated via
099:             * the doc templates in the doc_src directory.
100:             */
101:            public void setTxnWriteNoSync(boolean writeNoSync) {
102:                txnWriteNoSync = writeNoSync;
103:            }
104:
105:            /**
106:             * Javadoc for this public method is generated via
107:             * the doc templates in the doc_src directory.
108:             */
109:            public boolean getTxnWriteNoSync() {
110:                return txnWriteNoSync;
111:            }
112:
113:            /**
114:             * Javadoc for this public method is generated via
115:             * the doc templates in the doc_src directory.
116:             */
117:            public void setCacheSize(long totalBytes)
118:                    throws IllegalArgumentException {
119:
120:                DbConfigManager.setVal(props, EnvironmentParams.MAX_MEMORY,
121:                        Long.toString(totalBytes), validateParams);
122:            }
123:
124:            /**
125:             * Javadoc for this public method is generated via
126:             * the doc templates in the doc_src directory.
127:             */
128:            public long getCacheSize() {
129:
130:                /*
131:                 * CacheSize is filled in from the EnvironmentImpl by way of
132:                 * copyHandleProps.
133:                 */
134:                return cacheSize;
135:            }
136:
137:            /**
138:             * Javadoc for this public method is generated via
139:             * the doc templates in the doc_src directory.
140:             */
141:            public void setCachePercent(int percent)
142:                    throws IllegalArgumentException {
143:
144:                DbConfigManager.setVal(props,
145:                        EnvironmentParams.MAX_MEMORY_PERCENT, Integer
146:                                .toString(percent), validateParams);
147:            }
148:
149:            /**
150:             * Javadoc for this public method is generated via
151:             * the doc templates in the doc_src directory.
152:             */
153:            public int getCachePercent() {
154:
155:                String val = DbConfigManager.getVal(props,
156:                        EnvironmentParams.MAX_MEMORY_PERCENT);
157:                try {
158:                    return Integer.parseInt(val);
159:                } catch (NumberFormatException e) {
160:                    throw new IllegalArgumentException(
161:                            "Cache percent is not a valid integer: "
162:                                    + e.getMessage());
163:                }
164:            }
165:
166:            /**
167:             * Javadoc for this public method is generated via
168:             * the doc templates in the doc_src directory.
169:             */
170:            public void setConfigParam(String paramName, String value)
171:                    throws IllegalArgumentException {
172:
173:                DbConfigManager.setConfigParam(props, paramName, value, true, /* require mutability. */
174:                validateParams, false /* forReplication */);
175:            }
176:
177:            /**
178:             * Javadoc for this public method is generated via
179:             * the doc templates in the doc_src directory.
180:             */
181:            public String getConfigParam(String paramName)
182:                    throws IllegalArgumentException {
183:
184:                return DbConfigManager.getConfigParam(props, paramName);
185:            }
186:
187:            /*
188:             * Helpers
189:             */
190:            void setValidateParams(boolean validateParams) {
191:                this .validateParams = validateParams;
192:            }
193:
194:            /**
195:             * Check that the immutable values in the environment config used to open
196:             * an environment match those in the config object saved by the underlying
197:             * shared EnvironmentImpl.
198:             */
199:            void checkImmutablePropsForEquality(
200:                    EnvironmentMutableConfig passedConfig)
201:                    throws IllegalArgumentException {
202:
203:                Properties passedProps = passedConfig.props;
204:                Iterator iter = EnvironmentParams.SUPPORTED_PARAMS.keySet()
205:                        .iterator();
206:                while (iter.hasNext()) {
207:                    String paramName = (String) iter.next();
208:                    ConfigParam param = (ConfigParam) EnvironmentParams.SUPPORTED_PARAMS
209:                            .get(paramName);
210:                    assert param != null;
211:                    if (!param.isMutable()) {
212:                        String paramVal = props.getProperty(paramName);
213:                        String useParamVal = passedProps.getProperty(paramName);
214:                        if ((paramVal != null) ? (!paramVal.equals(useParamVal))
215:                                : (useParamVal != null)) {
216:                            throw new IllegalArgumentException(paramName
217:                                    + " is set to " + useParamVal
218:                                    + " in the config parameter"
219:                                    + " which is incompatible"
220:                                    + " with the value of " + paramVal
221:                                    + " in the" + " underlying environment");
222:                        }
223:                    }
224:                }
225:            }
226:
227:            /**
228:             * Overrides Object.clone() to clone all properties, used by this class and
229:             * EnvironmentConfig.
230:             */
231:            protected Object clone() throws CloneNotSupportedException {
232:
233:                EnvironmentMutableConfig copy = (EnvironmentMutableConfig) super 
234:                        .clone();
235:                copy.props = (Properties) props.clone();
236:                return copy;
237:            }
238:
239:            /**
240:             * Used by Environment to create a copy of the application
241:             * supplied configuration. Done this way to provide non-public cloning.
242:             */
243:            EnvironmentMutableConfig cloneMutableConfig() {
244:                try {
245:                    EnvironmentMutableConfig copy = (EnvironmentMutableConfig) clone();
246:                    /* Remove all immutable properties. */
247:                    copy.clearImmutableProps();
248:                    return copy;
249:                } catch (CloneNotSupportedException willNeverOccur) {
250:                    return null;
251:                }
252:            }
253:
254:            /**
255:             * Copies the per-handle properties of this object to the given config
256:             * object.
257:             */
258:            void copyHandlePropsTo(EnvironmentMutableConfig other) {
259:                other.txnNoSync = txnNoSync;
260:                other.txnWriteNoSync = txnWriteNoSync;
261:            }
262:
263:            /**
264:             * Copies all mutable props to the given config object.
265:             */
266:            void copyMutablePropsTo(EnvironmentMutableConfig toConfig) {
267:
268:                Properties toProps = toConfig.props;
269:                Enumeration propNames = props.propertyNames();
270:                while (propNames.hasMoreElements()) {
271:                    String paramName = (String) propNames.nextElement();
272:                    ConfigParam param = (ConfigParam) EnvironmentParams.SUPPORTED_PARAMS
273:                            .get(paramName);
274:                    assert param != null;
275:                    if (param.isMutable()) {
276:                        String newVal = props.getProperty(paramName);
277:                        toProps.setProperty(paramName, newVal);
278:                    }
279:                }
280:            }
281:
282:            /**
283:             * Fill in the properties calculated by the environment to the given
284:             * config object.
285:             */
286:            void fillInEnvironmentGeneratedProps(EnvironmentImpl envImpl) {
287:                cacheSize = envImpl.getMemoryBudget().getMaxMemory();
288:            }
289:
290:            /**
291:             * Removes all immutable props.
292:             */
293:            private void clearImmutableProps() {
294:                Enumeration propNames = props.propertyNames();
295:                while (propNames.hasMoreElements()) {
296:                    String paramName = (String) propNames.nextElement();
297:                    ConfigParam param = (ConfigParam) EnvironmentParams.SUPPORTED_PARAMS
298:                            .get(paramName);
299:                    assert param != null;
300:                    if (!param.isMutable()) {
301:                        props.remove(paramName);
302:                    }
303:                }
304:            }
305:
306:            Properties getProps() {
307:                return props;
308:            }
309:
310:            /**
311:             * For unit testing, to prevent loading of je.properties.
312:             */
313:            void setLoadPropertyFile(boolean loadPropertyFile) {
314:                this .loadPropertyFile = loadPropertyFile;
315:            }
316:
317:            /**
318:             * For unit testing, to prevent loading of je.properties.
319:             */
320:            boolean getLoadPropertyFile() {
321:                return loadPropertyFile;
322:            }
323:
324:            /**
325:             * Testing support
326:             */
327:            int getNumExplicitlySetParams() {
328:                return props.size();
329:            }
330:
331:            public String toString() {
332:                return props.toString();
333:            }
334:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.