camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggrzy...@apache.org
Subject [2/3] camel git commit: [CAMEL-11427] Provide camel-leveldb-java feature that uses non-native leveldb library
Date Tue, 20 Jun 2017 07:51:12 GMT
[CAMEL-11427] Provide camel-leveldb-java feature that uses non-native leveldb library

(cherry picked from commit 75498ab1ef70bb3694b84647f2e9d23d43268f9b)


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5e679431
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5e679431
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5e679431

Branch: refs/heads/camel-2.19.x
Commit: 5e679431094627981d8df55beb54b9f8998e0d1e
Parents: 3d33970
Author: Grzegorz Grzybek <gr.grzybek@gmail.com>
Authored: Tue Jun 20 09:48:48 2017 +0200
Committer: Grzegorz Grzybek <gr.grzybek@gmail.com>
Committed: Tue Jun 20 09:49:39 2017 +0200

----------------------------------------------------------------------
 components/camel-leveldb/pom.xml                | 12 ++++++++++++
 .../leveldb/LevelDBAggregationRepository.java   | 14 ++++++++++++--
 .../camel/component/leveldb/LevelDBFile.java    | 20 ++++++++++++++++++--
 parent/pom.xml                                  |  2 ++
 .../features/src/main/resources/features.xml    |  7 +++++++
 5 files changed, 51 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5e679431/components/camel-leveldb/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-leveldb/pom.xml b/components/camel-leveldb/pom.xml
index e1ce56d..5678155 100644
--- a/components/camel-leveldb/pom.xml
+++ b/components/camel-leveldb/pom.xml
@@ -36,6 +36,13 @@
         <title>LevelDB</title>
 
         <camel.osgi.export.pkg>org.apache.camel.component.leveldb.*</camel.osgi.export.pkg>
+        <camel.osgi.import.pkg>
+            *,
+            org.fusesource.leveldbjni;resolution:=optional,
+            org.iq80.leveldb;resolution:=optional,
+            org.iq80.leveldb.impl;resolution:=optional
+        </camel.osgi.import.pkg>
+        <leveldb-version>0.9</leveldb-version>
     </properties>
 
     <dependencies>
@@ -51,6 +58,11 @@
             <version>${leveldbjni-version}</version>
         </dependency>
         <dependency>
+            <groupId>org.iq80.leveldb</groupId>
+            <artifactId>leveldb</artifactId>
+            <version>${leveldb-version}</version>
+        </dependency>
+        <dependency>
             <groupId>org.fusesource.hawtbuf</groupId>
             <artifactId>hawtbuf</artifactId>
             <version>${hawtbuf-version}</version>

http://git-wip-us.apache.org/repos/asf/camel/blob/5e679431/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBAggregationRepository.java
----------------------------------------------------------------------
diff --git a/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBAggregationRepository.java
b/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBAggregationRepository.java
index 2c8bf5d..eea1ad2 100644
--- a/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBAggregationRepository.java
+++ b/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBAggregationRepository.java
@@ -36,8 +36,6 @@ import org.iq80.leveldb.WriteBatch;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.fusesource.leveldbjni.JniDBFactory.asString;
-
 /**
  * An instance of {@link org.apache.camel.spi.AggregationRepository} which is backed by a
{@link LevelDBFile}.
  */
@@ -441,4 +439,16 @@ public class LevelDBAggregationRepository extends ServiceSupport implements
Reco
         }
     }
 
