You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2009/10/10 13:50:59 UTC

svn commit: r823844 - in /felix/trunk/framework/src/main/java/org/apache/felix/framework/cache: DirectoryContent.java JarContent.java

Author: rickhall
Date: Sat Oct 10 11:50:59 2009
New Revision: 823844

URL: http://svn.apache.org/viewvc?rev=823844&view=rev
Log:
Modify native library caching so libraries are extracted into the same
directory if possible. (FELIX-1731)

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/DirectoryContent.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/JarContent.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/DirectoryContent.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/DirectoryContent.java?rev=823844&r1=823843&r2=823844&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/DirectoryContent.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/DirectoryContent.java Sat Oct 10 11:50:59 2009
@@ -37,7 +37,7 @@
     private final Object m_revisionLock;
     private final File m_rootDir;
     private final File m_dir;
-    private int m_libCount = 0;
+    private Map m_nativeLibMap;
 
     public DirectoryContent(Logger logger, Map configMap, Object revisionLock,
         File rootDir, File dir)
@@ -209,70 +209,74 @@
                 // Since native libraries cannot be shared, we must extract a
                 // separate copy per request, so use the request library counter
                 // as part of the extracted path.
+                if (m_nativeLibMap == null)
+                {
+                    m_nativeLibMap = new HashMap();
+                }
+                Integer libCount = (Integer) m_nativeLibMap.get(entryName);
+                // Either set or increment the library count.
+                libCount = (libCount == null) ? new Integer(0) : new Integer(libCount.intValue() + 1);
+                m_nativeLibMap.put(entryName, libCount);
                 File libFile = new File(
-                    libDir, Integer.toString(m_libCount) + File.separatorChar + entryName);
-                // Increment library request counter.
-                m_libCount++;
+                    libDir, libCount.toString() + File.separatorChar + entryName);
 
                 if (!BundleCache.getSecureAction().fileExists(libFile))
                 {
-                    if (!BundleCache.getSecureAction().fileExists(libFile.getParentFile()))
+                    if (!BundleCache.getSecureAction().fileExists(libFile.getParentFile())
+                        && !BundleCache.getSecureAction().mkdirs(libFile.getParentFile()))
+                    {
+                        m_logger.log(
+                            Logger.LOG_ERROR,
+                            "Unable to create library directory.");
+                    }
+                    else
                     {
-                        if (!BundleCache.getSecureAction().mkdirs(libFile.getParentFile()))
+                        InputStream is = null;
+
+                        try
+                        {
+                            is = new BufferedInputStream(
+                                new FileInputStream(entryFile),
+                                BundleCache.BUFSIZE);
+                            if (is == null)
+                            {
+                                throw new IOException("No input stream: " + entryName);
+                            }
+
+                            // Create the file.
+                            BundleCache.copyStreamToFile(is, libFile);
+
+                            // Perform exec permission command on extracted library
+                            // if one is configured.
+                            String command = (String) m_configMap.get(
+                                Constants.FRAMEWORK_EXECPERMISSION);
+                            if (command != null)
+                            {
+                                Properties props = new Properties();
+                                props.setProperty("abspath", libFile.toString());
+                                command = Util.substVars(command, "command", null, props);
+                                Process p = BundleCache.getSecureAction().exec(command);
+                                p.waitFor();
+                            }
+
+                            // Return the path to the extracted native library.
+                            result = BundleCache.getSecureAction().getAbsolutePath(libFile);
+                        }
+                        catch (Exception ex)
                         {
                             m_logger.log(
                                 Logger.LOG_ERROR,
-                                "Unable to create library directory.");
+                                "Extracting native library.", ex);
                         }
-                        else
+                        finally
                         {
-                            InputStream is = null;
-
                             try
                             {
-                                is = new BufferedInputStream(
-                                    new FileInputStream(entryFile),
-                                    BundleCache.BUFSIZE);
-                                if (is == null)
-                                {
-                                    throw new IOException("No input stream: " + entryName);
-                                }
-
-                                // Create the file.
-                                BundleCache.copyStreamToFile(is, libFile);
-
-                                // Perform exec permission command on extracted library
-                                // if one is configured.
-                                String command = (String) m_configMap.get(
-                                    Constants.FRAMEWORK_EXECPERMISSION);
-                                if (command != null)
-                                {
-                                    Properties props = new Properties();
-                                    props.setProperty("abspath", libFile.toString());
-                                    command = Util.substVars(command, "command", null, props);
-                                    Process p = BundleCache.getSecureAction().exec(command);
-                                    p.waitFor();
-                                }
-
-                                // Return the path to the extracted native library.
-                                result = BundleCache.getSecureAction().getAbsolutePath(libFile);
-                            }
-                            catch (Exception ex)
-                            {
-                                m_logger.log(
-                                    Logger.LOG_ERROR,
-                                    "Extracting native library.", ex);
+                                if (is != null) is.close();
                             }
-                            finally
+                            catch (IOException ex)
                             {
-                                try
-                                {
-                                    if (is != null) is.close();
-                                }
-                                catch (IOException ex)
-                                {
-                                    // Not much we can do.
-                                }
+                                // Not much we can do.
                             }
                         }
                     }

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/JarContent.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/JarContent.java?rev=823844&r1=823843&r2=823844&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/JarContent.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/cache/JarContent.java Sat Oct 10 11:50:59 2009
@@ -24,6 +24,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Enumeration;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
 import java.util.zip.ZipEntry;
@@ -47,7 +48,7 @@
     private final File m_file;
     private final JarFileX m_jarFile;
     private final boolean m_isJarFileOwner;
