You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/04/15 13:41:48 UTC
svn commit: r765144 - in /commons/sandbox/runtime/trunk/src:
main/java/org/apache/commons/runtime/ test/org/apache/commons/runtime/
Author: mturk
Date: Wed Apr 15 11:41:48 2009
New Revision: 765144
URL: http://svn.apache.org/viewvc?rev=765144&view=rev
Log:
Add Properties class and default properties resource
Added:
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/DefaultProperties.properties (with props)
commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java (with props)
Modified:
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestOS.java
commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestProperties.java
Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/DefaultProperties.properties
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/DefaultProperties.properties?rev=765144&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/DefaultProperties.properties (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/DefaultProperties.properties Wed Apr 15 11:41:48 2009
@@ -0,0 +1,27 @@
+# -----------------------------------------------------------------------------
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+# -----------------------------------------------------------------------------
+# DefaultRuntime.properties
+#
+# Main Apache Commons Runtime properties file.
+#
+# -----------------------------------------------------------------------------
+
+# Indicates the caching policy for lookups on cpu object.
+# The TTL is number of milliseconds between two counter lookups.
+cpu.cache.ttl = 100
+
Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/DefaultProperties.properties
------------------------------------------------------------------------------
svn:eol-style = native
Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java?rev=765144&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java (added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java Wed Apr 15 11:41:48 2009
@@ -0,0 +1,95 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.runtime;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/** The Properties class is used to obtain the various
+ * Apache Commons Runtime settings. Their default values are
+ * specified inside DefaultProperties.properties file.
+ * @since Runtime 1.0
+ *
+ */
+public final class Properties {
+
+ private Properties() {
+ try {
+ String name = Properties.class.getPackage().getName() + ".DefaultProperties";
+ System.out.println("File is " + name);
+ bundle = ResourceBundle.getBundle(name);
+
+ } catch (MissingResourceException ex) {
+ System.out.println("Exception ");
+ // Ignore
+ }
+ }
+
+ private ResourceBundle bundle;
+ private static Properties instance;
+
+ static {
+ instance = new Properties();
+ if (instance != null) {
+ CPU_CACHE_TTL = getLong("cpu.cache.ttl");
+ }
+ }
+
+ private ResourceBundle getBundle()
+ {
+ return bundle;
+ }
+
+ private static String getString(String key)
+ {
+ if (instance.getBundle() != null) {
+ return instance.getBundle().getString(key);
+ }
+ else
+ return null;
+ }
+
+ private static int getInt(String key)
+ {
+ int rv = 0;
+ if (instance.getBundle() != null) {
+ try {
+ rv = Integer.parseInt(instance.getBundle().getString(key));
+ } catch (NumberFormatException ex) {
+ // Ignore
+ }
+ }
+ return rv;
+ }
+
+ private static long getLong(String key)
+ {
+ long rv = 0;
+ if (instance.getBundle() != null) {
+ try {
+ rv = Long.parseLong(instance.getBundle().getString(key));
+ } catch (NumberFormatException ex) {
+ // Ignore
+ }
+ }
+ return rv;
+ }
+
+ /** Interval in milliseconds for a Cpu data caching.
+ */
+ public static long CPU_CACHE_TTL;
+}
Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestOS.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestOS.java?rev=765144&r1=765143&r2=765144&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestOS.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestOS.java Wed Apr 15 11:41:48 2009
@@ -17,7 +17,6 @@
package org.apache.commons.runtime;
import java.lang.System;
-import java.util.Properties;
import junit.framework.*;
/**
Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestProperties.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestProperties.java?rev=765144&r1=765143&r2=765144&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestProperties.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestProperties.java Wed Apr 15 11:41:48 2009
@@ -44,5 +44,14 @@
property = p.getProperty("java.library.path");
assertNotNull("java.library.path ", property);
}
+
+ public void testDefaultProperties()
+ throws Exception
+ {
+ long l;
+ l = org.apache.commons.runtime.Properties.CPU_CACHE_TTL;
+ assertEquals("Value ", 100, l);
+
+ }
}