diff --git a/pom.xml b/pom.xml
index 3653d82..4f3a869 100755
--- a/pom.xml
+++ b/pom.xml
@@ -82,7 +82,6 @@
-
org.apache.maven.plugins
@@ -171,9 +170,10 @@
org.apache.felix
maven-bundle-plugin
- 2.3.4
+ 2.3.7
true
+ META-INF
${project.groupId}.${project.artifactId}
${pproject.name}
@@ -181,10 +181,58 @@
org.xerial.snappy.SnappyBundleActivator
org.xerial.snappy
org.osgi.framework;version="[1.5,2)"
+ lazy
+
+ org/xerial/snappy/native/Windows/amd64/snappyjava.dll;selection-filter="(&(osgi.arch=x86_64)(osgi.os=win32))",
+ org/xerial/snappy/native/Windows/x86/snappyjava.dll;selection-filter="(&(osgi.arch=x86)(osgi.os=win32))",
+ org/xerial/snappy/native/Mac/i386/libsnappyjava.jnilib;selection-filter="(&(osgi.arch=x86)(osgi.os=macosx))",
+ org/xerial/snappy/native/Mac/x86_64/libsnappyjava.jnilib;selection-filter="(&(osgi.arch=x86_64)(osgi.os=macosx))",
+ org/xerial/snappy/native/Linux/amd64/libsnappyjava.so;selection-filter="(&(osgi.arch=x86_64)(osgi.os=linux))",
+ org/xerial/snappy/native/Linux/i386/libsnappyjava.so;selection-filter="(&(osgi.arch=x86)(osgi.os=linux))",
+ org/xerial/snappy/native/Linux/arm/libsnappyjava.so;selection-filter="(&(osgi.arch=arm)(osgi.os=linux))"
+
+
+
+
+ bundle-manifest
+ process-classes
+
+ manifest
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+
+
+ true
+ META-INF/MANIFEST.MF
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-clean-plugin
+ 2.4.1
+
+ false
+
+
+ META-INF
+
+ MANIFEST.MF
+
+
+
+
+
+
maven-assembly-plugin
2.2.1
@@ -205,6 +253,7 @@
+
@@ -254,7 +303,6 @@
-
junit
@@ -285,5 +333,7 @@
jar
test
+
+
diff --git a/src/main/java/org/xerial/snappy/SnappyBundleActivator.java b/src/main/java/org/xerial/snappy/SnappyBundleActivator.java
index 5495160..f36a4f5 100755
--- a/src/main/java/org/xerial/snappy/SnappyBundleActivator.java
+++ b/src/main/java/org/xerial/snappy/SnappyBundleActivator.java
@@ -24,6 +24,9 @@
//--------------------------------------
package org.xerial.snappy;
+import java.util.jar.Manifest;
+
+import org.osgi.framework.Bundle;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
@@ -35,12 +38,23 @@ import org.osgi.framework.BundleContext;
*/
public class SnappyBundleActivator implements BundleActivator
{
- public void start(BundleContext context) throws Exception {
-
+ /**
+ * Name of the Snappy native library
+ */
+ public static final String LIBRARY_NAME = "snappyjava";
+
+ /**
+ * Make a call to {@link System#loadLibrary(String)} to load the native library which assumes
+ * that the library is available on the path based on this {@link Bundle}'s {@link Manifest}.
+ */
+ public void start(BundleContext context) throws Exception
+ {
+ System.loadLibrary(System.mapLibraryName(LIBRARY_NAME));
+ SnappyLoader.setApi(new SnappyNative());
}
- public void stop(BundleContext context) throws Exception {
-
+ public void stop(BundleContext context) throws Exception
+ {
+ SnappyLoader.setApi(null);
}
-
}
diff --git a/src/main/java/org/xerial/snappy/SnappyLoader.java b/src/main/java/org/xerial/snappy/SnappyLoader.java
index 9ec625f..99b0e7a 100755
--- a/src/main/java/org/xerial/snappy/SnappyLoader.java
+++ b/src/main/java/org/xerial/snappy/SnappyLoader.java
@@ -24,7 +24,13 @@
//--------------------------------------
package org.xerial.snappy;
-import java.io.*;
+import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
@@ -87,9 +93,19 @@ public class SnappyLoader
public static final String KEY_SNAPPY_USE_SYSTEMLIB = "org.xerial.snappy.use.systemlib";
public static final String KEY_SNAPPY_DISABLE_BUNDLED_LIBS = "org.xerial.snappy.disable.bundled.libs"; // Depreciated, but preserved for backward compatibility
- private static boolean isLoaded = false;
- private static Object api = null;
-
+ private static volatile boolean isLoaded = false;
+ private static volatile Object api = null;
+
+ /**
+ * Set the api instance.
+ *
+ * @param nativeCode
+ */
+ static synchronized void setApi(Object nativeCode)
+ {
+ api = nativeCode;
+ }
+
/**
* load system properties when configuration file of the name
* {@link #SNAPPY_SYSTEM_PROPERTIES_FILE} is found
@@ -200,8 +216,8 @@ public class SnappyLoader
*
* @return
*/
- static synchronized Object load() {
-
+ static synchronized Object load()
+ {
if (api != null)
return api;
@@ -216,7 +232,7 @@ public class SnappyLoader
isLoaded = true;
// Look up SnappyNative, injected to the root classloder, using reflection in order to avoid the initialization of SnappyNative class in this context class loader.
Object nativeCode = Class.forName("org.xerial.snappy.SnappyNative").newInstance();
- api = nativeCode;
+ setApi(nativeCode);
}
catch (Exception e) {
e.printStackTrace();