commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r817320 - in /commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime: Default.properties Library.java Loader.java Main.java Properties.java
Date Mon, 21 Sep 2009 17:00:39 GMT
Author: mturk
Date: Mon Sep 21 17:00:38 2009
New Revision: 817320

URL: http://svn.apache.org/viewvc?rev=817320&view=rev
Log:
Add auto loader

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Default.properties
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Library.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Loader.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Main.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Default.properties
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Default.properties?rev=817320&r1=817319&r2=817320&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Default.properties
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Default.properties
Mon Sep 21 17:00:38 2009
@@ -18,6 +18,8 @@
 # DefaultProperties.properties
 #
 # Main Apache Commons Runtime properties file.
+# Notice: Properties defined inside platform specific Default.properties file
+# take precedence over the values in this file.
 #
 # -----------------------------------------------------------------------------
 
@@ -35,3 +37,9 @@
 
 # Maximum number of opened OS descriptors
 os.open.max = 65536
+
+# Native library name
+# See platform/<os>/Default.properties for any additional libraries
+# that has to be loaded before this library
+#
+library.load = acr

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Library.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Library.java?rev=817320&r1=817319&r2=817320&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Library.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Library.java Mon
Sep 21 17:00:38 2009
@@ -111,12 +111,12 @@
             return true;
         }
         /* Step 1.
-         * Try to load from acr.boot.path
+         * Try to load from acr.library.path
          */
-        String boot = System.getProperty("acr.boot.path");
-        if (boot != null) {
+        String path = System.getProperty("acr.library.path");
+        if (path != null) {
             try {
-                File f = new File(boot, getSoName(libname));
+                File f = new File(path, getSoName(libname));
                 System.load(f.getPath());
                 return true;
             } catch (Throwable ex) {

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Loader.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Loader.java?rev=817320&r1=817319&r2=817320&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Loader.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Loader.java Mon
Sep 21 17:00:38 2009
@@ -98,7 +98,7 @@
     /**
      * Check if the any of the native libraries was loaded.
      *
-     * @return {@code true} if the one of the native libraries was
+     * @return {@code true} if one of the native libraries was
      *         loaded.
      */
     public static boolean isEmpty()
@@ -106,4 +106,50 @@
         return libs.isEmpty();
     }
 
+    /**
+     * Load all native libraries in proper order according
+     * to the rules specified in {@code Default.properties} files.
+     *
+     * @return {@code true} if the final native library was
+     *         loaded.
+     */
+    public static boolean loadNatives()
+    {
+        boolean rc = false;
+        if (Properties.NATIVE_LIBS != null) {
+            for (int i = 0; i < Properties.NATIVE_LIBS.length; i++) {
+                boolean s = Library.load(Properties.NATIVE_LIBS[i]);
+                if (i == (Properties.NATIVE_LIBS.length - 1)) {
+                    /* Record the result of the last entry in the
+                     * list of the libraries
+                     */
+                    rc = s;
+                }
+            }
+        }
+        return rc;
+    }
+
+    /**
+     * Temporary debug method that dumps loaded natives to stdout.
+     */
+    @Deprecated
+    protected static void dump()
+    {
+        if (Properties.NATIVE_LIBS != null) {
+            System.out.println("Required libraries: ");
+            for (int i = 0; i < Properties.NATIVE_LIBS.length; i++) {
+                System.out.println("[" + i + "] " +  Properties.NATIVE_LIBS[i]);
+            }
+            System.out.println();
+            if (!isEmpty()) {
+                System.out.println("Loaded from classpath: ");
+                for (int i = 0; i < Properties.NATIVE_LIBS.length; i++) {
+                    System.out.println("[" + i + "] " +
+                                       libs.get(Properties.NATIVE_LIBS[i]).getPath());
+                }
+                System.out.println();
+            }
+        }
+    }
 }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Main.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Main.java?rev=817320&r1=817319&r2=817320&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Main.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Main.java Mon Sep
21 17:00:38 2009
@@ -43,7 +43,10 @@
     public static void main(String args[])
     {
         try {
-            Library.load("acr");
+            boolean loaded = Loader.loadNatives();
+            if (loaded) {
+                Loader.dump();
+            }
             boolean inited = Native.initialize();
             if (inited) {
                 System.out.println("Initialized Apache Commons Runtime : " +

Modified: 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=817320&r1=817319&r2=817320&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/Properties.java
Mon Sep 21 17:00:38 2009
@@ -16,6 +16,7 @@
 
 package org.apache.commons.runtime;
 
+import java.util.ArrayList;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
 
@@ -128,37 +129,66 @@
         return getL(key, 0L);
     }
 
+    /* Get string array with keys that are prefixed
+     * using key.0 ... key.N
+     */
+    private static String[] getA(String key)
+    {
+        ArrayList<String> a = new ArrayList<String>();
+        int i = 0;
+        while (true) {
+            String val = get(key + "." + i++);
+            if (val == null)
+                break;
+            else
+                a.add(val);
+        }
+        // Finally load the key itself
+        String val = get(key);
+        if (val != null)
+            a.add(val);
+        if (a.size() > 0) {
+            String [] s = new String[a.size()];
+            return a.toArray(s);
+        }
+        else
+            return null;
+    }
     //
     // Cpu info section.
     //
     /** Interval in milliseconds for a Cpu data caching.
      */
-    public static long          CPU_CACHE_TTL;
+    public static long           CPU_CACHE_TTL;
     /** Minimum interval of Cpu data cache.
      */
-    public static final long    CPU_CACHE_TTL_MIN = getL("cpu.cache.ttl.min", 1L);
+    public static final long     CPU_CACHE_TTL_MIN = getL("cpu.cache.ttl.min", 1L);
 
     //
     // File system section.
     //
     /** Maximum number of opened OS descriptors.
      */
-    public static final int     OS_OPEN_MAX   = getI("os.open.max");
+    public static final int      OS_OPEN_MAX   = getI("os.open.max");
 
     //
     // Version info section.
     //
     /** Major version of the runtime library
      */
-    public static final int     VERSION_MAJOR = getI("runtime.version.major");
+    public static final int      VERSION_MAJOR = getI("runtime.version.major");
     /** Minor version of the runtime library
      */
-    public static final int     VERSION_MINOR = getI("runtime.version.minor");
+    public static final int      VERSION_MINOR = getI("runtime.version.minor");
     /** Patch version of the runtime library
      */
-    public static final int     VERSION_PATCH = getI("runtime.version.patch");
+    public static final int      VERSION_PATCH = getI("runtime.version.patch");
     /** Product name of the runtime library
      */
-    public static final String  VERSION_PNAME = getS("runtime.version.pname");
+    public static final String   VERSION_PNAME = getS("runtime.version.pname");
+
+    /** List of the native libraries to load.
+     */
+    public static final String[] NATIVE_LIBS   = getA("library.load");
 
 }



Mime
View raw message