+    public static String asString(byte[] value) {
+        if (value == null) {
+            return null;
+        } else {
+            try {
+                return new String(value, "UTF-8");
+            } catch (UnsupportedEncodingException var2) {
+                throw new RuntimeException(var2);
+            }
+        }
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/5e679431/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBFile.java
----------------------------------------------------------------------
diff --git a/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBFile.java
b/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBFile.java
index 05fbf62..6a86a73 100644
--- a/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBFile.java
+++ b/components/camel-leveldb/src/main/java/org/apache/camel/component/leveldb/LevelDBFile.java
@@ -23,13 +23,12 @@ import org.apache.camel.Service;
 import org.apache.camel.util.IOHelper;
 import org.iq80.leveldb.CompressionType;
 import org.iq80.leveldb.DB;
+import org.iq80.leveldb.DBFactory;
 import org.iq80.leveldb.Options;
 import org.iq80.leveldb.WriteOptions;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static org.fusesource.leveldbjni.JniDBFactory.factory;
-
 /**
  * Manages access to a shared <a href="https://github.com/fusesource/leveldbjni/">LevelDB</a>
file.
  * <p/>
@@ -172,12 +171,29 @@ public class LevelDBFile implements Service {
         options.createIfMissing(true);
         try {
             getFile().getParentFile().mkdirs();
+            DBFactory factory = getFactory();
             db = factory.open(getFile(), options);
         } catch (IOException ioe) {
             throw new RuntimeException("Error opening LevelDB with file " + getFile(), ioe);
         }
     }
 
+    private DBFactory getFactory() {
+        String[] classNames = new String[] {
+                "org.fusesource.leveldbjni.JniDBFactory",
+                "org.iq80.leveldb.impl.Iq80DBFactory"
+        };
+        for (String cn : classNames) {
+            try {
+                Class<?> clz = getClass().getClassLoader().loadClass(cn);
+                return (DBFactory) clz.newInstance();
+            } catch (Exception e) {
+                LOG.warn(e.getMessage(), e);
+            }
+        }
+        throw new IllegalStateException("Can't find implementation of org.iq80.leveldb.DBFactory");
+    }
+
     public void stop() {
         File file = getFile();
 

http://git-wip-us.apache.org/repos/asf/camel/blob/5e679431/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index d511be0..881f572 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -408,6 +408,8 @@
     <kubernetes-model-version>1.0.72</kubernetes-model-version>
     <kxml2-bundle-version>2.3.0_3</kxml2-bundle-version>
     <leveldbjni-version>1.8</leveldbjni-version>
+    <leveldb-api-version>0.9</leveldb-api-version>
+    <leveldb-version>0.9</leveldb-version>
     <libphonenumber-version>8.3.3</libphonenumber-version>
     <libphonenumber-bundle-version>8.3.3_1</libphonenumber-bundle-version>
     <!-- virtual dependency only used by Eclipse m2e -->

http://git-wip-us.apache.org/repos/asf/camel/blob/5e679431/platforms/karaf/features/src/main/resources/features.xml
----------------------------------------------------------------------
diff --git a/platforms/karaf/features/src/main/resources/features.xml b/platforms/karaf/features/src/main/resources/features.xml
index 4992c69..51eb616 100644
--- a/platforms/karaf/features/src/main/resources/features.xml
+++ b/platforms/karaf/features/src/main/resources/features.xml
@@ -1206,6 +1206,13 @@
     <bundle dependency='true'>mvn:org.fusesource.hawtbuf/hawtbuf/${hawtbuf-version}</bundle>
     <bundle>mvn:org.apache.camel/camel-leveldb/${project.version}</bundle>
   </feature>
+  <feature name='camel-leveldb-java' version='${project.version}' resolver='(obr)' start-level='50'>
+    <feature version='${project.version}'>camel-core</feature>
+    <bundle dependency='true'>wrap:mvn:org.iq80.leveldb/leveldb-api/${leveldb-api-version}$Bundle-Version=${leveldb-api-version}&amp;Export-Package=*;-noimport:=true;version="${leveldb-api-version}"</bundle>
+    <bundle dependency='true'>wrap:mvn:org.iq80.leveldb/leveldb/${leveldb-version}$Bundle-Version=${leveldb-version}&amp;Export-Package=*;-noimport:=true;version="${leveldb-version}"</bundle>
+    <bundle dependency='true'>mvn:org.fusesource.hawtbuf/hawtbuf/${hawtbuf-version}</bundle>
+    <bundle>mvn:org.apache.camel/camel-leveldb/${project.version}</bundle>
+  </feature>
   <feature name='camel-lucene' version='${project.version}' resolver='(obr)' start-level='50'>
     <feature version='${project.version}'>camel-core</feature>
     <bundle dependency='true'>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.lucene/${lucene-bundle-version}</bundle>


Mime
View raw message