-    private int m_libCount = 0;
+    private Map m_nativeLibMap;
 
     public JarContent(Logger logger, Map configMap, Object revisionLock, File rootDir,
         File file, JarFileX jarFile)
@@ -297,83 +298,87 @@
                 // Since native libraries cannot be shared, we must extract a
                 // separate copy per request, so use the request library counter
                 // as part of the extracted path.
+                if (m_nativeLibMap == null)
+                {
+                    m_nativeLibMap = new HashMap();
+                }
+                Integer libCount = (Integer) m_nativeLibMap.get(entryName);
+                // Either set or increment the library count.
+                libCount = (libCount == null) ? new Integer(0) : new Integer(libCount.intValue() + 1);
+                m_nativeLibMap.put(entryName, libCount);
                 File libFile = new File(
-                    libDir, Integer.toString(m_libCount) + File.separatorChar + entryName);
-                // Increment library request counter.
-                m_libCount++;
+                    libDir, libCount.toString() + File.separatorChar + entryName);
 
                 if (!BundleCache.getSecureAction().fileExists(libFile))
                 {
-                    if (!BundleCache.getSecureAction().fileExists(libFile.getParentFile()))
+                    if (!BundleCache.getSecureAction().fileExists(libFile.getParentFile())
+                        && !BundleCache.getSecureAction().mkdirs(libFile.getParentFile()))
+                    {
+                        m_logger.log(
+                            Logger.LOG_ERROR,
+                            "Unable to create library directory.");
+                    }
+                    else
                     {
-                        if (!BundleCache.getSecureAction().mkdirs(libFile.getParentFile()))
+                        InputStream is = null;
+
+                        try
+                        {
+                            is = new BufferedInputStream(
+                                m_jarFile.getInputStream(ze),
+                                BundleCache.BUFSIZE);
+                            if (is == null)
+                            {
+                                throw new IOException("No input stream: " + entryName);
+                            }
+
+                            // Create the file.
+                            BundleCache.copyStreamToFile(is, libFile);
+
+                            // Perform exec permission command on extracted library
+                            // if one is configured.
+                            String command = (String) m_configMap.get(
+                                Constants.FRAMEWORK_EXECPERMISSION);
+                            if (command != null)
+                            {
+                                Properties props = new Properties();
+                                props.setProperty("abspath", libFile.toString());
+                                command = Util.substVars(command, "command", null, props);
+                                Process p = BundleCache.getSecureAction().exec(command);
+                                // We have to make sure we read stdout and stderr because
+                                // otherwise we will block on certain unbuffered os's
+                                // (like eg. windows)
+                                Thread stdOut = new Thread(
+                                    new DevNullRunnable(p.getInputStream()));
+                                Thread stdErr = new Thread(
+                                    new DevNullRunnable(p.getErrorStream()));
+                                stdOut.setDaemon(true);
+                                stdErr.setDaemon(true);
+                                stdOut.start();
+                                stdErr.start();
+                                p.waitFor();
+                                stdOut.join();
+                                stdErr.join();
+                            }
+
+                            // Return the path to the extracted native library.
+                            result = BundleCache.getSecureAction().getAbsolutePath(libFile);
+                        }
+                        catch (Exception ex)
                         {
                             m_logger.log(
                                 Logger.LOG_ERROR,
-                                "Unable to create library directory.");
+                                "Extracting native library.", ex);
                         }
-                        else
+                        finally
                         {
-                            InputStream is = null;
-
                             try
                             {
-                                is = new BufferedInputStream(
-                                    m_jarFile.getInputStream(ze),
-                                    BundleCache.BUFSIZE);
-                                if (is == null)
-                                {
-                                    throw new IOException("No input stream: " + entryName);
-                                }
-
-                                // Create the file.
-                                BundleCache.copyStreamToFile(is, libFile);
-
-                                // Perform exec permission command on extracted library
-                                // if one is configured.
-                                String command = (String) m_configMap.get(
-                                    Constants.FRAMEWORK_EXECPERMISSION);
-                                if (command != null)
-                                {
-                                    Properties props = new Properties();
-                                    props.setProperty("abspath", libFile.toString());
-                                    command = Util.substVars(command, "command", null, props);
-                                    Process p = BundleCache.getSecureAction().exec(command);
-                                    // We have to make sure we read stdout and stderr because
-                                    // otherwise we will block on certain unbuffered os's
-                                    // (like eg. windows)
-                                    Thread stdOut = new Thread(
-                                        new DevNullRunnable(p.getInputStream()));
-                                    Thread stdErr = new Thread(
-                                        new DevNullRunnable(p.getErrorStream()));
-                                    stdOut.setDaemon(true);
-                                    stdErr.setDaemon(true);
-                                    stdOut.start();
-                                    stdErr.start();
-                                    p.waitFor();
-                                    stdOut.join();
-                                    stdErr.join();
-                                }
-
-                                // Return the path to the extracted native library.
-                                result = BundleCache.getSecureAction().getAbsolutePath(libFile);
-                            }
-                            catch (Exception ex)
-                            {
-                                m_logger.log(
-                                    Logger.LOG_ERROR,
-                                    "Extracting native library.", ex);
+                                if (is != null) is.close();
                             }
-                            finally
+                            catch (IOException ex)
                             {
-                                try
-                                {
-                                    if (is != null) is.close();
-                                }
-                                catch (IOException ex)
-                                {
-                                    // Not much we can do.
-                                }
+                                // Not much we can do.
                             }
                         }
                     }