├── rocksdbjni
├── src
│ └── main
│ │ ├── resources
│ │ └── org
│ │ │ └── fusesource
│ │ │ └── rocksdbjni
│ │ │ └── version.txt
│ │ ├── native-package
│ │ ├── Makefile.win
│ │ ├── m4
│ │ │ ├── ltversion.m4
│ │ │ ├── custom.m4
│ │ │ ├── osx-universal.m4
│ │ │ ├── ltsugar.m4
│ │ │ ├── lt~obsolete.m4
│ │ │ └── jni.m4
│ │ ├── Makefile.am
│ │ ├── license.txt
│ │ ├── src
│ │ │ ├── config.h.in
│ │ │ ├── buffer.c
│ │ │ └── rocksdbjni.h
│ │ └── autotools
│ │ │ ├── ar-lib
│ │ │ └── missing
│ │ └── java
│ │ └── org
│ │ └── fusesource
│ │ └── rocksdbjni
│ │ ├── internal
│ │ ├── NativeSnapshot.java
│ │ ├── NativeCompressionType.java
│ │ ├── JniSnapshot.java
│ │ ├── NativeObject.java
│ │ ├── NativeWriteOptions.java
│ │ ├── JniWriteBatch.java
│ │ ├── NativeReadOptions.java
│ │ ├── NativeStatus.java
│ │ ├── NativeStdString.java
│ │ ├── NativeLogger.java
│ │ ├── NativeRange.java
│ │ ├── JniDBIterator.java
│ │ ├── NativeWriteBatch.java
│ │ ├── Util.java
│ │ ├── NativeSlice.java
│ │ ├── NativeComparator.java
│ │ ├── NativeIterator.java
│ │ ├── NativeOptions.java
│ │ ├── JniDB.java
│ │ └── NativeBuffer.java
│ │ └── JniDBFactory.java
└── pom.xml
├── rocksdbjni-all
├── src
│ └── main
│ │ ├── java
│ │ └── org
│ │ │ └── fusesource
│ │ │ └── rocksdbjni
│ │ │ └── All.java
│ │ └── descriptors
│ │ └── uber-sources.xml
└── pom.xml
├── .gitignore
├── changelog.md
├── release.properties
├── rocksdb.patch
├── license.txt
├── releasing.md
├── rocksdbjni-win64
└── pom.xml
├── rocksdbjni-win32
└── pom.xml
├── rocksdbjni-linux64
└── pom.xml
├── rocksdbjni-linux32
└── pom.xml
├── rocksdbjni-osx
└── pom.xml
├── readme.md
└── pom.xml
/rocksdbjni/src/main/resources/org/fusesource/rocksdbjni/version.txt:
--------------------------------------------------------------------------------
1 | ${project.version}
--------------------------------------------------------------------------------
/rocksdbjni-all/src/main/java/org/fusesource/rocksdbjni/All.java:
--------------------------------------------------------------------------------
1 | package org.fusesource.rocksdbjni;
2 |
3 | public class All {
4 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *~
2 | *.swp
3 | .idea
4 | .idea/*
5 | *.iml
6 | *.ipr
7 | *.iws
8 | target
9 | .DS_Store
10 | .project
11 | .classpath
12 | .settings
13 | eclipse-classes
14 |
--------------------------------------------------------------------------------
/changelog.md:
--------------------------------------------------------------------------------
1 | # [rocksdbjni](https://github.com/fusesource/rocksdbjni)
2 |
3 | ## [rocksdbjni 1.0][1_0], unreleased
4 | [1_0]: http://repo.fusesource.com/nexus/content/groups/public/org/fusesource/rocksdbjni/rocksdbjni/1.0
5 |
6 | * Initial Release
7 |
--------------------------------------------------------------------------------
/release.properties:
--------------------------------------------------------------------------------
1 | #release configuration
2 | #Mon May 13 09:09:05 EDT 2013
3 | scm.tagNameFormat=@{project.artifactId}-@{project.version}
4 | pushChanges=false
5 | scm.url=scm\:git\:git@github.com\:fusesource/rocksdbjni.git
6 | preparationGoals=clean install
7 | remoteTagging=true
8 | scm.commentPrefix=[maven-release-plugin]
9 | exec.additionalArguments=-Prelease -P download,download,swiftmq-client
10 | exec.snapshotReleasePluginAllowed=false
11 | completedPhase=create-backup-poms
12 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/native-package/Makefile.win:
--------------------------------------------------------------------------------
1 | CC ?= gcc
2 | CXX ?= g++
3 |
4 | JDK ?= /c/java/jdk7
5 | PLATFORM ?= win32
6 |
7 | CPPFLAGS = -I/usr/local/include -I$(JDK)/include -I$(JDK)/include/$(PLATFORM)
8 | LDFLAGS = -L/usr/local/lib
9 | SHARED_CFLAGS = -fPIC
10 |
11 | OBJS = src/rocksdbjni.o src/rocksdbjni_stats.o src/rocksdbjni_structs.o \
12 | src/buffer.o src/hawtjni.o
13 |
14 | .cpp.o:
15 | $(CXX) $(CPPFLAGS) $(SHARED_CFLAGS) -c $< -o $@
16 |
17 | .c.o:
18 | $(CC) $(CPPFLAGS) $(SHARED_CFLAGS) -c $< -o $@
19 |
20 | rocksdbjni.dll: $(OBJS) Makefile.win
21 | $(CC) -shared -o $@ -Wl,--kill-at $(OBJS) -lrocksdb $(LDFLAGS) -lstdc++
22 |
23 | clean:
24 | rm -f $(OBJS) *.dll
25 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/native-package/m4/ltversion.m4:
--------------------------------------------------------------------------------
1 | # ltversion.m4 -- version numbers -*- Autoconf -*-
2 | #
3 | # Copyright (C) 2004 Free Software Foundation, Inc.
4 | # Written by Scott James Remnant, 2004
5 | #
6 | # This file is free software; the Free Software Foundation gives
7 | # unlimited permission to copy and/or distribute it, with or without
8 | # modifications, as long as this notice is preserved.
9 |
10 | # @configure_input@
11 |
12 | # serial 3337 ltversion.m4
13 | # This file is part of GNU Libtool
14 |
15 | m4_define([LT_PACKAGE_VERSION], [2.4.2])
16 | m4_define([LT_PACKAGE_REVISION], [1.3337])
17 |
18 | AC_DEFUN([LTVERSION_VERSION],
19 | [macro_version='2.4.2'
20 | macro_revision='1.3337'
21 | _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?])
22 | _LT_DECL(, macro_revision, 0)
23 | ])
24 |
--------------------------------------------------------------------------------
/rocksdb.patch:
--------------------------------------------------------------------------------
1 | diff --git a/build_detect_platform b/build_detect_platform
2 | index 5801d20..517db04 100755
3 | --- a/build_detect_platform
4 | +++ b/build_detect_platform
5 | @@ -195,9 +195,9 @@ echo "CXX=$CXX" >> $OUTPUT
6 | echo "PLATFORM=$PLATFORM" >> $OUTPUT
7 | echo "PLATFORM_LDFLAGS=$PLATFORM_LDFLAGS" >> $OUTPUT
8 | echo "PLATFORM_LIBS=$PLATFORM_LIBS" >> $OUTPUT
9 | -echo "PLATFORM_CCFLAGS=$PLATFORM_CCFLAGS" >> $OUTPUT
10 | -echo "PLATFORM_CXXFLAGS=$PLATFORM_CXXFLAGS" >> $OUTPUT
11 | -echo "PLATFORM_SHARED_CFLAGS=$PLATFORM_SHARED_CFLAGS" >> $OUTPUT
12 | +echo "PLATFORM_CCFLAGS=$PLATFORM_CCFLAGS $PLATFORM_SHARED_CFLAGS" >> $OUTPUT
13 | +echo "PLATFORM_CXXFLAGS=$PLATFORM_CXXFLAGS $PLATFORM_SHARED_CFLAGS" >> $OUTPUT
14 | +echo "PLATFORM_SHARED_CFLAGS=" >> $OUTPUT
15 | echo "PLATFORM_SHARED_EXT=$PLATFORM_SHARED_EXT" >> $OUTPUT
16 | echo "PLATFORM_SHARED_LDFLAGS=$PLATFORM_SHARED_LDFLAGS" >> $OUTPUT
17 | echo "PLATFORM_SHARED_VERSIONED=$PLATFORM_SHARED_VERSIONED" >> $OUTPUT
18 | diff --git a/include/rocksdb/slice.h b/include/rocksdb/slice.h
19 | index 74ea8fa..135bbd7 100644
20 | --- a/include/rocksdb/slice.h
21 | +++ b/include/rocksdb/slice.h
22 | @@ -77,7 +77,6 @@ class Slice {
23 | (memcmp(data_, x.data_, x.size_) == 0));
24 | }
25 |
26 | - private:
27 | const char* data_;
28 | size_t size_;
29 |
30 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/native-package/Makefile.am:
--------------------------------------------------------------------------------
1 | # ---------------------------------------------------------------------------
2 | # Licensed to the Apache Software Foundation (ASF) under one or more
3 | # contributor license agreements. See the NOTICE file distributed with
4 | # this work for additional information regarding copyright ownership.
5 | # The ASF licenses this file to You under the Apache License, Version 2.0
6 | # (the "License"); you may not use this file except in compliance with
7 | # the License. You may obtain a copy of the License at
8 | #
9 | # http://www.apache.org/licenses/LICENSE-2.0
10 | #
11 | # Unless required by applicable law or agreed to in writing, software
12 | # distributed under the License is distributed on an "AS IS" BASIS,
13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | # See the License for the specific language governing permissions and
15 | # limitations under the License.
16 | # ---------------------------------------------------------------------------
17 |
18 | ACLOCAL_AMFLAGS = -I m4
19 |
20 | lib_LTLIBRARIES = librocksdbjni.la
21 | # librocksdbjni_la_CFLAGS =
22 | #librocksdbjni_la_LDFLAGS =
23 |
24 | librocksdbjni_la_SOURCES = src/rocksdbjni.cpp\
25 | src/rocksdbjni_stats.cpp\
26 | src/rocksdbjni_structs.cpp\
27 | src/buffer.c\
28 | src/hawtjni.c
29 |
--------------------------------------------------------------------------------
/rocksdbjni-all/src/main/descriptors/uber-sources.xml:
--------------------------------------------------------------------------------
1 |
2 |
18 |
19 | sources
20 |
21 | jar
22 |
23 | false
24 |
25 |
26 | /
27 | true
28 | true
29 |
30 | *:*:jar:sources
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/license.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2011 FuseSource Corp. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following disclaimer
11 | in the documentation and/or other materials provided with the
12 | distribution.
13 | * Neither the name of FuseSource Corp. nor the names of its
14 | contributors may be used to endorse or promote products derived from
15 | this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/native-package/license.txt:
--------------------------------------------------------------------------------
1 | Copyright (c) 2011 FuseSource Corp. All rights reserved.
2 |
3 | Redistribution and use in source and binary forms, with or without
4 | modification, are permitted provided that the following conditions are
5 | met:
6 |
7 | * Redistributions of source code must retain the above copyright
8 | notice, this list of conditions and the following disclaimer.
9 | * Redistributions in binary form must reproduce the above
10 | copyright notice, this list of conditions and the following disclaimer
11 | in the documentation and/or other materials provided with the
12 | distribution.
13 | * Neither the name of FuseSource Corp. nor the names of its
14 | contributors may be used to endorse or promote products derived from
15 | this software without specific prior written permission.
16 |
17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/native-package/src/config.h.in:
--------------------------------------------------------------------------------
1 | /* src/config.h.in. Generated from configure.ac by autoheader. */
2 |
3 | /* Define to 1 if you have the header file. */
4 | #undef HAVE_DLFCN_H
5 |
6 | /* Define to 1 if you have the header file. */
7 | #undef HAVE_INTTYPES_H
8 |
9 | /* Define to 1 if you have the header file. */
10 | #undef HAVE_MEMORY_H
11 |
12 | /* Define to 1 if you have the header file. */
13 | #undef HAVE_PTHREAD_H
14 |
15 | /* Define to 1 if you have the header file. */
16 | #undef HAVE_STDINT_H
17 |
18 | /* Define to 1 if you have the header file. */
19 | #undef HAVE_STDLIB_H
20 |
21 | /* Define to 1 if you have the header file. */
22 | #undef HAVE_STRINGS_H
23 |
24 | /* Define to 1 if you have the header file. */
25 | #undef HAVE_STRING_H
26 |
27 | /* Define to 1 if you have the header file. */
28 | #undef HAVE_SYS_ERRNO_H
29 |
30 | /* Define to 1 if you have the header file. */
31 | #undef HAVE_SYS_STAT_H
32 |
33 | /* Define to 1 if you have the header file. */
34 | #undef HAVE_SYS_TYPES_H
35 |
36 | /* Define to 1 if you have the header file. */
37 | #undef HAVE_UNISTD_H
38 |
39 | /* Define to the sub-directory in which libtool stores uninstalled libraries.
40 | */
41 | #undef LT_OBJDIR
42 |
43 | /* Name of package */
44 | #undef PACKAGE
45 |
46 | /* Define to the address where bug reports for this package should be sent. */
47 | #undef PACKAGE_BUGREPORT
48 |
49 | /* Define to the full name of this package. */
50 | #undef PACKAGE_NAME
51 |
52 | /* Define to the full name and version of this package. */
53 | #undef PACKAGE_STRING
54 |
55 | /* Define to the one symbol short name of this package. */
56 | #undef PACKAGE_TARNAME
57 |
58 | /* Define to the home page for this package. */
59 | #undef PACKAGE_URL
60 |
61 | /* Define to the version of this package. */
62 | #undef PACKAGE_VERSION
63 |
64 | /* Define to 1 if you have the ANSI C header files. */
65 | #undef STDC_HEADERS
66 |
67 | /* Version number of package */
68 | #undef VERSION
69 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/native-package/src/buffer.c:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (C) 2011, FuseSource Corp. All rights reserved.
3 | *
4 | * http://fusesource.com
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are
8 | * met:
9 | *
10 | * * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above
13 | * copyright notice, this list of conditions and the following disclaimer
14 | * in the documentation and/or other materials provided with the
15 | * distribution.
16 | * * Neither the name of FuseSource Corp. nor the names of its
17 | * contributors may be used to endorse or promote products derived from
18 | * this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | *******************************************************************************/
32 | #include "rocksdbjni.h"
33 |
34 | void buffer_copy(const void *source, size_t source_pos, void *dest, size_t dest_pos, size_t length) {
35 | memmove(((char *)dest)+dest_pos, ((const char *)source)+source_pos, length);
36 | }
37 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/java/org/fusesource/rocksdbjni/internal/NativeSnapshot.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011, FuseSource Corp. All rights reserved.
3 | *
4 | * http://fusesource.com
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are
8 | * met:
9 | *
10 | * * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above
13 | * copyright notice, this list of conditions and the following disclaimer
14 | * in the documentation and/or other materials provided with the
15 | * distribution.
16 | * * Neither the name of FuseSource Corp. nor the names of its
17 | * contributors may be used to endorse or promote products derived from
18 | * this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.fusesource.rocksdbjni.internal;
33 |
34 | /**
35 | * Provides a java interface to the C++ rocksdb::Snapshot class.
36 | *
37 | * @author Hiram Chirino
38 | */
39 | public class NativeSnapshot extends NativeObject {
40 |
41 | NativeSnapshot(long self) {
42 | super(self);
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/java/org/fusesource/rocksdbjni/internal/NativeCompressionType.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011, FuseSource Corp. All rights reserved.
3 | *
4 | * http://fusesource.com
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are
8 | * met:
9 | *
10 | * * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above
13 | * copyright notice, this list of conditions and the following disclaimer
14 | * in the documentation and/or other materials provided with the
15 | * distribution.
16 | * * Neither the name of FuseSource Corp. nor the names of its
17 | * contributors may be used to endorse or promote products derived from
18 | * this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.fusesource.rocksdbjni.internal;
33 |
34 | /**
35 | * Provides a java interface to the C++ rocksdb::CompressionType enum.
36 | *
37 | * @author Hiram Chirino
38 | */
39 | public enum NativeCompressionType {
40 | kNoCompression(0x0), kSnappyCompression(0x1);
41 |
42 | static final int t = kNoCompression.value;
43 | final int value;
44 |
45 | NativeCompressionType(int value) {
46 | this.value = value;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/java/org/fusesource/rocksdbjni/internal/JniSnapshot.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011, FuseSource Corp. All rights reserved.
3 | *
4 | * http://fusesource.com
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are
8 | * met:
9 | *
10 | * * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above
13 | * copyright notice, this list of conditions and the following disclaimer
14 | * in the documentation and/or other materials provided with the
15 | * distribution.
16 | * * Neither the name of FuseSource Corp. nor the names of its
17 | * contributors may be used to endorse or promote products derived from
18 | * this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.fusesource.rocksdbjni.internal;
33 |
34 | import org.fusesource.rocksdbjni.internal.*;
35 | import org.iq80.leveldb.Snapshot;
36 |
37 | /**
38 | * @author Hiram Chirino
39 | */
40 | public class JniSnapshot implements Snapshot {
41 |
42 | private final NativeDB db;
43 | private final NativeSnapshot snapshot;
44 |
45 | JniSnapshot(NativeDB db, NativeSnapshot snapshot) {
46 | this.db = db;
47 | this.snapshot = snapshot;
48 | }
49 |
50 | public void close() {
51 | db.releaseSnapshot(snapshot);
52 | }
53 |
54 | NativeSnapshot snapshot() {
55 | return snapshot;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/java/org/fusesource/rocksdbjni/internal/NativeObject.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011, FuseSource Corp. All rights reserved.
3 | *
4 | * http://fusesource.com
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are
8 | * met:
9 | *
10 | * * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above
13 | * copyright notice, this list of conditions and the following disclaimer
14 | * in the documentation and/or other materials provided with the
15 | * distribution.
16 | * * Neither the name of FuseSource Corp. nor the names of its
17 | * contributors may be used to endorse or promote products derived from
18 | * this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.fusesource.rocksdbjni.internal;
33 |
34 | /**
35 | * A helper base class which is used to track a pointer to a native
36 | * structure or class.
37 | *
38 | * @author Hiram Chirino
39 | */
40 | class NativeObject {
41 |
42 | protected long self;
43 |
44 | protected NativeObject(long self) {
45 | this.self = self;
46 | if( self ==0 ) {
47 | throw new OutOfMemoryError("Failure allocating native heap memory");
48 | }
49 | }
50 |
51 | long pointer() {
52 | return self;
53 | }
54 |
55 | public boolean isAllocated() {
56 | return self !=0;
57 | }
58 |
59 | protected void assertAllocated() {
60 | assert isAllocated() : "This object has been deleted";
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/java/org/fusesource/rocksdbjni/internal/NativeWriteOptions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011, FuseSource Corp. All rights reserved.
3 | *
4 | * http://fusesource.com
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are
8 | * met:
9 | *
10 | * * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above
13 | * copyright notice, this list of conditions and the following disclaimer
14 | * in the documentation and/or other materials provided with the
15 | * distribution.
16 | * * Neither the name of FuseSource Corp. nor the names of its
17 | * contributors may be used to endorse or promote products derived from
18 | * this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.fusesource.rocksdbjni.internal;
33 |
34 | import org.fusesource.hawtjni.runtime.JniClass;
35 | import org.fusesource.hawtjni.runtime.JniField;
36 |
37 | import static org.fusesource.hawtjni.runtime.ClassFlag.CPP;
38 | import static org.fusesource.hawtjni.runtime.ClassFlag.STRUCT;
39 |
40 | /**
41 | * Provides a java interface to the C++ rocksdb::WriteOptions class.
42 | *
43 | * @author Hiram Chirino
44 | */
45 | @JniClass(name="rocksdb::WriteOptions", flags={STRUCT, CPP})
46 | public class NativeWriteOptions {
47 |
48 | @JniField
49 | boolean sync;
50 |
51 | public boolean sync() {
52 | return sync;
53 | }
54 |
55 | public NativeWriteOptions sync(boolean sync) {
56 | this.sync = sync;
57 | return this;
58 | }
59 |
60 | }
61 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/java/org/fusesource/rocksdbjni/internal/JniWriteBatch.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011, FuseSource Corp. All rights reserved.
3 | *
4 | * http://fusesource.com
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are
8 | * met:
9 | *
10 | * * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above
13 | * copyright notice, this list of conditions and the following disclaimer
14 | * in the documentation and/or other materials provided with the
15 | * distribution.
16 | * * Neither the name of FuseSource Corp. nor the names of its
17 | * contributors may be used to endorse or promote products derived from
18 | * this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.fusesource.rocksdbjni.internal;
33 |
34 | import org.fusesource.rocksdbjni.internal.NativeWriteBatch;
35 | import org.iq80.leveldb.WriteBatch;
36 |
37 | /**
38 | * @author Hiram Chirino
39 | */
40 | public class JniWriteBatch implements WriteBatch {
41 |
42 | private final NativeWriteBatch writeBatch;
43 |
44 | JniWriteBatch(NativeWriteBatch writeBatch) {
45 | this.writeBatch = writeBatch;
46 | }
47 |
48 | public void close() {
49 | writeBatch.delete();
50 | }
51 |
52 | public WriteBatch put(byte[] key, byte[] value) {
53 | writeBatch.put(key, value);
54 | return this;
55 | }
56 |
57 | public WriteBatch delete(byte[] key) {
58 | writeBatch.delete(key);
59 | return this;
60 | }
61 |
62 | public NativeWriteBatch writeBatch() {
63 | return writeBatch;
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/java/org/fusesource/rocksdbjni/internal/NativeReadOptions.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011, FuseSource Corp. All rights reserved.
3 | *
4 | * http://fusesource.com
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are
8 | * met:
9 | *
10 | * * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above
13 | * copyright notice, this list of conditions and the following disclaimer
14 | * in the documentation and/or other materials provided with the
15 | * distribution.
16 | * * Neither the name of FuseSource Corp. nor the names of its
17 | * contributors may be used to endorse or promote products derived from
18 | * this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.fusesource.rocksdbjni.internal;
33 |
34 | import org.fusesource.hawtjni.runtime.JniClass;
35 | import org.fusesource.hawtjni.runtime.JniField;
36 |
37 | import static org.fusesource.hawtjni.runtime.ClassFlag.CPP;
38 | import static org.fusesource.hawtjni.runtime.ClassFlag.STRUCT;
39 |
40 | /**
41 | * Provides a java interface to the C++ rocksdb::ReadOptions class.
42 | *
43 | * @author Hiram Chirino
44 | */
45 | @JniClass(name="rocksdb::ReadOptions", flags={STRUCT, CPP})
46 | public class NativeReadOptions {
47 |
48 | @JniField
49 | private boolean verify_checksums = false;
50 |
51 | @JniField
52 | private boolean fill_cache = true;
53 |
54 | @JniField(cast="const rocksdb::Snapshot*")
55 | private long snapshot=0;
56 |
57 | public boolean fillCache() {
58 | return fill_cache;
59 | }
60 |
61 | public NativeReadOptions fillCache(boolean fill_cache) {
62 | this.fill_cache = fill_cache;
63 | return this;
64 | }
65 |
66 | public NativeSnapshot snapshot() {
67 | if( snapshot == 0 ) {
68 | return null;
69 | } else {
70 | return new NativeSnapshot(snapshot);
71 | }
72 | }
73 |
74 | public NativeReadOptions snapshot(NativeSnapshot snapshot) {
75 | if( snapshot==null ) {
76 | this.snapshot = 0;
77 | } else {
78 | this.snapshot = snapshot.pointer();
79 | }
80 | return this;
81 | }
82 |
83 | public boolean verifyChecksums() {
84 | return verify_checksums;
85 | }
86 |
87 | public NativeReadOptions verifyChecksums(boolean verify_checksums) {
88 | this.verify_checksums = verify_checksums;
89 | return this;
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/native-package/m4/custom.m4:
--------------------------------------------------------------------------------
1 | dnl ---------------------------------------------------------------------------
2 | dnl Copyright (C) 2011, FuseSource Corp. All rights reserved.
3 | dnl
4 | dnl http://fusesource.com
5 | dnl
6 | dnl Redistribution and use in source and binary forms, with or without
7 | dnl modification, are permitted provided that the following conditions are
8 | dnl met:
9 | dnl
10 | dnl * Redistributions of source code must retain the above copyright
11 | dnl notice, this list of conditions and the following disclaimer.
12 | dnl * Redistributions in binary form must reproduce the above
13 | dnl copyright notice, this list of conditions and the following disclaimer
14 | dnl in the documentation and/or other materials provided with the
15 | dnl distribution.
16 | dnl * Neither the name of FuseSource Corp. nor the names of its
17 | dnl contributors may be used to endorse or promote products derived from
18 | dnl this software without specific prior written permission.
19 | dnl
20 | dnl THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | dnl "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | dnl LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | dnl A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | dnl OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | dnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | dnl LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | dnl DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | dnl THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | dnl (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | dnl OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | dnl ---------------------------------------------------------------------------
32 |
33 | AC_DEFUN([AX_CHECK_COMPILE_FLAG],
34 | [AC_PREREQ(2.59)dnl for _AC_LANG_PREFIX
35 | AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
36 | AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
37 | ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
38 | _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
39 | AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
40 | [AS_VAR_SET(CACHEVAR,[yes])],
41 | [AS_VAR_SET(CACHEVAR,[no])])
42 | _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
43 | AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes],
44 | [m4_default([$2], :)],
45 | [m4_default([$3], :)])
46 | AS_VAR_POPDEF([CACHEVAR])dnl
47 | ])
48 |
49 | AC_DEFUN([CUSTOM_M4_SETUP],
50 | [
51 | AC_LANG_PUSH(C++)
52 | AC_CHECK_HEADER([pthread.h],[AC_DEFINE([HAVE_PTHREAD_H], [1], [Define to 1 if you have the header file.])])
53 |
54 | AC_ARG_WITH([rocksdb],
55 | [AS_HELP_STRING([--with-rocksdb@<:@=PATH@:>@],
56 | [Directory where rocksdb was built. Example: --with-rocksdb=/opt/rocksdb])],
57 | [
58 | CFLAGS="$CFLAGS -I${withval}/include"
59 | CXXFLAGS="$CXXFLAGS -I${withval}/include"
60 | AC_SUBST(CXXFLAGS)
61 | LDFLAGS="$LDFLAGS -lrocksdb -L${withval}"
62 | AC_SUBST(LDFLAGS)
63 | ])
64 |
65 | AX_CHECK_COMPILE_FLAG("-std=c++0x", CXXFLAGS="$CXXFLAGS -std=c++0x")
66 | AC_SUBST(CXXFLAGS)
67 |
68 | AC_CHECK_HEADER([rocksdb/db.h],,AC_MSG_ERROR([cannot find headers for rocksdb]))
69 |
70 | AC_ARG_WITH([snappy],
71 | [AS_HELP_STRING([--with-snappy@<:@=PATH@:>@],
72 | [Directory where snappy was built. Example: --with-snappy=/opt/snappy])],
73 | [
74 | LDFLAGS="$LDFLAGS -lsnappy -L${withval}"
75 | AC_SUBST(LDFLAGS)
76 | ])
77 |
78 | AC_CHECK_HEADER([sys/errno.h],[AC_DEFINE([HAVE_SYS_ERRNO_H], [1], [Define to 1 if you have the header file.])])
79 |
80 | AC_LANG_POP()
81 | ])
--------------------------------------------------------------------------------
/releasing.md:
--------------------------------------------------------------------------------
1 | # How To Release
2 |
3 | Since levedbjni has to be build against multiple platforms, the standard maven release plugin will not work to do the release. First off, lets
4 | get the sources tagged properly so we can reproduce the build on all the platforms:
5 |
6 | ## Prepping and tagging the rocksdbjni source code.
7 |
8 | cd /tmp
9 | git clone git://github.com/fusesource/rocksdbjni.git
10 | cd rocksdbjni
11 | git co -b ${version}.x
12 | mvn -P all org.codehaus.mojo:versions-maven-plugin:1.2:set org.codehaus.mojo:versions-maven-plugin:1.2:commit -DnewVersion="${version}"
13 | git commit -am "Preping for a the ${version} release"
14 | git tag "rocksdbjni-${version}"
15 | git push origin "rocksdbjni-${version}"
16 |
17 | ## Prepping and tagging the rocksdb source code.
18 |
19 | cd /tmp
20 | git clone git://github.com/chirino/rocksdb.git
21 | cd rocksdb
22 | git apply ../rocksdbjni/rocksdb.patch
23 | git commit -am "Preping for a the rocksdbjni-${version} release"
24 | git push origin "rocksdbjni-${version}"
25 |
26 | ## Releasing the non-platform specific artifacts
27 |
28 | Now we are read to start doing release builds. The first step is to release the non-platform specific artifacts
29 | of rocksdbjni. This build should be done on a machine with an autoconfig version of at least 2.61 so that it
30 | can generate the configure script for the gnu make based builds.
31 |
32 | cd /tmp
33 | git clone git://github.com/fusesource/rocksdbjni.git
34 | git checkout "rocksdbjni-${version}"
35 | mvn clean deploy -P release -P download
36 |
37 | ## Releasing the platform specific artifacts
38 |
39 | Once this is done, now you can build the platform specific shared libraries. These platform builds depend on
40 | being able to access the artifacts previously deployed so you may need to close out any staged deployments before
41 | progressing to the next step. The first thing we need to do is download and build the snappy and rocksdb
42 | static libraries.
43 |
44 | To download the snappy, rocksdb, and rocksdbjni project source code:
45 |
46 | cd /tmp
47 |
48 | wget http://snappy.googlecode.com/files/snappy-1.0.5.tar.gz
49 | tar -zxvf snappy-1.0.5.tar.gz
50 |
51 | git clone git://github.com/chirino/rocksdb.git
52 | cd rocksdb
53 | git checkout "rocksdbjni-${version}"
54 | cd ..
55 |
56 | git clone git://github.com/fusesource/rocksdbjni.git
57 | cd rocksdbjni
58 | git checkout "rocksdbjni-${version}"
59 | cd ..
60 |
61 | export SNAPPY_HOME=`cd snappy-1.0.5; pwd`
62 | export ROCKSDB_HOME=`cd rocksdb; pwd`
63 | export rocksdbjni_HOME=`cd rocksdbjni; pwd`
64 | export LIBRARY_PATH=${SNAPPY_HOME}
65 | export C_INCLUDE_PATH=${LIBRARY_PATH}
66 | export CPLUS_INCLUDE_PATH=${LIBRARY_PATH}
67 |
68 | Compile the snappy project and rocksdb static libs
69 |
70 | cd ${SNAPPY_HOME}
71 | ./configure --disable-shared --with-pic; make
72 |
73 | cd ${ROCKSDB_HOME}
74 | make librocksdb.a
75 |
76 | Now cd to the platform specific rocksdbjni module. For example on 32 bit linux you would cd to ${rocksdbjni_HOME}/rocksdbjni/rocksdbjni-linux32 and run a release build:
77 |
78 | cd ${rocksdbjni_HOME}/rocksdbjni-$platform
79 | mvn clean deploy -P release -P download
80 |
81 | ### Linux build tips:
82 |
83 | * Build on REHL 5.6 for best compatibility across linux versions.
84 |
85 | ### Windows build tips:
86 |
87 | * Build on Windows 7 using the Windows 7.1 SDK http://www.microsoft.com/en-us/download/details.aspx?id=8279
88 |
89 | ## Aggregating platform specific artifacts
90 |
91 | Once you have released all the platform specific artifacts, then release the `rocksdbjni-all` which uber jars all the previously released artifacts.
92 |
93 | cd ${rocksdbjni_HOME}/rocksdbjni-all
94 | mvn clean deploy -P release -P download
95 |
96 | Congrats your done.
--------------------------------------------------------------------------------
/rocksdbjni/src/main/java/org/fusesource/rocksdbjni/internal/NativeStatus.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011, FuseSource Corp. All rights reserved.
3 | *
4 | * http://fusesource.com
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are
8 | * met:
9 | *
10 | * * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above
13 | * copyright notice, this list of conditions and the following disclaimer
14 | * in the documentation and/or other materials provided with the
15 | * distribution.
16 | * * Neither the name of FuseSource Corp. nor the names of its
17 | * contributors may be used to endorse or promote products derived from
18 | * this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.fusesource.rocksdbjni.internal;
33 |
34 | import org.fusesource.hawtjni.runtime.JniClass;
35 | import org.fusesource.hawtjni.runtime.JniMethod;
36 |
37 | import static org.fusesource.hawtjni.runtime.ClassFlag.CPP;
38 | import static org.fusesource.hawtjni.runtime.MethodFlag.CPP_DELETE;
39 | import static org.fusesource.hawtjni.runtime.MethodFlag.CPP_METHOD;
40 |
41 | /**
42 | * Provides a java interface to the C++ rocksdb::Status class.
43 | *
44 | * @author Hiram Chirino
45 | */
46 | class NativeStatus extends NativeObject{
47 |
48 | @JniClass(name="rocksdb::Status", flags={CPP})
49 | static class StatusJNI {
50 | static {
51 | NativeDB.LIBRARY.load();
52 | }
53 |
54 | @JniMethod(flags={CPP_DELETE})
55 | public static final native void delete(
56 | long self);
57 |
58 | @JniMethod(flags={CPP_METHOD})
59 | public static final native boolean ok(
60 | long self);
61 |
62 | @JniMethod(flags={CPP_METHOD})
63 | public static final native boolean IsNotFound(
64 | long self);
65 |
66 | @JniMethod(copy="std::string", flags={CPP_METHOD})
67 | public static final native long ToString(
68 | long self);
69 | }
70 |
71 | public NativeStatus(long self) {
72 | super(self);
73 | }
74 |
75 | public void delete() {
76 | assertAllocated();
77 | StatusJNI.delete(self);
78 | self = 0;
79 | }
80 |
81 | public boolean isOk() {
82 | assertAllocated();
83 | return StatusJNI.ok(self);
84 | }
85 |
86 | public boolean isNotFound() {
87 | assertAllocated();
88 | return StatusJNI.IsNotFound(self);
89 | }
90 |
91 | public String toString() {
92 | assertAllocated();
93 | long strptr = StatusJNI.ToString(self);
94 | if( strptr==0 ) {
95 | return null;
96 | } else {
97 | NativeStdString rc = new NativeStdString(strptr);
98 | try {
99 | return rc.toString();
100 | } finally {
101 | rc.delete();
102 | }
103 | }
104 | }
105 |
106 | }
107 |
--------------------------------------------------------------------------------
/rocksdbjni-win64/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
33 |
34 |
35 | 4.0.0
36 |
37 | org.fusesource.rocksdbjni
38 | rocksdbjni-project
39 | 99-master-SNAPSHOT
40 |
41 |
42 | org.fusesource.rocksdbjni
43 | rocksdbjni-win64
44 | 99-master-SNAPSHOT
45 |
46 | ${project.artifactId}
47 | The rocksdbjni Windows 64 bit native libraries
48 |
49 |
50 |
51 | org.fusesource.rocksdbjni
52 | rocksdbjni
53 | 99-master-SNAPSHOT
54 |
55 |
56 |
57 |
58 | ${basedir}/../rocksdbjni/src/test/java
59 |
60 |
61 |
62 | org.apache.maven.plugins
63 | maven-jar-plugin
64 | 2.3.1
65 |
66 | ${basedir}/target/generated-sources/hawtjni/lib
67 |
68 |
69 |
70 | org.fusesource.hawtjni
71 | maven-hawtjni-plugin
72 | ${hawtjni-version}
73 |
74 |
75 |
76 | build
77 |
78 |
79 |
80 |
81 | rocksdbjni
82 | false
83 |
84 | org.fusesource.rocksdbjni
85 | rocksdbjni
86 | ${project.version}
87 | native-src
88 | zip
89 |
90 | ${basedir}/../rocksdbjni/target/generated-sources/hawtjni/native-package
91 |
92 |
93 |
94 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/java/org/fusesource/rocksdbjni/internal/NativeStdString.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011, FuseSource Corp. All rights reserved.
3 | *
4 | * http://fusesource.com
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are
8 | * met:
9 | *
10 | * * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above
13 | * copyright notice, this list of conditions and the following disclaimer
14 | * in the documentation and/or other materials provided with the
15 | * distribution.
16 | * * Neither the name of FuseSource Corp. nor the names of its
17 | * contributors may be used to endorse or promote products derived from
18 | * this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.fusesource.rocksdbjni.internal;
33 |
34 | import org.fusesource.hawtjni.runtime.JniClass;
35 | import org.fusesource.hawtjni.runtime.JniMethod;
36 |
37 | import static org.fusesource.hawtjni.runtime.ClassFlag.CPP;
38 | import static org.fusesource.hawtjni.runtime.MethodFlag.*;
39 |
40 | /**
41 | * Provides a java interface to the C++ std::string class.
42 | *
43 | * @author Hiram Chirino
44 | */
45 | class NativeStdString extends NativeObject {
46 |
47 | @JniClass(name="std::string", flags={CPP})
48 | private static class StdStringJNI {
49 | static {
50 | NativeDB.LIBRARY.load();
51 | }
52 |
53 | @JniMethod(flags={CPP_NEW})
54 | public static final native long create();
55 |
56 | @JniMethod(flags={CPP_NEW})
57 | public static final native long create(String value);
58 |
59 | @JniMethod(flags={CPP_DELETE})
60 | static final native void delete(
61 | long self);
62 |
63 | @JniMethod(flags={CPP_METHOD}, accessor = "c_str", cast="const char*")
64 | public static final native long c_str_ptr (
65 | long self);
66 |
67 | @JniMethod(flags={CPP_METHOD},cast = "size_t")
68 | public static final native long length (
69 | long self);
70 |
71 | }
72 |
73 | public NativeStdString(long self) {
74 | super(self);
75 | }
76 |
77 | public NativeStdString() {
78 | super(StdStringJNI.create());
79 | }
80 |
81 | public void delete() {
82 | assertAllocated();
83 | StdStringJNI.delete(self);
84 | self = 0;
85 | }
86 |
87 | public String toString() {
88 | return new String(toByteArray());
89 | }
90 |
91 | public long length() {
92 | assertAllocated();
93 | return StdStringJNI.length(self);
94 | }
95 |
96 | public byte[] toByteArray() {
97 | long l = length();
98 | if( l > Integer.MAX_VALUE ) {
99 | throw new ArrayIndexOutOfBoundsException("Native string is larger than the maximum Java array");
100 | }
101 | byte []rc = new byte[(int) l];
102 | NativeBuffer.NativeBufferJNI.buffer_copy(StdStringJNI.c_str_ptr(self), 0, rc, 0, rc.length);
103 | return rc;
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/rocksdbjni-win32/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
33 |
34 |
35 | 4.0.0
36 |
37 | org.fusesource.rocksdbjni
38 | rocksdbjni-project
39 | 99-master-SNAPSHOT
40 |
41 |
42 | org.fusesource.rocksdbjni
43 | rocksdbjni-win32
44 | 99-master-SNAPSHOT
45 |
46 | ${project.artifactId}
47 | The rocksdbjni Windows 32 bit native libraries
48 |
49 |
50 |
51 | org.fusesource.rocksdbjni
52 | rocksdbjni
53 | 99-master-SNAPSHOT
54 |
55 |
56 |
57 |
58 | ${basedir}/../rocksdbjni/src/test/java
59 |
60 |
61 |
62 | org.apache.maven.plugins
63 | maven-jar-plugin
64 | 2.3.1
65 |
66 | ${basedir}/target/generated-sources/hawtjni/lib
67 |
68 |
69 |
70 | org.fusesource.hawtjni
71 | maven-hawtjni-plugin
72 | ${hawtjni-version}
73 |
74 |
75 |
76 | build
77 |
78 | compile
79 |
80 |
81 |
82 | rocksdbjni
83 | false
84 |
85 | org.fusesource.rocksdbjni
86 | rocksdbjni
87 | ${project.version}
88 | native-src
89 | zip
90 |
91 | ${basedir}/../rocksdbjni/target/generated-sources/hawtjni/native-package
92 |
93 |
94 |
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/rocksdbjni-linux64/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
33 |
34 |
35 | 4.0.0
36 |
37 | org.fusesource.rocksdbjni
38 | rocksdbjni-project
39 | 99-master-SNAPSHOT
40 |
41 |
42 | org.fusesource.rocksdbjni
43 | rocksdbjni-linux64
44 | 99-master-SNAPSHOT
45 |
46 | ${project.artifactId}
47 | The rocksdbjni linux 64 native libraries
48 |
49 |
50 |
51 | org.fusesource.rocksdbjni
52 | rocksdbjni
53 | 99-master-SNAPSHOT
54 |
55 |
56 |
57 |
58 | ${basedir}/../rocksdbjni/src/test/java
59 |
60 |
61 |
62 | org.apache.maven.plugins
63 | maven-jar-plugin
64 | 2.3.1
65 |
66 | ${basedir}/target/generated-sources/hawtjni/lib
67 |
68 |
69 |
70 | org.fusesource.hawtjni
71 | maven-hawtjni-plugin
72 | ${hawtjni-version}
73 |
74 |
75 |
76 | build
77 |
78 |
79 |
80 |
81 | rocksdbjni
82 | false
83 |
84 | org.fusesource.rocksdbjni
85 | rocksdbjni
86 | ${project.version}
87 | native-src
88 | zip
89 |
90 |
91 | --with-rocksdb=${env.ROCKSDB_HOME}
92 | --with-snappy=${env.SNAPPY_HOME}
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
--------------------------------------------------------------------------------
/rocksdbjni-linux32/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
33 |
34 |
35 | 4.0.0
36 |
37 | org.fusesource.rocksdbjni
38 | rocksdbjni-project
39 | 99-master-SNAPSHOT
40 |
41 |
42 | org.fusesource.rocksdbjni
43 | rocksdbjni-linux32
44 | 99-master-SNAPSHOT
45 |
46 | ${project.artifactId}
47 | The rocksdbjni linux 32 native libraries
48 |
49 |
50 |
51 | org.fusesource.rocksdbjni
52 | rocksdbjni
53 | 99-master-SNAPSHOT
54 |
55 |
56 |
57 |
58 | ${basedir}/../rocksdbjni/src/test/java
59 |
60 |
61 |
62 | org.apache.maven.plugins
63 | maven-jar-plugin
64 | 2.3.1
65 |
66 | ${basedir}/target/generated-sources/hawtjni/lib
67 |
68 |
69 |
70 | org.fusesource.hawtjni
71 | maven-hawtjni-plugin
72 | ${hawtjni-version}
73 |
74 |
75 |
76 | build
77 |
78 | compile
79 |
80 |
81 |
82 | rocksdbjni
83 | false
84 |
85 | org.fusesource.rocksdbjni
86 | rocksdbjni
87 | ${project.version}
88 | native-src
89 | zip
90 |
91 |
92 | --with-rocksdb=${env.ROCKSDB_HOME}
93 | --with-snappy=${env.SNAPPY_HOME}
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/native-package/m4/osx-universal.m4:
--------------------------------------------------------------------------------
1 | dnl ---------------------------------------------------------------------------
2 | dnl Copyright (C) 2009-2011 FuseSource Corp.
3 | dnl http://fusesource.com
4 | dnl
5 | dnl Licensed under the Apache License, Version 2.0 (the "License");
6 | dnl you may not use this file except in compliance with the License.
7 | dnl You may obtain a copy of the License at
8 | dnl
9 | dnl http://www.apache.org/licenses/LICENSE-2.0
10 | dnl
11 | dnl Unless required by applicable law or agreed to in writing, software
12 | dnl distributed under the License is distributed on an "AS IS" BASIS,
13 | dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | dnl See the License for the specific language governing permissions and
15 | dnl limitations under the License.
16 | dnl ---------------------------------------------------------------------------
17 | dnl ---------------------------------------------------------------------------
18 | dnl SYNOPSIS:
19 | dnl
20 | dnl WITH_OSX_UNIVERSAL()
21 | dnl
22 | dnl Allows creating universal binaries on the
23 | dnl
24 | dnl Adds the --with-universal=ARCH option. This will will
25 | dnl set -isysroot option to the location of the MacOSX${OSX_VERSION}.sdk.
26 | dnl if OSX_VERSION is not defined, it will set it to the latest version
27 | dnl of the SDK installed on your system.
28 | dnl
29 | dnl You must use the no-dependencies option when automake is initialized.
30 | dnl for example: AM_INIT_AUTOMAKE([no-dependencies])
31 | dnl
32 | dnl This macro calls:
33 | dnl AC_SUBST(CFLAGS)
34 | dnl AC_SUBST(CXXFLAGS)
35 | dnl AC_SUBST(LDFLAGS)
36 | dnl AC_SUBST(OSX_VERSION)
37 | dnl
38 | dnl AUTHOR: Hiram Chrino
39 | dnl ---------------------------------------------------------------------------
40 |
41 | AC_DEFUN([WITH_OSX_UNIVERSAL],
42 | [
43 | AC_PREREQ([2.61])
44 | case "$host_os" in
45 | darwin*)
46 |
47 | AC_MSG_CHECKING(OS X SDK version)
48 | AC_ARG_WITH([osxsdk],
49 | [AS_HELP_STRING([--with-osxsdk@<:@=VERSION@:>@],
50 | [OS X SDK version to build against. Example: --with-osxsdk=10.6])],
51 | [
52 | OSX_UNIVERSAL="$withval"
53 | ],[
54 | OSX_SDKS_DIR=""
55 | OSX_VERSION=""
56 | for v in 10.0 10.1 10.2 10.3 10.4 10.5 10.6 10.7 10.8 10.9 10.10 10.11 10.12; do
57 | for location in "/Developer/SDKs" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs" ; do
58 | if test -z "${OSX_VERSION}" && test -d "${location}/MacOSX${v}.sdk" ; then
59 | OSX_SDKS_DIR="${location}"
60 | OSX_VERSION="${v}"
61 | fi
62 | done
63 | done
64 | ])
65 | AC_MSG_RESULT([$OSX_VERSION])
66 | AC_SUBST(OSX_SDKS_DIR)
67 | AC_SUBST(OSX_VERSION)
68 |
69 | AC_MSG_CHECKING(whether to build universal binaries)
70 | AC_ARG_WITH([universal],
71 | [AS_HELP_STRING([--with-universal@<:@=ARCH@:>@],
72 | [Build a universal binary. Set to a space separated architecture list. Pick from: i386, x86_64, ppc, and/or ppc64. @<:@default="i386 x86_64"@:>@])],
73 | [
74 | AS_IF(test "$withval" = "no", [
75 | OSX_UNIVERSAL=""
76 | AC_MSG_RESULT([no])
77 | ], test "$withval" = "yes", [
78 | OSX_UNIVERSAL="i386 x86_64"
79 | AC_MSG_RESULT([yes, archs: $OSX_UNIVERSAL])
80 | ],[
81 | OSX_UNIVERSAL="$withval"
82 | AC_MSG_RESULT([yes, archs: $OSX_UNIVERSAL])
83 | ])
84 | ],[
85 | OSX_UNIVERSAL=""
86 | AC_MSG_RESULT([no])
87 | ])
88 |
89 | AS_IF(test -n "$OSX_UNIVERSAL", [
90 | for i in $OSX_UNIVERSAL ; do
91 | CFLAGS="-arch $i $CFLAGS"
92 | CXXFLAGS="-arch $i $CXXFLAGS"
93 | LDFLAGS="-arch $i $LDFLAGS"
94 | done
95 |
96 |
97 | for f in $__JNI_INCLUDE_EXTRAS ; do
98 | if test -d "$__JNI_INCLUDE/$f"; then
99 | __JNI_CFLAGS="$__JNI_CFLAGS -I$__JNI_INCLUDE/$f"
100 | fi
101 | done
102 |
103 |
104 | CFLAGS="-isysroot ${OSX_SDKS_DIR}/MacOSX${OSX_VERSION}.sdk $CFLAGS"
105 | CXXFLAGS="-isysroot ${OSX_SDKS_DIR}/MacOSX${OSX_VERSION}.sdk $CXXFLAGS"
106 | LDFLAGS="-syslibroot,${OSX_SDKS_DIR}/MacOSX${OSX_VERSION}.sdk $LDFLAGS"
107 | AC_SUBST(CFLAGS)
108 | AC_SUBST(CXXFLAGS)
109 | AC_SUBST(LDFLAGS)
110 | ])
111 | ;;
112 | esac
113 | ])
114 |
115 |
116 |
--------------------------------------------------------------------------------
/rocksdbjni-osx/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
33 |
34 |
35 | 4.0.0
36 |
37 | org.fusesource.rocksdbjni
38 | rocksdbjni-project
39 | 99-master-SNAPSHOT
40 |
41 |
42 | org.fusesource.rocksdbjni
43 | rocksdbjni-osx
44 | 99-master-SNAPSHOT
45 |
46 | ${project.artifactId}
47 | The rocksdbjni OS X universal native libraries
48 |
49 |
50 |
51 | org.fusesource.rocksdbjni
52 | rocksdbjni
53 | 99-master-SNAPSHOT
54 |
55 |
56 |
57 | org.fusesource.rocksdbjni
58 | rocksdbjni
59 | 99-master-SNAPSHOT
60 | test-jar
61 | test
62 |
63 |
64 |
65 |
66 | ${basedir}/../rocksdbjni/src/test/java
67 |
68 |
69 |
70 | org.apache.maven.plugins
71 | maven-jar-plugin
72 | 2.3.1
73 |
74 | ${basedir}/target/generated-sources/hawtjni/lib
75 |
76 |
77 |
78 |
79 | org.fusesource.hawtjni
80 | maven-hawtjni-plugin
81 | ${hawtjni-version}
82 |
83 |
84 |
85 | build
86 |
87 |
88 |
89 |
90 | rocksdbjni
91 | false
92 |
93 | org.fusesource.rocksdbjni
94 | rocksdbjni
95 | ${project.version}
96 | native-src
97 | zip
98 |
99 | osx
100 |
101 | --with-rocksdb=${env.ROCKSDB_HOME}
102 | --with-snappy=${env.SNAPPY_HOME}
103 | --with-universal
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/native-package/src/rocksdbjni.h:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 | * Copyright (C) 2011, FuseSource Corp. All rights reserved.
3 | *
4 | * http://fusesource.com
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are
8 | * met:
9 | *
10 | * * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above
13 | * copyright notice, this list of conditions and the following disclaimer
14 | * in the documentation and/or other materials provided with the
15 | * distribution.
16 | * * Neither the name of FuseSource Corp. nor the names of its
17 | * contributors may be used to endorse or promote products derived from
18 | * this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | *******************************************************************************/
32 | #ifndef rocksdbjni_H
33 | #define rocksdbjni_H
34 |
35 | #ifdef HAVE_CONFIG_H
36 | /* configure based build.. we will use what it discovered about the platform */
37 | #include "config.h"
38 | #endif
39 | #if defined(_WIN32) || defined(_WIN64)
40 | /* Windows based build */
41 | #define _WIN32_WINNT 0x0501
42 | #include
43 | #endif
44 | #if !defined(HAVE_CONFIG_H) && (defined(_WIN32) || defined(_WIN64))
45 | #define HAVE_STDLIB_H 1
46 | #define HAVE_STRINGS_H 1
47 | #endif
48 |
49 | #ifdef HAVE_UNISTD_H
50 | #include
51 | #endif
52 |
53 | #ifdef HAVE_STDLIB_H
54 | #include
55 | #endif
56 |
57 | #ifdef HAVE_STRINGS_H
58 | #include
59 | #endif
60 |
61 | #ifdef HAVE_SYS_ERRNO_H
62 | #include
63 | #endif
64 |
65 | #include "hawtjni.h"
66 | #include
67 | #include
68 |
69 | #ifdef __cplusplus
70 |
71 | #include "rocksdb/db.h"
72 | #include "rocksdb/options.h"
73 | #include "rocksdb/write_batch.h"
74 | #include "rocksdb/cache.h"
75 | #include "rocksdb/comparator.h"
76 | #include "rocksdb/env.h"
77 | #include "rocksdb/slice.h"
78 |
79 | struct JNIComparator : public rocksdb::Comparator {
80 | jobject target;
81 | jmethodID compare_method;
82 | const char *name;
83 |
84 | int Compare(const rocksdb::Slice& a, const rocksdb::Slice& b) const {
85 | JNIEnv *env;
86 | if ( hawtjni_attach_thread(&env, "rocksdb") ) {
87 | return 0;
88 | }
89 | int rc = env->CallIntMethod(target, compare_method, (jlong)(intptr_t)&a, (jlong)(intptr_t)&b);
90 | hawtjni_detach_thread();
91 | return rc;
92 | }
93 |
94 | const char* Name() const {
95 | return name;
96 | }
97 |
98 | void FindShortestSeparator(std::string*, const rocksdb::Slice&) const { }
99 | void FindShortSuccessor(std::string*) const { }
100 | };
101 |
102 | struct JNILogger : public rocksdb::Logger {
103 | jobject target;
104 | jmethodID log_method;
105 |
106 | void Logv(const char* format, va_list ap) {
107 | JNIEnv *env;
108 | if ( hawtjni_attach_thread(&env, "rocksdb") ) {
109 | return;
110 | }
111 |
112 | char buffer[1024];
113 | vsnprintf(buffer, sizeof(buffer), format, ap);
114 |
115 | jstring message = env->NewStringUTF(buffer);
116 | if( message ) {
117 | env->CallVoidMethod(target, log_method, message);
118 | env->DeleteLocalRef(message);
119 | }
120 |
121 | if (env->ExceptionOccurred() ) {
122 | env->ExceptionDescribe();
123 | env->ExceptionClear();
124 | }
125 | hawtjni_detach_thread();
126 | }
127 |
128 | };
129 |
130 | #endif
131 |
132 |
133 | #ifdef __cplusplus
134 | extern "C" {
135 | #endif
136 |
137 | void buffer_copy(const void *source, size_t source_pos, void *dest, size_t dest_pos, size_t length);
138 |
139 | #ifdef __cplusplus
140 | } /* extern "C" */
141 | #endif
142 |
143 |
144 | #endif /* rocksdbjni_H */
145 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/native-package/m4/ltsugar.m4:
--------------------------------------------------------------------------------
1 | # ltsugar.m4 -- libtool m4 base layer. -*-Autoconf-*-
2 | #
3 | # Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
4 | # Written by Gary V. Vaughan, 2004
5 | #
6 | # This file is free software; the Free Software Foundation gives
7 | # unlimited permission to copy and/or distribute it, with or without
8 | # modifications, as long as this notice is preserved.
9 |
10 | # serial 6 ltsugar.m4
11 |
12 | # This is to help aclocal find these macros, as it can't see m4_define.
13 | AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])])
14 |
15 |
16 | # lt_join(SEP, ARG1, [ARG2...])
17 | # -----------------------------
18 | # Produce ARG1SEPARG2...SEPARGn, omitting [] arguments and their
19 | # associated separator.
20 | # Needed until we can rely on m4_join from Autoconf 2.62, since all earlier
21 | # versions in m4sugar had bugs.
22 | m4_define([lt_join],
23 | [m4_if([$#], [1], [],
24 | [$#], [2], [[$2]],
25 | [m4_if([$2], [], [], [[$2]_])$0([$1], m4_shift(m4_shift($@)))])])
26 | m4_define([_lt_join],
27 | [m4_if([$#$2], [2], [],
28 | [m4_if([$2], [], [], [[$1$2]])$0([$1], m4_shift(m4_shift($@)))])])
29 |
30 |
31 | # lt_car(LIST)
32 | # lt_cdr(LIST)
33 | # ------------
34 | # Manipulate m4 lists.
35 | # These macros are necessary as long as will still need to support
36 | # Autoconf-2.59 which quotes differently.
37 | m4_define([lt_car], [[$1]])
38 | m4_define([lt_cdr],
39 | [m4_if([$#], 0, [m4_fatal([$0: cannot be called without arguments])],
40 | [$#], 1, [],
41 | [m4_dquote(m4_shift($@))])])
42 | m4_define([lt_unquote], $1)
43 |
44 |
45 | # lt_append(MACRO-NAME, STRING, [SEPARATOR])
46 | # ------------------------------------------
47 | # Redefine MACRO-NAME to hold its former content plus `SEPARATOR'`STRING'.
48 | # Note that neither SEPARATOR nor STRING are expanded; they are appended
49 | # to MACRO-NAME as is (leaving the expansion for when MACRO-NAME is invoked).
50 | # No SEPARATOR is output if MACRO-NAME was previously undefined (different
51 | # than defined and empty).
52 | #
53 | # This macro is needed until we can rely on Autoconf 2.62, since earlier
54 | # versions of m4sugar mistakenly expanded SEPARATOR but not STRING.
55 | m4_define([lt_append],
56 | [m4_define([$1],
57 | m4_ifdef([$1], [m4_defn([$1])[$3]])[$2])])
58 |
59 |
60 |
61 | # lt_combine(SEP, PREFIX-LIST, INFIX, SUFFIX1, [SUFFIX2...])
62 | # ----------------------------------------------------------
63 | # Produce a SEP delimited list of all paired combinations of elements of
64 | # PREFIX-LIST with SUFFIX1 through SUFFIXn. Each element of the list
65 | # has the form PREFIXmINFIXSUFFIXn.
66 | # Needed until we can rely on m4_combine added in Autoconf 2.62.
67 | m4_define([lt_combine],
68 | [m4_if(m4_eval([$# > 3]), [1],
69 | [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], m4_defn([lt_car]))])]]dnl
70 | [[m4_foreach([_Lt_prefix], [$2],
71 | [m4_foreach([_Lt_suffix],
72 | ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[,
73 | [_Lt_sep([$1])[]m4_defn([_Lt_prefix])[$3]m4_defn([_Lt_suffix])])])])])
74 |
75 |
76 | # lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ])
77 | # -----------------------------------------------------------------------
78 | # Iff MACRO-NAME does not yet contain VARNAME, then append it (delimited
79 | # by SEPARATOR if supplied) and expand UNIQ, else NOT-UNIQ.
80 | m4_define([lt_if_append_uniq],
81 | [m4_ifdef([$1],
82 | [m4_if(m4_index([$3]m4_defn([$1])[$3], [$3$2$3]), [-1],
83 | [lt_append([$1], [$2], [$3])$4],
84 | [$5])],
85 | [lt_append([$1], [$2], [$3])$4])])
86 |
87 |
88 | # lt_dict_add(DICT, KEY, VALUE)
89 | # -----------------------------
90 | m4_define([lt_dict_add],
91 | [m4_define([$1($2)], [$3])])
92 |
93 |
94 | # lt_dict_add_subkey(DICT, KEY, SUBKEY, VALUE)
95 | # --------------------------------------------
96 | m4_define([lt_dict_add_subkey],
97 | [m4_define([$1($2:$3)], [$4])])
98 |
99 |
100 | # lt_dict_fetch(DICT, KEY, [SUBKEY])
101 | # ----------------------------------
102 | m4_define([lt_dict_fetch],
103 | [m4_ifval([$3],
104 | m4_ifdef([$1($2:$3)], [m4_defn([$1($2:$3)])]),
105 | m4_ifdef([$1($2)], [m4_defn([$1($2)])]))])
106 |
107 |
108 | # lt_if_dict_fetch(DICT, KEY, [SUBKEY], VALUE, IF-TRUE, [IF-FALSE])
109 | # -----------------------------------------------------------------
110 | m4_define([lt_if_dict_fetch],
111 | [m4_if(lt_dict_fetch([$1], [$2], [$3]), [$4],
112 | [$5],
113 | [$6])])
114 |
115 |
116 | # lt_dict_filter(DICT, [SUBKEY], VALUE, [SEPARATOR], KEY, [...])
117 | # --------------------------------------------------------------
118 | m4_define([lt_dict_filter],
119 | [m4_if([$5], [], [],
120 | [lt_join(m4_quote(m4_default([$4], [[, ]])),
121 | lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_key, lt_car([m4_shiftn(4, $@)]),
122 | [lt_if_dict_fetch([$1], _Lt_key, [$2], [$3], [_Lt_key ])])))))])[]dnl
123 | ])
124 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/java/org/fusesource/rocksdbjni/internal/NativeLogger.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011, FuseSource Corp. All rights reserved.
3 | *
4 | * http://fusesource.com
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are
8 | * met:
9 | *
10 | * * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above
13 | * copyright notice, this list of conditions and the following disclaimer
14 | * in the documentation and/or other materials provided with the
15 | * distribution.
16 | * * Neither the name of FuseSource Corp. nor the names of its
17 | * contributors may be used to endorse or promote products derived from
18 | * this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.fusesource.rocksdbjni.internal;
33 |
34 | import org.fusesource.hawtjni.runtime.JniArg;
35 | import org.fusesource.hawtjni.runtime.JniClass;
36 | import org.fusesource.hawtjni.runtime.JniField;
37 | import org.fusesource.hawtjni.runtime.JniMethod;
38 |
39 | import static org.fusesource.hawtjni.runtime.ArgFlag.CRITICAL;
40 | import static org.fusesource.hawtjni.runtime.ArgFlag.NO_OUT;
41 | import static org.fusesource.hawtjni.runtime.ClassFlag.CPP;
42 | import static org.fusesource.hawtjni.runtime.ClassFlag.STRUCT;
43 | import static org.fusesource.hawtjni.runtime.FieldFlag.CONSTANT;
44 | import static org.fusesource.hawtjni.runtime.FieldFlag.POINTER_FIELD;
45 | import static org.fusesource.hawtjni.runtime.MethodFlag.*;
46 |
47 | /**
48 | *
49 | * Provides a java interface to the C++ rocksdb::Logger class.
50 | *
51 | *
52 | * @author Hiram Chirino
53 | */
54 | public abstract class NativeLogger extends NativeObject {
55 |
56 | @JniClass(name="JNILogger", flags={STRUCT, CPP})
57 | static public class LoggerJNI {
58 |
59 | static {
60 | NativeDB.LIBRARY.load();
61 | init();
62 | }
63 |
64 | @JniMethod(flags={CPP_NEW})
65 | public static final native long create();
66 |
67 | @JniMethod(flags={CPP_DELETE})
68 | public static final native void delete(
69 | long self
70 | );
71 |
72 | public static final native void memmove (
73 | @JniArg(cast="void *") long dest,
74 | @JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) LoggerJNI src,
75 | @JniArg(cast="size_t") long size);
76 |
77 | @JniField(cast="jobject", flags={POINTER_FIELD})
78 | long target;
79 |
80 | @JniField(cast="jmethodID", flags={POINTER_FIELD})
81 | long log_method;
82 |
83 | @JniMethod(flags={CONSTANT_INITIALIZER})
84 | private static final native void init();
85 |
86 | @JniField(flags={CONSTANT}, accessor="sizeof(struct JNILogger)")
87 | static int SIZEOF;
88 | }
89 |
90 | private long globalRef;
91 |
92 | public NativeLogger() {
93 | super(LoggerJNI.create());
94 | try {
95 | globalRef = NativeDB.DBJNI.NewGlobalRef(this);
96 | if( globalRef==0 ) {
97 | throw new RuntimeException("jni call failed: NewGlobalRef");
98 | }
99 | LoggerJNI struct = new LoggerJNI();
100 | struct.log_method = NativeDB.DBJNI.GetMethodID(this.getClass(), "log", "(Ljava/lang/String;)V");
101 | if( struct.log_method ==0 ) {
102 | throw new RuntimeException("jni call failed: GetMethodID");
103 | }
104 | struct.target = globalRef;
105 | LoggerJNI.memmove(self, struct, LoggerJNI.SIZEOF);
106 |
107 | } catch (RuntimeException e) {
108 | delete();
109 | throw e;
110 | }
111 | }
112 |
113 | NativeLogger(long ptr) {
114 | super(ptr);
115 | }
116 |
117 | public void delete() {
118 | if( globalRef!=0 ) {
119 | NativeDB.DBJNI.DeleteGlobalRef(globalRef);
120 | globalRef = 0;
121 | }
122 | }
123 |
124 | public abstract void log(String message);
125 |
126 | }
127 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/java/org/fusesource/rocksdbjni/internal/NativeRange.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011, FuseSource Corp. All rights reserved.
3 | *
4 | * http://fusesource.com
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are
8 | * met:
9 | *
10 | * * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above
13 | * copyright notice, this list of conditions and the following disclaimer
14 | * in the documentation and/or other materials provided with the
15 | * distribution.
16 | * * Neither the name of FuseSource Corp. nor the names of its
17 | * contributors may be used to endorse or promote products derived from
18 | * this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.fusesource.rocksdbjni.internal;
33 |
34 | import org.fusesource.hawtjni.runtime.*;
35 |
36 | import static org.fusesource.hawtjni.runtime.ArgFlag.*;
37 | import static org.fusesource.hawtjni.runtime.ClassFlag.CPP;
38 | import static org.fusesource.hawtjni.runtime.ClassFlag.STRUCT;
39 | import static org.fusesource.hawtjni.runtime.FieldFlag.CONSTANT;
40 | import static org.fusesource.hawtjni.runtime.FieldFlag.FIELD_SKIP;
41 | import static org.fusesource.hawtjni.runtime.MethodFlag.CONSTANT_INITIALIZER;
42 |
43 | /**
44 | * Provides a java interface to the C++ rocksdb::ReadOptions class.
45 | *
46 | * @author Hiram Chirino
47 | */
48 | public class NativeRange {
49 |
50 | @JniClass(name="rocksdb::Range", flags={STRUCT, CPP})
51 | static public class RangeJNI {
52 |
53 | static {
54 | NativeDB.LIBRARY.load();
55 | init();
56 | }
57 |
58 | public static final native void memmove (
59 | @JniArg(cast="void *") long dest,
60 | @JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) RangeJNI src,
61 | @JniArg(cast="size_t") long size);
62 |
63 | public static final native void memmove (
64 | @JniArg(cast="void *", flags={NO_IN, CRITICAL}) RangeJNI dest,
65 | @JniArg(cast="const void *") long src,
66 | @JniArg(cast="size_t") long size);
67 |
68 |
69 | @JniMethod(flags={CONSTANT_INITIALIZER})
70 | private static final native void init();
71 |
72 | @JniField(flags={CONSTANT}, accessor="sizeof(struct rocksdb::Range)")
73 | static int SIZEOF;
74 |
75 | @JniField
76 | NativeSlice start = new NativeSlice();
77 | @JniField(flags={FIELD_SKIP})
78 | NativeBuffer start_buffer;
79 |
80 | @JniField
81 | NativeSlice limit = new NativeSlice();
82 | @JniField(flags={FIELD_SKIP})
83 | NativeBuffer limit_buffer;
84 |
85 | public RangeJNI(NativeRange range) {
86 | start_buffer = NativeBuffer.create(range.start());
87 | start.set(start_buffer);
88 | try {
89 | limit_buffer = NativeBuffer.create(range.limit());
90 | } catch (OutOfMemoryError e) {
91 | start_buffer.delete();
92 | throw e;
93 | }
94 | limit.set(limit_buffer);
95 | }
96 |
97 | public void delete() {
98 | start_buffer.delete();
99 | limit_buffer.delete();
100 | }
101 |
102 | static NativeBuffer arrayCreate(int dimension) {
103 | return NativeBuffer.create(dimension*SIZEOF);
104 | }
105 |
106 | void arrayWrite(long buffer, int index) {
107 | RangeJNI.memmove(PointerMath.add(buffer, SIZEOF * index), this, SIZEOF);
108 | }
109 |
110 | void arrayRead(long buffer, int index) {
111 | RangeJNI.memmove(this, PointerMath.add(buffer, SIZEOF * index), SIZEOF);
112 | }
113 |
114 | }
115 |
116 | final private byte[] start;
117 | final private byte[] limit;
118 |
119 | public byte[] limit() {
120 | return limit;
121 | }
122 |
123 | public byte[] start() {
124 | return start;
125 | }
126 |
127 | public NativeRange(byte[] start, byte[] limit) {
128 | NativeDB.checkArgNotNull(start, "start");
129 | NativeDB.checkArgNotNull(limit, "limit");
130 | this.limit = limit;
131 | this.start = start;
132 | }
133 | }
134 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/java/org/fusesource/rocksdbjni/internal/JniDBIterator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011, FuseSource Corp. All rights reserved.
3 | *
4 | * http://fusesource.com
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are
8 | * met:
9 | *
10 | * * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above
13 | * copyright notice, this list of conditions and the following disclaimer
14 | * in the documentation and/or other materials provided with the
15 | * distribution.
16 | * * Neither the name of FuseSource Corp. nor the names of its
17 | * contributors may be used to endorse or promote products derived from
18 | * this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.fusesource.rocksdbjni.internal;
33 |
34 | import org.fusesource.rocksdbjni.internal.NativeDB;
35 | import org.fusesource.rocksdbjni.internal.NativeIterator;
36 | import org.iq80.leveldb.DBIterator;
37 |
38 | import java.util.AbstractMap;
39 | import java.util.Map;
40 | import java.util.NoSuchElementException;
41 |
42 | /**
43 | * @author Hiram Chirino
44 | */
45 | public class JniDBIterator implements DBIterator {
46 |
47 | private final NativeIterator iterator;
48 |
49 | JniDBIterator(NativeIterator iterator) {
50 | this.iterator = iterator;
51 | }
52 |
53 | public void close() {
54 | iterator.delete();
55 | }
56 |
57 | public void remove() {
58 | throw new UnsupportedOperationException();
59 | }
60 |
61 | public void seek(byte[] key) {
62 | try {
63 | iterator.seek(key);
64 | } catch (NativeDB.DBException e) {
65 | if( e.isNotFound() ) {
66 | throw new NoSuchElementException();
67 | } else {
68 | throw new RuntimeException(e);
69 | }
70 | }
71 | }
72 |
73 | public void seekToFirst() {
74 | iterator.seekToFirst();
75 | }
76 |
77 | public void seekToLast() {
78 | iterator.seekToLast();
79 | }
80 |
81 |
82 | public Map.Entry peekNext() {
83 | if(!iterator.isValid()) {
84 | throw new NoSuchElementException();
85 | }
86 | try {
87 | return new AbstractMap.SimpleImmutableEntry(iterator.key(), iterator.value());
88 | } catch (NativeDB.DBException e) {
89 | throw new RuntimeException(e);
90 | }
91 | }
92 |
93 | public boolean hasNext() {
94 | return iterator.isValid();
95 | }
96 |
97 | public Map.Entry next() {
98 | Map.Entry rc = peekNext();
99 | try {
100 | iterator.next();
101 | } catch (NativeDB.DBException e) {
102 | throw new RuntimeException(e);
103 | }
104 | return rc;
105 | }
106 |
107 | public boolean hasPrev() {
108 | if( !iterator.isValid() )
109 | return false;
110 | try {
111 | iterator.prev();
112 | try {
113 | return iterator.isValid();
114 | } finally {
115 | if (iterator.isValid()) {
116 | iterator.next();
117 | } else {
118 | iterator.seekToFirst();
119 | }
120 | }
121 | } catch (NativeDB.DBException e) {
122 | throw new RuntimeException(e);
123 | }
124 | }
125 |
126 | public Map.Entry peekPrev() {
127 | try {
128 | iterator.prev();
129 | try {
130 | return peekNext();
131 | } finally {
132 | if (iterator.isValid()) {
133 | iterator.next();
134 | } else {
135 | iterator.seekToFirst();
136 | }
137 | }
138 | } catch (NativeDB.DBException e) {
139 | throw new RuntimeException(e);
140 | }
141 | }
142 |
143 | public Map.Entry prev() {
144 | Map.Entry rc = peekPrev();
145 | try {
146 | iterator.prev();
147 | } catch (NativeDB.DBException e) {
148 | throw new RuntimeException(e);
149 | }
150 | return rc;
151 | }
152 |
153 |
154 | }
155 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/java/org/fusesource/rocksdbjni/internal/NativeWriteBatch.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011, FuseSource Corp. All rights reserved.
3 | *
4 | * http://fusesource.com
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are
8 | * met:
9 | *
10 | * * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above
13 | * copyright notice, this list of conditions and the following disclaimer
14 | * in the documentation and/or other materials provided with the
15 | * distribution.
16 | * * Neither the name of FuseSource Corp. nor the names of its
17 | * contributors may be used to endorse or promote products derived from
18 | * this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.fusesource.rocksdbjni.internal;
33 |
34 | import org.fusesource.hawtjni.runtime.JniArg;
35 | import org.fusesource.hawtjni.runtime.JniClass;
36 | import org.fusesource.hawtjni.runtime.JniMethod;
37 |
38 | import static org.fusesource.hawtjni.runtime.ArgFlag.BY_VALUE;
39 | import static org.fusesource.hawtjni.runtime.ArgFlag.NO_OUT;
40 | import static org.fusesource.hawtjni.runtime.ClassFlag.CPP;
41 | import static org.fusesource.hawtjni.runtime.MethodFlag.*;
42 |
43 | /**
44 | * Provides a java interface to the C++ rocksdb::WriteBatch class.
45 | *
46 | * @author Hiram Chirino
47 | */
48 | public class NativeWriteBatch extends NativeObject {
49 |
50 | @JniClass(name="rocksdb::WriteBatch", flags={CPP})
51 | private static class WriteBatchJNI {
52 | static {
53 | NativeDB.LIBRARY.load();
54 | }
55 |
56 | @JniMethod(flags={CPP_NEW})
57 | public static final native long create();
58 | @JniMethod(flags={CPP_DELETE})
59 | public static final native void delete(
60 | long self);
61 |
62 | @JniMethod(flags={CPP_METHOD})
63 | static final native void Put(
64 | long self,
65 | @JniArg(flags={BY_VALUE, NO_OUT}) NativeSlice key,
66 | @JniArg(flags={BY_VALUE, NO_OUT}) NativeSlice value
67 | );
68 |
69 | @JniMethod(flags={CPP_METHOD})
70 | static final native void Delete(
71 | long self,
72 | @JniArg(flags={BY_VALUE, NO_OUT}) NativeSlice key
73 | );
74 |
75 | @JniMethod(flags={CPP_METHOD})
76 | static final native void Clear(
77 | long self
78 | );
79 |
80 | }
81 |
82 | public NativeWriteBatch() {
83 | super(WriteBatchJNI.create());
84 | }
85 |
86 | public void delete() {
87 | assertAllocated();
88 | WriteBatchJNI.delete(self);
89 | self = 0;
90 | }
91 |
92 | public void put(byte[] key, byte[] value) {
93 | NativeDB.checkArgNotNull(key, "key");
94 | NativeDB.checkArgNotNull(value, "value");
95 | NativeBuffer keyBuffer = NativeBuffer.create(key);
96 | try {
97 | NativeBuffer valueBuffer = NativeBuffer.create(value);
98 | try {
99 | put(keyBuffer, valueBuffer);
100 | } finally {
101 | valueBuffer.delete();
102 | }
103 | } finally {
104 | keyBuffer.delete();
105 | }
106 | }
107 |
108 | private void put(NativeBuffer keyBuffer, NativeBuffer valueBuffer) {
109 | put(new NativeSlice(keyBuffer), new NativeSlice(valueBuffer));
110 | }
111 |
112 | private void put(NativeSlice keySlice, NativeSlice valueSlice) {
113 | assertAllocated();
114 | WriteBatchJNI.Put(self, keySlice, valueSlice);
115 | }
116 |
117 |
118 | public void delete(byte[] key) {
119 | NativeDB.checkArgNotNull(key, "key");
120 | NativeBuffer keyBuffer = NativeBuffer.create(key);
121 | try {
122 | delete(keyBuffer);
123 | } finally {
124 | keyBuffer.delete();
125 | }
126 | }
127 |
128 | private void delete(NativeBuffer keyBuffer) {
129 | delete(new NativeSlice(keyBuffer));
130 | }
131 |
132 | private void delete(NativeSlice keySlice) {
133 | assertAllocated();
134 | WriteBatchJNI.Delete(self, keySlice);
135 | }
136 |
137 | public void clear() {
138 | assertAllocated();
139 | WriteBatchJNI.Clear(self);
140 | }
141 |
142 | }
143 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/java/org/fusesource/rocksdbjni/internal/Util.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011, FuseSource Corp. All rights reserved.
3 | *
4 | * http://fusesource.com
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are
8 | * met:
9 | *
10 | * * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above
13 | * copyright notice, this list of conditions and the following disclaimer
14 | * in the documentation and/or other materials provided with the
15 | * distribution.
16 | * * Neither the name of FuseSource Corp. nor the names of its
17 | * contributors may be used to endorse or promote products derived from
18 | * this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.fusesource.rocksdbjni.internal;
33 |
34 | import org.fusesource.hawtjni.runtime.JniArg;
35 | import org.fusesource.hawtjni.runtime.JniClass;
36 | import org.fusesource.hawtjni.runtime.JniField;
37 | import org.fusesource.hawtjni.runtime.JniMethod;
38 |
39 | import java.io.File;
40 | import java.io.IOException;
41 |
42 | import static org.fusesource.hawtjni.runtime.ClassFlag.CPP;
43 | import static org.fusesource.hawtjni.runtime.FieldFlag.CONSTANT;
44 | import static org.fusesource.hawtjni.runtime.MethodFlag.*;
45 | import static org.fusesource.hawtjni.runtime.ArgFlag.*;
46 |
47 | /**
48 | * Some miscellaneous utility functions.
49 | *
50 | * @author Hiram Chirino
51 | */
52 | public class Util {
53 |
54 | @JniClass(name="rocksdb::Env", flags={CPP})
55 | static class EnvJNI {
56 |
57 | static {
58 | NativeDB.LIBRARY.load();
59 | }
60 |
61 | @JniMethod(cast = "rocksdb::Env *", accessor = "rocksdb::Env::Default")
62 | public static final native long Default();
63 |
64 | @JniMethod(flags = {CPP_METHOD})
65 | public static final native void Schedule(
66 | long self,
67 | @JniArg(cast = "void (*)(void*)") long fp,
68 | @JniArg(cast = "void *") long arg);
69 |
70 | }
71 |
72 | @JniClass(flags={CPP})
73 | static class UtilJNI {
74 |
75 | static {
76 | NativeDB.LIBRARY.load();
77 | init();
78 | }
79 |
80 | @JniMethod(flags={CONSTANT_INITIALIZER})
81 | private static final native void init();
82 |
83 | @JniField(flags={CONSTANT}, accessor="1", conditional="defined(_WIN32) || defined(_WIN64)")
84 | static int ON_WINDOWS;
85 |
86 |
87 | @JniMethod(conditional="!defined(_WIN32) && !defined(_WIN64)")
88 | static final native int link(
89 | @JniArg(cast="const char*") String source,
90 | @JniArg(cast="const char*") String target);
91 |
92 | @JniMethod(conditional="defined(_WIN32) || defined(_WIN64)")
93 | static final native int CreateHardLinkW(
94 | @JniArg(cast="LPCWSTR", flags={POINTER_ARG, UNICODE}) String target,
95 | @JniArg(cast="LPCWSTR", flags={POINTER_ARG, UNICODE}) String source,
96 | @JniArg(cast="LPSECURITY_ATTRIBUTES", flags={POINTER_ARG}) long lpSecurityAttributes);
97 |
98 | @JniMethod(flags={CONSTANT_GETTER})
99 | public static final native int errno();
100 |
101 | @JniMethod(cast="char *")
102 | public static final native long strerror(int errnum);
103 |
104 | public static final native int strlen(
105 | @JniArg(cast="const char *")long s);
106 |
107 | }
108 |
109 | /**
110 | * Creates a hard link from source to target.
111 | * @param source
112 | * @param target
113 | * @return
114 | */
115 | public static void link(File source, File target) throws IOException {
116 | if( UtilJNI.ON_WINDOWS == 1 ) {
117 | if( UtilJNI.CreateHardLinkW(target.getCanonicalPath(), source.getCanonicalPath(), 0) == 0) {
118 | throw new IOException("link failed");
119 | }
120 | } else {
121 | if( UtilJNI.link(source.getCanonicalPath(), target.getCanonicalPath()) != 0 ) {
122 | throw new IOException("link failed: "+strerror());
123 | }
124 | }
125 | }
126 |
127 | static int errno() {
128 | return UtilJNI.errno();
129 | }
130 |
131 | static String strerror() {
132 | return string(UtilJNI.strerror(errno()));
133 | }
134 |
135 | static String string(long ptr) {
136 | if( ptr == 0 )
137 | return null;
138 | return new String(new NativeSlice(ptr, UtilJNI.strlen(ptr)).toByteArray());
139 | }
140 |
141 | }
142 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/java/org/fusesource/rocksdbjni/internal/NativeSlice.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011, FuseSource Corp. All rights reserved.
3 | *
4 | * http://fusesource.com
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are
8 | * met:
9 | *
10 | * * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above
13 | * copyright notice, this list of conditions and the following disclaimer
14 | * in the documentation and/or other materials provided with the
15 | * distribution.
16 | * * Neither the name of FuseSource Corp. nor the names of its
17 | * contributors may be used to endorse or promote products derived from
18 | * this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.fusesource.rocksdbjni.internal;
33 |
34 | import org.fusesource.hawtjni.runtime.*;
35 |
36 | import static org.fusesource.hawtjni.runtime.ArgFlag.*;
37 | import static org.fusesource.hawtjni.runtime.ClassFlag.CPP;
38 | import static org.fusesource.hawtjni.runtime.ClassFlag.STRUCT;
39 | import static org.fusesource.hawtjni.runtime.FieldFlag.CONSTANT;
40 | import static org.fusesource.hawtjni.runtime.MethodFlag.CONSTANT_INITIALIZER;
41 | import static org.fusesource.hawtjni.runtime.MethodFlag.CPP_DELETE;
42 |
43 | /**
44 | * Provides a java interface to the C++ rocksdb::Slice class.
45 | *
46 | * @author Hiram Chirino
47 | */
48 | @JniClass(name="rocksdb::Slice", flags={STRUCT, CPP})
49 | class NativeSlice {
50 |
51 | @JniClass(name="rocksdb::Slice", flags={CPP})
52 | static class SliceJNI {
53 | static {
54 | NativeDB.LIBRARY.load();
55 | init();
56 | }
57 |
58 | @JniMethod(flags={CPP_DELETE})
59 | public static final native void delete(
60 | long self
61 | );
62 |
63 | public static final native void memmove (
64 | @JniArg(cast="void *") long dest,
65 | @JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) NativeSlice src,
66 | @JniArg(cast="size_t") long size);
67 |
68 | public static final native void memmove (
69 | @JniArg(cast="void *", flags={NO_IN, CRITICAL}) NativeSlice dest,
70 | @JniArg(cast="const void *") long src,
71 | @JniArg(cast="size_t") long size);
72 |
73 |
74 | @JniMethod(flags={CONSTANT_INITIALIZER})
75 | private static final native void init();
76 |
77 | @JniField(flags={CONSTANT}, accessor="sizeof(struct rocksdb::Slice)")
78 | static int SIZEOF;
79 |
80 | }
81 |
82 |
83 | @JniField(cast="const char*")
84 | private long data_;
85 | @JniField(cast="size_t")
86 | private long size_;
87 |
88 | public NativeSlice() {
89 | }
90 |
91 | public NativeSlice(long data, long length) {
92 | this.data_ = data;
93 | this.size_ = length;
94 | }
95 |
96 | public NativeSlice(NativeBuffer buffer) {
97 | this(buffer.pointer(), buffer.capacity());
98 | }
99 |
100 | public static NativeSlice create(NativeBuffer buffer) {
101 | if(buffer == null ) {
102 | return null;
103 | } else {
104 | return new NativeSlice(buffer);
105 | }
106 | }
107 |
108 | public long data() {
109 | return data_;
110 | }
111 |
112 | public NativeSlice data(long data) {
113 | this.data_ = data;
114 | return this;
115 | }
116 |
117 | public long size() {
118 | return size_;
119 | }
120 |
121 | public NativeSlice size(long size) {
122 | this.size_ = size;
123 | return this;
124 | }
125 |
126 | public NativeSlice set(NativeSlice buffer) {
127 | this.size_ = buffer.size_;
128 | this.data_ = buffer.data_;
129 | return this;
130 | }
131 |
132 | public NativeSlice set(NativeBuffer buffer) {
133 | this.size_ = buffer.capacity();
134 | this.data_ = buffer.pointer();
135 | return this;
136 | }
137 |
138 | public byte[] toByteArray() {
139 | if( size_ > Integer.MAX_VALUE ) {
140 | throw new ArrayIndexOutOfBoundsException("Native slice is larger than the maximum Java array");
141 | }
142 | byte []rc = new byte[(int) size_];
143 | NativeBuffer.NativeBufferJNI.buffer_copy(data_, 0, rc, 0, rc.length);
144 | return rc;
145 | }
146 |
147 | static NativeBuffer arrayCreate(int dimension) {
148 | return NativeBuffer.create(dimension*SliceJNI.SIZEOF);
149 | }
150 |
151 | void write(long buffer, int index) {
152 | SliceJNI.memmove(PointerMath.add(buffer, SliceJNI.SIZEOF*index), this, SliceJNI.SIZEOF);
153 | }
154 |
155 | void read(long buffer, int index) {
156 | SliceJNI.memmove(this, PointerMath.add(buffer, SliceJNI.SIZEOF*index), SliceJNI.SIZEOF);
157 | }
158 |
159 |
160 | }
161 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/native-package/m4/lt~obsolete.m4:
--------------------------------------------------------------------------------
1 | # lt~obsolete.m4 -- aclocal satisfying obsolete definitions. -*-Autoconf-*-
2 | #
3 | # Copyright (C) 2004, 2005, 2007, 2009 Free Software Foundation, Inc.
4 | # Written by Scott James Remnant, 2004.
5 | #
6 | # This file is free software; the Free Software Foundation gives
7 | # unlimited permission to copy and/or distribute it, with or without
8 | # modifications, as long as this notice is preserved.
9 |
10 | # serial 5 lt~obsolete.m4
11 |
12 | # These exist entirely to fool aclocal when bootstrapping libtool.
13 | #
14 | # In the past libtool.m4 has provided macros via AC_DEFUN (or AU_DEFUN)
15 | # which have later been changed to m4_define as they aren't part of the
16 | # exported API, or moved to Autoconf or Automake where they belong.
17 | #
18 | # The trouble is, aclocal is a bit thick. It'll see the old AC_DEFUN
19 | # in /usr/share/aclocal/libtool.m4 and remember it, then when it sees us
20 | # using a macro with the same name in our local m4/libtool.m4 it'll
21 | # pull the old libtool.m4 in (it doesn't see our shiny new m4_define
22 | # and doesn't know about Autoconf macros at all.)
23 | #
24 | # So we provide this file, which has a silly filename so it's always
25 | # included after everything else. This provides aclocal with the
26 | # AC_DEFUNs it wants, but when m4 processes it, it doesn't do anything
27 | # because those macros already exist, or will be overwritten later.
28 | # We use AC_DEFUN over AU_DEFUN for compatibility with aclocal-1.6.
29 | #
30 | # Anytime we withdraw an AC_DEFUN or AU_DEFUN, remember to add it here.
31 | # Yes, that means every name once taken will need to remain here until
32 | # we give up compatibility with versions before 1.7, at which point
33 | # we need to keep only those names which we still refer to.
34 |
35 | # This is to help aclocal find these macros, as it can't see m4_define.
36 | AC_DEFUN([LTOBSOLETE_VERSION], [m4_if([1])])
37 |
38 | m4_ifndef([AC_LIBTOOL_LINKER_OPTION], [AC_DEFUN([AC_LIBTOOL_LINKER_OPTION])])
39 | m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP])])
40 | m4_ifndef([_LT_AC_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH])])
41 | m4_ifndef([_LT_AC_SHELL_INIT], [AC_DEFUN([_LT_AC_SHELL_INIT])])
42 | m4_ifndef([_LT_AC_SYS_LIBPATH_AIX], [AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX])])
43 | m4_ifndef([_LT_PROG_LTMAIN], [AC_DEFUN([_LT_PROG_LTMAIN])])
44 | m4_ifndef([_LT_AC_TAGVAR], [AC_DEFUN([_LT_AC_TAGVAR])])
45 | m4_ifndef([AC_LTDL_ENABLE_INSTALL], [AC_DEFUN([AC_LTDL_ENABLE_INSTALL])])
46 | m4_ifndef([AC_LTDL_PREOPEN], [AC_DEFUN([AC_LTDL_PREOPEN])])
47 | m4_ifndef([_LT_AC_SYS_COMPILER], [AC_DEFUN([_LT_AC_SYS_COMPILER])])
48 | m4_ifndef([_LT_AC_LOCK], [AC_DEFUN([_LT_AC_LOCK])])
49 | m4_ifndef([AC_LIBTOOL_SYS_OLD_ARCHIVE], [AC_DEFUN([AC_LIBTOOL_SYS_OLD_ARCHIVE])])
50 | m4_ifndef([_LT_AC_TRY_DLOPEN_SELF], [AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF])])
51 | m4_ifndef([AC_LIBTOOL_PROG_CC_C_O], [AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O])])
52 | m4_ifndef([AC_LIBTOOL_SYS_HARD_LINK_LOCKS], [AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS])])
53 | m4_ifndef([AC_LIBTOOL_OBJDIR], [AC_DEFUN([AC_LIBTOOL_OBJDIR])])
54 | m4_ifndef([AC_LTDL_OBJDIR], [AC_DEFUN([AC_LTDL_OBJDIR])])
55 | m4_ifndef([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH], [AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH])])
56 | m4_ifndef([AC_LIBTOOL_SYS_LIB_STRIP], [AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP])])
57 | m4_ifndef([AC_PATH_MAGIC], [AC_DEFUN([AC_PATH_MAGIC])])
58 | m4_ifndef([AC_PROG_LD_GNU], [AC_DEFUN([AC_PROG_LD_GNU])])
59 | m4_ifndef([AC_PROG_LD_RELOAD_FLAG], [AC_DEFUN([AC_PROG_LD_RELOAD_FLAG])])
60 | m4_ifndef([AC_DEPLIBS_CHECK_METHOD], [AC_DEFUN([AC_DEPLIBS_CHECK_METHOD])])
61 | m4_ifndef([AC_LIBTOOL_PROG_COMPILER_NO_RTTI], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI])])
62 | m4_ifndef([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE], [AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE])])
63 | m4_ifndef([AC_LIBTOOL_PROG_COMPILER_PIC], [AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC])])
64 | m4_ifndef([AC_LIBTOOL_PROG_LD_SHLIBS], [AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS])])
65 | m4_ifndef([AC_LIBTOOL_POSTDEP_PREDEP], [AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP])])
66 | m4_ifndef([LT_AC_PROG_EGREP], [AC_DEFUN([LT_AC_PROG_EGREP])])
67 | m4_ifndef([LT_AC_PROG_SED], [AC_DEFUN([LT_AC_PROG_SED])])
68 | m4_ifndef([_LT_CC_BASENAME], [AC_DEFUN([_LT_CC_BASENAME])])
69 | m4_ifndef([_LT_COMPILER_BOILERPLATE], [AC_DEFUN([_LT_COMPILER_BOILERPLATE])])
70 | m4_ifndef([_LT_LINKER_BOILERPLATE], [AC_DEFUN([_LT_LINKER_BOILERPLATE])])
71 | m4_ifndef([_AC_PROG_LIBTOOL], [AC_DEFUN([_AC_PROG_LIBTOOL])])
72 | m4_ifndef([AC_LIBTOOL_SETUP], [AC_DEFUN([AC_LIBTOOL_SETUP])])
73 | m4_ifndef([_LT_AC_CHECK_DLFCN], [AC_DEFUN([_LT_AC_CHECK_DLFCN])])
74 | m4_ifndef([AC_LIBTOOL_SYS_DYNAMIC_LINKER], [AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER])])
75 | m4_ifndef([_LT_AC_TAGCONFIG], [AC_DEFUN([_LT_AC_TAGCONFIG])])
76 | m4_ifndef([AC_DISABLE_FAST_INSTALL], [AC_DEFUN([AC_DISABLE_FAST_INSTALL])])
77 | m4_ifndef([_LT_AC_LANG_CXX], [AC_DEFUN([_LT_AC_LANG_CXX])])
78 | m4_ifndef([_LT_AC_LANG_F77], [AC_DEFUN([_LT_AC_LANG_F77])])
79 | m4_ifndef([_LT_AC_LANG_GCJ], [AC_DEFUN([_LT_AC_LANG_GCJ])])
80 | m4_ifndef([AC_LIBTOOL_LANG_C_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG])])
81 | m4_ifndef([_LT_AC_LANG_C_CONFIG], [AC_DEFUN([_LT_AC_LANG_C_CONFIG])])
82 | m4_ifndef([AC_LIBTOOL_LANG_CXX_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG])])
83 | m4_ifndef([_LT_AC_LANG_CXX_CONFIG], [AC_DEFUN([_LT_AC_LANG_CXX_CONFIG])])
84 | m4_ifndef([AC_LIBTOOL_LANG_F77_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG])])
85 | m4_ifndef([_LT_AC_LANG_F77_CONFIG], [AC_DEFUN([_LT_AC_LANG_F77_CONFIG])])
86 | m4_ifndef([AC_LIBTOOL_LANG_GCJ_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG])])
87 | m4_ifndef([_LT_AC_LANG_GCJ_CONFIG], [AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG])])
88 | m4_ifndef([AC_LIBTOOL_LANG_RC_CONFIG], [AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG])])
89 | m4_ifndef([_LT_AC_LANG_RC_CONFIG], [AC_DEFUN([_LT_AC_LANG_RC_CONFIG])])
90 | m4_ifndef([AC_LIBTOOL_CONFIG], [AC_DEFUN([AC_LIBTOOL_CONFIG])])
91 | m4_ifndef([_LT_AC_FILE_LTDLL_C], [AC_DEFUN([_LT_AC_FILE_LTDLL_C])])
92 | m4_ifndef([_LT_REQUIRED_DARWIN_CHECKS], [AC_DEFUN([_LT_REQUIRED_DARWIN_CHECKS])])
93 | m4_ifndef([_LT_AC_PROG_CXXCPP], [AC_DEFUN([_LT_AC_PROG_CXXCPP])])
94 | m4_ifndef([_LT_PREPARE_SED_QUOTE_VARS], [AC_DEFUN([_LT_PREPARE_SED_QUOTE_VARS])])
95 | m4_ifndef([_LT_PROG_ECHO_BACKSLASH], [AC_DEFUN([_LT_PROG_ECHO_BACKSLASH])])
96 | m4_ifndef([_LT_PROG_F77], [AC_DEFUN([_LT_PROG_F77])])
97 | m4_ifndef([_LT_PROG_FC], [AC_DEFUN([_LT_PROG_FC])])
98 | m4_ifndef([_LT_PROG_CXX], [AC_DEFUN([_LT_PROG_CXX])])
99 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/native-package/m4/jni.m4:
--------------------------------------------------------------------------------
1 | dnl ---------------------------------------------------------------------------
2 | dnl Copyright (C) 2009-2011 FuseSource Corp.
3 | dnl http://fusesource.com
4 | dnl
5 | dnl Licensed under the Apache License, Version 2.0 (the "License");
6 | dnl you may not use this file except in compliance with the License.
7 | dnl You may obtain a copy of the License at
8 | dnl
9 | dnl http://www.apache.org/licenses/LICENSE-2.0
10 | dnl
11 | dnl Unless required by applicable law or agreed to in writing, software
12 | dnl distributed under the License is distributed on an "AS IS" BASIS,
13 | dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | dnl See the License for the specific language governing permissions and
15 | dnl limitations under the License.
16 | dnl ---------------------------------------------------------------------------
17 | dnl ---------------------------------------------------------------------------
18 | dnl SYNOPSIS:
19 | dnl
20 | dnl WITH_JNI_JDK()
21 | dnl
22 | dnl Adds the --with-jni-jdk=PATH option. If not provided, it searches
23 | dnl for the JDK in the default OS locations.
24 | dnl
25 | dnl This macro calls:
26 | dnl AC_SUBST(JNI_JDK)
27 | dnl AC_SUBST(JNI_EXTRA_CFLAGS)
28 | dnl AC_SUBST(JNI_EXTRA_LDFLAGS)
29 | dnl
30 | dnl AUTHOR: Hiram Chrino
31 | dnl ---------------------------------------------------------------------------
32 |
33 | AC_DEFUN([WITH_JNI_JDK],
34 | [
35 | AC_PREREQ([2.61])
36 | AC_ARG_WITH(jni-jdk,
37 | [AS_HELP_STRING([--with-jni-jdk=PATH],
38 | [Location of the Java Development Kit. Defaults to your JAVA_HOME setting and falls back to where it is typically installed on your OS])],
39 | [
40 | if test "$withval" = "no" || test "$withval" = "yes"; then
41 | AC_MSG_ERROR([--with-jni-jdk: PATH to JDK not supplied])
42 | fi
43 | CHECK_JNI_JDK([$withval], [], [AC_MSG_ERROR([JDK not found. Invalid --with-jni-jdk PATH])])
44 | ],[
45 |
46 | if test -n "$JAVA_HOME" ; then
47 | AC_MSG_NOTICE([JAVA_HOME was set, checking to see if it's a JDK we can use...])
48 | CHECK_JNI_JDK([$JAVA_HOME], [], [])
49 | fi
50 |
51 | __JNI_GUESS=`which javac`
52 | AS_IF(test -z "$JNI_JDK" && test -n "$__JNI_GUESS", [
53 | AC_MSG_NOTICE([javac was on your path, checking to see if it's part of a JDK we can use...])
54 | # transitively resolve the symbolic links to javac
55 | while file -h "$__JNI_GUESS" 2>/dev/null | grep " symbolic link to " >/dev/null; do
56 | __JNI_LINK=$( file -h $__JNI_GUESS | sed 's/.*symbolic link to //' | sed "s/'$//" | sed 's/^`//' )
57 | __JNI_GUESS=$(cd $(dirname $__JNI_GUESS); cd $(dirname $__JNI_LINK); echo "$(pwd)/$(basename $__JNI_LINK)")
58 | done
59 | # move 2 dirs up to the home dir...
60 | __JNI_GUESS=$(dirname $(dirname $__JNI_GUESS))
61 | CHECK_JNI_JDK([$__JNI_GUESS], [], [],[])
62 | ],[])
63 |
64 | AS_IF(test -z "$JNI_JDK", [
65 | case "$host_os" in
66 | darwin*) __JNI_GUESS="/System/Library/Frameworks/JavaVM.framework";;
67 | *) __JNI_GUESS="/usr";;
68 | esac
69 | AC_MSG_NOTICE([Taking a guess as to where your OS installs the JDK by default...])
70 | CHECK_JNI_JDK([$__JNI_GUESS], [], [AC_MSG_ERROR([JDK not found. Please use the --with-jni-jdk option])])
71 | ],[])
72 | ])
73 | ])
74 |
75 | dnl ---------------------------------------------------------------------------
76 | dnl
77 | dnl JNI_CHECK_JDK_HOME(PATH, [ACTION-SUCCESS], [ACTION-FAILURE])
78 | dnl
79 | dnl Tests to see if the given path is a valid JDK home location with
80 | dnl with a JNI headers and library that can be compiled against.
81 | dnl
82 | dnl This macro calls:
83 | dnl
84 | dnl AC_SUBST(JNI_JDK)
85 | dnl AC_SUBST(JNI_EXTRA_CFLAGS)
86 | dnl AC_SUBST(JNI_EXTRA_LDFLAGS)
87 | dnl
88 | dnl AUTHOR: Hiram Chrino
89 | dnl ---------------------------------------------------------------------------
90 | AC_DEFUN([CHECK_JNI_JDK],[
91 | AC_PREREQ([2.61])
92 | __JNI_JDK_HOME="$1"
93 | AC_MSG_CHECKING(if '$__JNI_JDK_HOME' is a JDK)
94 |
95 | __JNI_INCLUDE="$__JNI_JDK_HOME/include"
96 |
97 | # OSX had to be a little different.
98 | AS_IF(test -r "$__JNI_JDK_HOME/Headers/jni.h",[
99 | __JNI_INCLUDE="$__JNI_JDK_HOME/Headers"
100 | ])
101 |
102 | AS_IF(test -r "$__JNI_INCLUDE/jni.h",[
103 |
104 | AS_IF(test -r "$__JNI_JDK_HOME/Headers/jni.h",[
105 | __JNI_INCLUDE="$__JNI_JDK_HOME/Headers"
106 | ])
107 |
108 | # Also include the os specific include dirs in the JNI_CFLAGS
109 | __JNI_CFLAGS="-I$__JNI_INCLUDE"
110 | case "$host_os" in
111 | bsdi*) __JNI_INCLUDE_EXTRAS="bsdos";;
112 | linux*) __JNI_INCLUDE_EXTRAS="linux genunix";;
113 | osf*) __JNI_INCLUDE_EXTRAS="alpha";;
114 | solaris*) __JNI_INCLUDE_EXTRAS="solaris";;
115 | mingw*) __JNI_INCLUDE_EXTRAS="win32";;
116 | cygwin*) __JNI_INCLUDE_EXTRAS="win32";;
117 | darwin*) __JNI_INCLUDE_EXTRAS="darwin";;
118 | *) __JNI_INCLUDE_EXTRAS="genunix";;
119 | esac
120 |
121 | for f in $__JNI_INCLUDE_EXTRAS ; do
122 | if test -d "$__JNI_INCLUDE/$f"; then
123 | __JNI_CFLAGS="$__JNI_CFLAGS -I$__JNI_INCLUDE/$f"
124 | fi
125 | done
126 |
127 | saved_CPPFLAGS="$CPPFLAGS"
128 | CPPFLAGS="$CPPFLAGS $__JNI_CFLAGS"
129 | JNI_VERSION="1_2"
130 | AC_LANG_PUSH(C)
131 |
132 | AC_COMPILE_IFELSE(
133 | [AC_LANG_PROGRAM([[@%:@include ]],[[
134 | #ifndef JNI_VERSION_$JNI_VERSION
135 | # error JNI version $JNI_VERSION is not supported.
136 | #endif
137 | ]])
138 | ],[
139 |
140 | JNI_JDK=$"$__JNI_JDK_HOME"
141 | JNI_EXTRA_CFLAGS="$__JNI_CFLAGS"
142 | AC_SUBST(JNI_JDK)
143 | AC_SUBST(JNI_EXTRA_CFLAGS)
144 | case $host_os in
145 | darwin*)
146 | JNI_EXTRA_LDFLAGS="-shrext .jnilib -dynamiclib" ;;
147 | esac
148 | AC_SUBST(JNI_EXTRA_LDFLAGS)
149 |
150 | AC_MSG_RESULT([yes])
151 | $2
152 | ],[
153 | AC_MSG_RESULT([no])
154 | $3
155 | ])
156 | AC_LANG_POP()
157 | CPPFLAGS="$saved_CPPFLAGS"
158 | ],[
159 | AC_MSG_RESULT([no])
160 | $3
161 | ])
162 | ])
163 |
164 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/java/org/fusesource/rocksdbjni/internal/NativeComparator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011, FuseSource Corp. All rights reserved.
3 | *
4 | * http://fusesource.com
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are
8 | * met:
9 | *
10 | * * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above
13 | * copyright notice, this list of conditions and the following disclaimer
14 | * in the documentation and/or other materials provided with the
15 | * distribution.
16 | * * Neither the name of FuseSource Corp. nor the names of its
17 | * contributors may be used to endorse or promote products derived from
18 | * this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.fusesource.rocksdbjni.internal;
33 |
34 | import org.fusesource.hawtjni.runtime.*;
35 |
36 | import static org.fusesource.hawtjni.runtime.FieldFlag.*;
37 | import static org.fusesource.hawtjni.runtime.MethodFlag.*;
38 | import static org.fusesource.hawtjni.runtime.ArgFlag.*;
39 | import static org.fusesource.hawtjni.runtime.ClassFlag.*;
40 |
41 | /**
42 | *
43 | * Provides a java interface to the C++ rocksdb::Comparator class.
44 | *
45 | *
46 | * @author Hiram Chirino
47 | */
48 | public abstract class NativeComparator extends NativeObject {
49 |
50 | @JniClass(name="JNIComparator", flags={STRUCT, CPP})
51 | static public class ComparatorJNI {
52 |
53 | static {
54 | NativeDB.LIBRARY.load();
55 | init();
56 | }
57 |
58 | @JniMethod(flags={CPP_NEW})
59 | public static final native long create();
60 | @JniMethod(flags={CPP_DELETE})
61 | public static final native void delete(long ptr);
62 |
63 | public static final native void memmove (
64 | @JniArg(cast="void *") long dest,
65 | @JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) ComparatorJNI src,
66 | @JniArg(cast="size_t") long size);
67 |
68 | public static final native void memmove (
69 | @JniArg(cast="void *", flags={NO_IN, CRITICAL}) ComparatorJNI dest,
70 | @JniArg(cast="const void *") long src,
71 | @JniArg(cast="size_t") long size);
72 |
73 | @JniField(cast="jobject", flags={POINTER_FIELD})
74 | long target;
75 |
76 | @JniField(cast="jmethodID", flags={POINTER_FIELD})
77 | long compare_method;
78 |
79 | @JniField(cast="const char *")
80 | long name;
81 |
82 | @JniMethod(flags={CONSTANT_INITIALIZER})
83 | private static final native void init();
84 |
85 | @JniField(flags={CONSTANT}, accessor="sizeof(struct JNIComparator)")
86 | static int SIZEOF;
87 |
88 | @JniField(flags={CONSTANT}, cast="const Comparator*", accessor="rocksdb::BytewiseComparator()")
89 | private static long BYTEWISE_COMPARATOR;
90 |
91 | }
92 |
93 | private NativeBuffer name_buffer;
94 | private long globalRef;
95 |
96 | public NativeComparator() {
97 | super(ComparatorJNI.create());
98 | try {
99 | name_buffer = NativeBuffer.create(name());
100 | globalRef = NativeDB.DBJNI.NewGlobalRef(this);
101 | if( globalRef==0 ) {
102 | throw new RuntimeException("jni call failed: NewGlobalRef");
103 | }
104 | ComparatorJNI struct = new ComparatorJNI();
105 | struct.compare_method = NativeDB.DBJNI.GetMethodID(this.getClass(), "compare", "(JJ)I");
106 | if( struct.compare_method==0 ) {
107 | throw new RuntimeException("jni call failed: GetMethodID");
108 | }
109 | struct.target = globalRef;
110 | struct.name = name_buffer.pointer();
111 | ComparatorJNI.memmove(self, struct, ComparatorJNI.SIZEOF);
112 |
113 | } catch (RuntimeException e) {
114 | delete();
115 | throw e;
116 | }
117 | }
118 |
119 | public static final NativeComparator BYTEWISE_COMPARATOR = new NativeComparator(ComparatorJNI.BYTEWISE_COMPARATOR) {
120 | @Override
121 | public void delete() {
122 | // we won't really delete this one since it's static.
123 | }
124 | @Override
125 | public int compare(byte[] key1, byte[] key2) {
126 | throw new UnsupportedOperationException();
127 | }
128 | @Override
129 | public String name() {
130 | throw new UnsupportedOperationException();
131 | }
132 | };
133 |
134 | NativeComparator(long ptr) {
135 | super(ptr);
136 | }
137 |
138 | public void delete() {
139 | if( name_buffer!=null ) {
140 | name_buffer.delete();
141 | name_buffer = null;
142 | }
143 | if( globalRef!=0 ) {
144 | NativeDB.DBJNI.DeleteGlobalRef(globalRef);
145 | globalRef = 0;
146 | }
147 | }
148 |
149 | private int compare(long ptr1, long ptr2) {
150 | NativeSlice s1 = new NativeSlice();
151 | s1.read(ptr1, 0);
152 | NativeSlice s2 = new NativeSlice();
153 | s2.read(ptr2, 0);
154 | return compare(s1.toByteArray(), s2.toByteArray());
155 | }
156 |
157 | public abstract int compare(byte[] key1, byte[] key2);
158 | public abstract String name();
159 |
160 | }
161 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/java/org/fusesource/rocksdbjni/internal/NativeIterator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011, FuseSource Corp. All rights reserved.
3 | *
4 | * http://fusesource.com
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are
8 | * met:
9 | *
10 | * * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above
13 | * copyright notice, this list of conditions and the following disclaimer
14 | * in the documentation and/or other materials provided with the
15 | * distribution.
16 | * * Neither the name of FuseSource Corp. nor the names of its
17 | * contributors may be used to endorse or promote products derived from
18 | * this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.fusesource.rocksdbjni.internal;
33 |
34 | import org.fusesource.hawtjni.runtime.*;
35 |
36 | import static org.fusesource.hawtjni.runtime.MethodFlag.*;
37 | import static org.fusesource.hawtjni.runtime.ArgFlag.*;
38 | import static org.fusesource.hawtjni.runtime.ClassFlag.*;
39 |
40 | /**
41 | * Provides a java interface to the C++ rocksdb::Iterator class.
42 | *
43 | * @author Hiram Chirino
44 | */
45 | public class NativeIterator extends NativeObject {
46 |
47 | @JniClass(name="rocksdb::Iterator", flags={CPP})
48 | private static class IteratorJNI {
49 | static {
50 | NativeDB.LIBRARY.load();
51 | }
52 |
53 | @JniMethod(flags={CPP_DELETE})
54 | public static final native void delete(
55 | long self
56 | );
57 |
58 | @JniMethod(flags={CPP_METHOD})
59 | static final native boolean Valid(
60 | long self
61 | );
62 |
63 | @JniMethod(flags={CPP_METHOD})
64 | static final native void SeekToFirst(
65 | long self
66 | );
67 |
68 | @JniMethod(flags={CPP_METHOD})
69 | static final native void SeekToLast(
70 | long self
71 | );
72 |
73 | @JniMethod(flags={CPP_METHOD})
74 | static final native void Seek(
75 | long self,
76 | @JniArg(flags={BY_VALUE, NO_OUT}) NativeSlice target
77 | );
78 |
79 | @JniMethod(flags={CPP_METHOD})
80 | static final native void Next(
81 | long self
82 | );
83 |
84 | @JniMethod(flags={CPP_METHOD})
85 | static final native void Prev(
86 | long self
87 | );
88 |
89 | @JniMethod(copy="rocksdb::Slice", flags={CPP_METHOD})
90 | static final native long key(
91 | long self
92 | );
93 |
94 | @JniMethod(copy="rocksdb::Slice", flags={CPP_METHOD})
95 | static final native long value(
96 | long self
97 | );
98 |
99 | @JniMethod(copy="rocksdb::Status", flags={CPP_METHOD})
100 | static final native long status(
101 | long self
102 | );
103 | }
104 |
105 | NativeIterator(long self) {
106 | super(self);
107 | }
108 |
109 | public void delete() {
110 | assertAllocated();
111 | IteratorJNI.delete(self);
112 | self = 0;
113 | }
114 |
115 | public boolean isValid() {
116 | assertAllocated();
117 | return IteratorJNI.Valid(self);
118 | }
119 |
120 | private void checkStatus() throws NativeDB.DBException {
121 | NativeDB.checkStatus(IteratorJNI.status(self));
122 | }
123 |
124 | public void seekToFirst() {
125 | assertAllocated();
126 | IteratorJNI.SeekToFirst(self);
127 | }
128 |
129 | public void seekToLast() {
130 | assertAllocated();
131 | IteratorJNI.SeekToLast(self);
132 | }
133 |
134 | public void seek(byte[] key) throws NativeDB.DBException {
135 | NativeDB.checkArgNotNull(key, "key");
136 | NativeBuffer keyBuffer = NativeBuffer.create(key);
137 | try {
138 | seek(keyBuffer);
139 | } finally {
140 | keyBuffer.delete();
141 | }
142 | }
143 |
144 | private void seek(NativeBuffer keyBuffer) throws NativeDB.DBException {
145 | seek(new NativeSlice(keyBuffer));
146 | }
147 |
148 | private void seek(NativeSlice keySlice) throws NativeDB.DBException {
149 | assertAllocated();
150 | IteratorJNI.Seek(self, keySlice);
151 | checkStatus();
152 | }
153 |
154 | public void next() throws NativeDB.DBException {
155 | assertAllocated();
156 | IteratorJNI.Next(self);
157 | checkStatus();
158 | }
159 |
160 | public void prev() throws NativeDB.DBException {
161 | assertAllocated();
162 | IteratorJNI.Prev(self);
163 | checkStatus();
164 | }
165 |
166 | public byte[] key() throws NativeDB.DBException {
167 | assertAllocated();
168 | long slice_ptr = IteratorJNI.key(self);
169 | checkStatus();
170 | try {
171 | NativeSlice slice = new NativeSlice();
172 | slice.read(slice_ptr, 0);
173 | return slice.toByteArray();
174 | } finally {
175 | NativeSlice.SliceJNI.delete(slice_ptr);
176 | }
177 | }
178 |
179 | public byte[] value() throws NativeDB.DBException {
180 | assertAllocated();
181 | long slice_ptr = IteratorJNI.value(self);
182 | checkStatus();
183 | try {
184 | NativeSlice slice = new NativeSlice();
185 | slice.read(slice_ptr, 0);
186 | return slice.toByteArray();
187 | } finally {
188 | NativeSlice.SliceJNI.delete(slice_ptr);
189 | }
190 | }
191 | }
192 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/native-package/autotools/ar-lib:
--------------------------------------------------------------------------------
1 | #! /bin/sh
2 | # Wrapper for Microsoft lib.exe
3 |
4 | me=ar-lib
5 | scriptversion=2012-03-01.08; # UTC
6 |
7 | # Copyright (C) 2010-2013 Free Software Foundation, Inc.
8 | # Written by Peter Rosin .
9 | #
10 | # This program is free software; you can redistribute it and/or modify
11 | # it under the terms of the GNU General Public License as published by
12 | # the Free Software Foundation; either version 2, or (at your option)
13 | # any later version.
14 | #
15 | # This program is distributed in the hope that it will be useful,
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 | # GNU General Public License for more details.
19 | #
20 | # You should have received a copy of the GNU General Public License
21 | # along with this program. If not, see .
22 |
23 | # As a special exception to the GNU General Public License, if you
24 | # distribute this file as part of a program that contains a
25 | # configuration script generated by Autoconf, you may include it under
26 | # the same distribution terms that you use for the rest of that program.
27 |
28 | # This file is maintained in Automake, please report
29 | # bugs to or send patches to
30 | # .
31 |
32 |
33 | # func_error message
34 | func_error ()
35 | {
36 | echo "$me: $1" 1>&2
37 | exit 1
38 | }
39 |
40 | file_conv=
41 |
42 | # func_file_conv build_file
43 | # Convert a $build file to $host form and store it in $file
44 | # Currently only supports Windows hosts.
45 | func_file_conv ()
46 | {
47 | file=$1
48 | case $file in
49 | / | /[!/]*) # absolute file, and not a UNC file
50 | if test -z "$file_conv"; then
51 | # lazily determine how to convert abs files
52 | case `uname -s` in
53 | MINGW*)
54 | file_conv=mingw
55 | ;;
56 | CYGWIN*)
57 | file_conv=cygwin
58 | ;;
59 | *)
60 | file_conv=wine
61 | ;;
62 | esac
63 | fi
64 | case $file_conv in
65 | mingw)
66 | file=`cmd //C echo "$file " | sed -e 's/"\(.*\) " *$/\1/'`
67 | ;;
68 | cygwin)
69 | file=`cygpath -m "$file" || echo "$file"`
70 | ;;
71 | wine)
72 | file=`winepath -w "$file" || echo "$file"`
73 | ;;
74 | esac
75 | ;;
76 | esac
77 | }
78 |
79 | # func_at_file at_file operation archive
80 | # Iterate over all members in AT_FILE performing OPERATION on ARCHIVE
81 | # for each of them.
82 | # When interpreting the content of the @FILE, do NOT use func_file_conv,
83 | # since the user would need to supply preconverted file names to
84 | # binutils ar, at least for MinGW.
85 | func_at_file ()
86 | {
87 | operation=$2
88 | archive=$3
89 | at_file_contents=`cat "$1"`
90 | eval set x "$at_file_contents"
91 | shift
92 |
93 | for member
94 | do
95 | $AR -NOLOGO $operation:"$member" "$archive" || exit $?
96 | done
97 | }
98 |
99 | case $1 in
100 | '')
101 | func_error "no command. Try '$0 --help' for more information."
102 | ;;
103 | -h | --h*)
104 | cat <Hiram Chirino
48 | */
49 | @JniClass(name="rocksdb::Options", flags={STRUCT, CPP})
50 | public class NativeOptions {
51 |
52 | static {
53 | NativeDB.LIBRARY.load();
54 | init();
55 | }
56 |
57 | @JniMethod(flags={CONSTANT_INITIALIZER})
58 | private static final native void init();
59 |
60 | @JniField(flags={CONSTANT}, cast="Env*", accessor="rocksdb::Env::Default()")
61 | private static long DEFAULT_ENV;
62 |
63 | private boolean create_if_missing = false;
64 | private boolean error_if_exists = false;
65 | private boolean paranoid_checks = false;
66 | @JniField(cast="size_t")
67 | private long write_buffer_size = 4 << 20;
68 | @JniField(cast="size_t")
69 | private long block_size = 4086;
70 | private int max_open_files = 1000;
71 | private int block_restart_interval = 16;
72 |
73 | @JniField(flags={FIELD_SKIP})
74 | private NativeComparator comparatorObject = NativeComparator.BYTEWISE_COMPARATOR;
75 | @JniField(cast="const rocksdb::Comparator*")
76 | private long comparator = comparatorObject.pointer();
77 |
78 | @JniField(flags={FIELD_SKIP})
79 | private NativeLogger infoLogObject = null;
80 | // @JniField(cast="rocksdb::Logger*")
81 | // private long info_log = 0;
82 |
83 | @JniField(cast="rocksdb::Env*")
84 | private long env = DEFAULT_ENV;
85 |
86 | @JniField(cast="rocksdb::CompressionType")
87 | private int compression = NativeCompressionType.kSnappyCompression.value;
88 |
89 | public NativeOptions createIfMissing(boolean value) {
90 | this.create_if_missing = value;
91 | return this;
92 | }
93 | public boolean createIfMissing() {
94 | return create_if_missing;
95 | }
96 |
97 | public NativeOptions errorIfExists(boolean value) {
98 | this.error_if_exists = value;
99 | return this;
100 | }
101 | public boolean errorIfExists() {
102 | return error_if_exists;
103 | }
104 |
105 | public NativeOptions paranoidChecks(boolean value) {
106 | this.paranoid_checks = value;
107 | return this;
108 | }
109 | public boolean paranoidChecks() {
110 | return paranoid_checks;
111 | }
112 |
113 | public NativeOptions writeBufferSize(long value) {
114 | this.write_buffer_size = value;
115 | return this;
116 | }
117 | public long writeBufferSize() {
118 | return write_buffer_size;
119 | }
120 |
121 | public NativeOptions maxOpenFiles(int value) {
122 | this.max_open_files = value;
123 | return this;
124 | }
125 | public int maxOpenFiles() {
126 | return max_open_files;
127 | }
128 |
129 | public NativeOptions blockRestartInterval(int value) {
130 | this.block_restart_interval = value;
131 | return this;
132 | }
133 | public int blockRestartInterval() {
134 | return block_restart_interval;
135 | }
136 |
137 | public NativeOptions blockSize(long value) {
138 | this.block_size = value;
139 | return this;
140 | }
141 | public long blockSize() {
142 | return block_size;
143 | }
144 |
145 | // @JniField(cast="Env*")
146 | // private long env = DEFAULT_ENV;
147 |
148 | public NativeComparator comparator() {
149 | return comparatorObject;
150 | }
151 |
152 | public NativeOptions comparator(NativeComparator comparator) {
153 | if( comparator==null ) {
154 | throw new IllegalArgumentException("comparator cannot be null");
155 | }
156 | this.comparatorObject = comparator;
157 | this.comparator = comparator.pointer();
158 | return this;
159 | }
160 |
161 | public NativeLogger infoLog() {
162 | return infoLogObject;
163 | }
164 |
165 | public NativeOptions infoLog(NativeLogger logger) {
166 | this.infoLogObject = logger;
167 | // if( logger ==null ) {
168 | // this.info_log = 0;
169 | // } else {
170 | // this.info_log = logger.pointer();
171 | // }
172 | return this;
173 | }
174 |
175 | public NativeCompressionType compression() {
176 | if(compression == NativeCompressionType.kNoCompression.value) {
177 | return NativeCompressionType.kNoCompression;
178 | } else if(compression == NativeCompressionType.kSnappyCompression.value) {
179 | return NativeCompressionType.kSnappyCompression;
180 | } else {
181 | return NativeCompressionType.kSnappyCompression;
182 | }
183 | }
184 |
185 | public NativeOptions compression(NativeCompressionType compression) {
186 | this.compression = compression.value;
187 | return this;
188 | }
189 |
190 | }
191 |
--------------------------------------------------------------------------------
/rocksdbjni/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
33 |
34 |
35 | 4.0.0
36 |
37 | org.fusesource.rocksdbjni
38 | rocksdbjni-project
39 | 99-master-SNAPSHOT
40 |
41 |
42 | org.fusesource.rocksdbjni
43 | rocksdbjni
44 | 99-master-SNAPSHOT
45 | jar
46 |
47 | ${project.artifactId}
48 | rocksdbjni is a jni library for acessing rocksdb.
49 |
50 |
51 | false
52 |
53 |
54 |
55 |
56 | org.fusesource.hawtjni
57 | hawtjni-runtime
58 | ${hawtjni-version}
59 |
60 |
61 | org.iq80.leveldb
62 | leveldb-api
63 | ${leveldb-api-version}
64 |
65 |
66 |
67 |
68 |
69 |
70 | ${project.basedir}/src/main/resources
71 | true
72 |
73 | **/*
74 |
75 |
76 |
77 |
78 |
79 |
80 | org.apache.maven.plugins
81 | maven-jar-plugin
82 |
83 |
84 |
85 | test-jar
86 |
87 |
88 |
89 |
90 |
91 |
92 | org.fusesource.hawtjni
93 | maven-hawtjni-plugin
94 | ${hawtjni-version}
95 |
96 |
97 |
98 | generate
99 | package-source
100 |
101 |
102 |
103 |
104 | ${skipAutogen}
105 | rocksdbjni
106 | false
107 |
118 |
119 |
120 |
121 |
122 | org.apache.maven.plugins
123 | maven-surefire-plugin
124 | 2.4.3
125 |
126 | true
127 | once
128 | -ea
129 | false
130 | ${project.build.directory}
131 |
132 | **/*
133 |
134 |
135 | **/*Test.java
136 |
137 |
138 |
139 |
140 |
141 | org.apache.maven.plugins
142 | maven-compiler-plugin
143 |
144 | 1.5
145 | 1.5
146 |
147 |
148 |
149 |
150 | org.apache.felix
151 | maven-bundle-plugin
152 | 2.0.1
153 |
154 |
155 | bundle-manifest
156 | process-classes
157 |
158 | manifest
159 |
160 |
161 |
162 | !org.fusesource.rocksdbjni*,!org.fusesource.hawtjni*,sun.reflect;resolution:=optional,*
163 |
164 |
165 |
166 |
167 |
168 |
169 | maven-jar-plugin
170 |
171 |
172 | ${project.build.outputDirectory}/META-INF/MANIFEST.MF
173 |
174 |
175 |
176 |
177 | org.apache.maven.plugins
178 | maven-source-plugin
179 | 2.2.1
180 |
181 |
182 | attach-sources
183 | package
184 |
185 | jar-no-fork
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/java/org/fusesource/rocksdbjni/JniDBFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011, FuseSource Corp. All rights reserved.
3 | *
4 | * http://fusesource.com
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are
8 | * met:
9 | *
10 | * * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above
13 | * copyright notice, this list of conditions and the following disclaimer
14 | * in the documentation and/or other materials provided with the
15 | * distribution.
16 | * * Neither the name of FuseSource Corp. nor the names of its
17 | * contributors may be used to endorse or promote products derived from
18 | * this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.fusesource.rocksdbjni;
33 |
34 | import org.fusesource.rocksdbjni.internal.*;
35 | import org.iq80.leveldb.*;
36 |
37 | import java.io.*;
38 | import java.net.URL;
39 | import java.util.concurrent.Callable;
40 |
41 | /**
42 | * @author Hiram Chirino
43 | */
44 | public class JniDBFactory implements DBFactory {
45 |
46 | public static final JniDBFactory factory = new JniDBFactory();
47 | static {
48 | NativeDB.LIBRARY.load();
49 | }
50 |
51 | public static final String VERSION;
52 | static {
53 | String v="unknown";
54 | InputStream is = JniDBFactory.class.getResourceAsStream("version.txt");
55 | try {
56 | v = new BufferedReader(new InputStreamReader(is, "UTF-8")).readLine();
57 | } catch (Throwable e) {
58 | } finally {
59 | try {
60 | is.close();
61 | } catch (Throwable e) {
62 | }
63 | }
64 | VERSION = v;
65 | }
66 |
67 | public static byte[] bytes(String value) {
68 | if( value == null) {
69 | return null;
70 | }
71 | try {
72 | return value.getBytes("UTF-8");
73 | } catch (UnsupportedEncodingException e) {
74 | throw new RuntimeException(e);
75 | }
76 | }
77 |
78 | public static String asString(byte value[]) {
79 | if( value == null) {
80 | return null;
81 | }
82 | try {
83 | return new String(value, "UTF-8");
84 | } catch (UnsupportedEncodingException e) {
85 | throw new RuntimeException(e);
86 | }
87 | }
88 |
89 | static private class OptionsResourceHolder {
90 |
91 | NativeComparator comparator=null;
92 | NativeLogger logger=null;
93 | NativeOptions options;
94 |
95 | public void init(Options value) {
96 |
97 | options = new NativeOptions();
98 | options.blockRestartInterval(value.blockRestartInterval());
99 | options.blockSize(value.blockSize());
100 | options.createIfMissing(value.createIfMissing());
101 | options.errorIfExists(value.errorIfExists());
102 | options.maxOpenFiles(value.maxOpenFiles());
103 | options.paranoidChecks(value.paranoidChecks());
104 | options.writeBufferSize(value.writeBufferSize());
105 |
106 | switch(value.compressionType()) {
107 | case NONE:
108 | options.compression(NativeCompressionType.kNoCompression);
109 | break;
110 | case SNAPPY:
111 | options.compression(NativeCompressionType.kSnappyCompression);
112 | break;
113 | }
114 |
115 | final DBComparator userComparator = value.comparator();
116 | if(userComparator!=null) {
117 | comparator = new NativeComparator() {
118 | @Override
119 | public int compare(byte[] key1, byte[] key2) {
120 | return userComparator.compare(key1, key2);
121 | }
122 |
123 | @Override
124 | public String name() {
125 | return userComparator.name();
126 | }
127 | };
128 | options.comparator(comparator);
129 | }
130 |
131 | final Logger userLogger = value.logger();
132 | if(userLogger!=null) {
133 | logger = new NativeLogger() {
134 | @Override
135 | public void log(String message) {
136 | userLogger.log(message);
137 | }
138 | };
139 | options.infoLog(logger);
140 | }
141 |
142 | }
143 | public void close() {
144 | if(comparator!=null){
145 | comparator.delete();
146 | }
147 | if(logger!=null) {
148 | logger.delete();
149 | }
150 | }
151 | }
152 |
153 | public DB open(File path, Options options) throws IOException {
154 | NativeDB db=null;
155 | OptionsResourceHolder holder = new OptionsResourceHolder();
156 | try {
157 | holder.init(options);
158 | db = NativeDB.open(holder.options, path);
159 | } finally {
160 | // if we could not open up the DB, then clean up the
161 | // other allocated native resouces..
162 | if(db==null) {
163 | holder.close();
164 | }
165 | }
166 | return new JniDB(db, holder.comparator, holder.logger);
167 | }
168 |
169 | public void destroy(File path, Options options) throws IOException {
170 | OptionsResourceHolder holder = new OptionsResourceHolder();
171 | try {
172 | holder.init(options);
173 | NativeDB.destroy(path, holder.options);
174 | } finally {
175 | holder.close();
176 | }
177 | }
178 |
179 | public void repair(File path, Options options) throws IOException {
180 | OptionsResourceHolder holder = new OptionsResourceHolder();
181 | try {
182 | holder.init(options);
183 | NativeDB.repair(path, holder.options);
184 | } finally {
185 | holder.close();
186 | }
187 | }
188 |
189 | @Override
190 | public String toString() {
191 | return String.format("rocksdbjni version %s", VERSION);
192 | }
193 |
194 |
195 | public static void pushMemoryPool(int size) {
196 | NativeBuffer.pushMemoryPool(size);
197 | }
198 |
199 | public static void popMemoryPool() {
200 | NativeBuffer.popMemoryPool();
201 | }
202 | }
203 |
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | # RocksDB JNI
2 |
3 | ## Description
4 |
5 | RocksDB JNI gives you a Java interface to the
6 | [RocksDB](http://rocksdb.org/) C++ library
7 | which is an embeddable persistent key-value store for fast storage.
8 |
9 |
27 |
28 | ## API Usage:
29 |
30 | Recommended Package imports:
31 |
32 | import org.iq80.rocksdb.*;
33 | import static org.fusesource.rocksdbjni.JniDBFactory.*;
34 | import java.io.*;
35 |
36 | Opening and closing the database.
37 |
38 | Options options = new Options();
39 | options.createIfMissing(true);
40 | DB db = factory.open(new File("example"), options);
41 | try {
42 | // Use the db in here....
43 | } finally {
44 | // Make sure you close the db to shutdown the
45 | // database and avoid resource leaks.
46 | db.close();
47 | }
48 |
49 | Putting, Getting, and Deleting key/values.
50 |
51 | db.put(bytes("Tampa"), bytes("rocks"));
52 | String value = asString(db.get(bytes("Tampa")));
53 | db.delete(bytes("Tampa"));
54 |
55 | Performing Batch/Bulk/Atomic Updates.
56 |
57 | WriteBatch batch = db.createWriteBatch();
58 | try {
59 | batch.delete(bytes("Denver"));
60 | batch.put(bytes("Tampa"), bytes("green"));
61 | batch.put(bytes("London"), bytes("red"));
62 |
63 | db.write(batch);
64 | } finally {
65 | // Make sure you close the batch to avoid resource leaks.
66 | batch.close();
67 | }
68 |
69 | Iterating key/values.
70 |
71 | DBIterator iterator = db.iterator();
72 | try {
73 | for(iterator.seekToFirst(); iterator.hasNext(); iterator.next()) {
74 | String key = asString(iterator.peekNext().getKey());
75 | String value = asString(iterator.peekNext().getValue());
76 | System.out.println(key+" = "+value);
77 | }
78 | } finally {
79 | // Make sure you close the iterator to avoid resource leaks.
80 | iterator.close();
81 | }
82 |
83 | Working against a Snapshot view of the Database.
84 |
85 | ReadOptions ro = new ReadOptions();
86 | ro.snapshot(db.getSnapshot());
87 | try {
88 |
89 | // All read operations will now use the same
90 | // consistent view of the data.
91 | ... = db.iterator(ro);
92 | ... = db.get(bytes("Tampa"), ro);
93 |
94 | } finally {
95 | // Make sure you close the snapshot to avoid resource leaks.
96 | ro.snapshot().close();
97 | }
98 |
99 | Using a custom Comparator.
100 |
101 | DBComparator comparator = new DBComparator(){
102 | public int compare(byte[] key1, byte[] key2) {
103 | return new String(key1).compareTo(new String(key2));
104 | }
105 | public String name() {
106 | return "simple";
107 | }
108 | public byte[] findShortestSeparator(byte[] start, byte[] limit) {
109 | return start;
110 | }
111 | public byte[] findShortSuccessor(byte[] key) {
112 | return key;
113 | }
114 | };
115 | Options options = new Options();
116 | options.comparator(comparator);
117 | DB db = factory.open(new File("example"), options);
118 |
119 | Disabling Compression
120 |
121 | Options options = new Options();
122 | options.compressionType(CompressionType.NONE);
123 | DB db = factory.open(new File("example"), options);
124 |
125 |
132 |
133 | Getting approximate sizes.
134 |
135 | long[] sizes = db.getApproximateSizes(new Range(bytes("a"), bytes("k")), new Range(bytes("k"), bytes("z")));
136 | System.out.println("Size: "+sizes[0]+", "+sizes[1]);
137 |
138 | Getting database status.
139 |
140 | String stats = db.getProperty("rocksdb.stats");
141 | System.out.println(stats);
142 |
143 |
155 |
156 | Destroying a database.
157 |
158 | Options options = new Options();
159 | factory.destroy(new File("example"), options);
160 |
161 | Repairing a database.
162 |
163 | Options options = new Options();
164 | factory.repair(new File("example"), options);
165 |
166 | Using a memory pool to make native memory allocations more efficient:
167 |
168 | JniDBFactory.pushMemoryPool(1024 * 512);
169 | try {
170 | // .. work with the DB in here,
171 | } finally {
172 | JniDBFactory.popMemoryPool();
173 | }
174 |
175 | ## Building
176 |
177 | ### Prerequisites
178 |
179 | * GNU compiler toolchain
180 | * [Maven 3](http://maven.apache.org/download.html)
181 |
182 | ### Supported Platforms
183 |
184 | The following worked for me on:
185 |
186 | * OS X Lion with X Code 4
187 | * CentOS 5.6 (32 and 64 bit)
188 | * Ubuntu 12.04 (32 and 64 bit)
189 | * apt-get install autoconf libtool
190 |
191 | ### Build Procedure
192 |
193 | Then download the snappy, rocksdb, and rocksdbjni project source code:
194 |
195 | wget http://snappy.googlecode.com/files/snappy-1.0.5.tar.gz
196 | tar -zxvf snappy-1.0.5.tar.gz
197 | git clone git@github.com:facebook/rocksdb.git
198 | git clone git://github.com/fusesource/rocksdbjni.git
199 | export SNAPPY_HOME=`cd snappy-1.0.5; pwd`
200 | export ROCKSDB_HOME=`cd rocksdb; pwd`
201 | export ROCKSDBJNI_HOME=`cd rocksdbjni; pwd`
202 |
203 |
208 |
209 | Compile the snappy project. This produces a static library.
210 |
211 | cd ${SNAPPY_HOME}
212 | ./configure --disable-shared --with-pic
213 | make
214 |
215 | Patch and Compile the rocksdb project. This produces a static library.
216 |
217 | cd ${ROCKSDB_HOME}
218 | export LIBRARY_PATH=${SNAPPY_HOME}
219 | export C_INCLUDE_PATH=${LIBRARY_PATH}
220 | export CPLUS_INCLUDE_PATH=${LIBRARY_PATH}
221 | make librocksdb.a
222 |
223 | Now use maven to build the rocksdbjni project.
224 |
225 | cd ${ROCKSDBJNI_HOME}
226 | mvn clean install
227 |
228 | The cd to the platform specific directory that matches your platform
229 |
230 | * rocksdbjni-osx
231 | * rocksdbjni-linux32
232 | * rocksdbjni-linux64
233 | * rocksdbjni-win32
234 | * rocksdbjni-win64
235 |
236 | And then run:
237 |
238 | mvn clean install
239 |
240 | ### Build Results
241 |
242 | * `rocksdbjni/target/rocksdbjni-${version}.jar` : The java class file to the library.
243 | * `rocksdbjni/target/rocksdbjni-${version}-native-src.zip` : A GNU style source project which you can use to build the native library on other systems.
244 | * `rocksdbjni-${platform}/target/rocksdbjni-${platform}-${version}.jar` : A jar file containing the built native library using your currently platform.
245 |
246 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/java/org/fusesource/rocksdbjni/internal/JniDB.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011, FuseSource Corp. All rights reserved.
3 | *
4 | * http://fusesource.com
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are
8 | * met:
9 | *
10 | * * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above
13 | * copyright notice, this list of conditions and the following disclaimer
14 | * in the documentation and/or other materials provided with the
15 | * distribution.
16 | * * Neither the name of FuseSource Corp. nor the names of its
17 | * contributors may be used to endorse or promote products derived from
18 | * this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.fusesource.rocksdbjni.internal;
33 |
34 | import org.iq80.leveldb.*;
35 |
36 | /**
37 | * @author Hiram Chirino
38 | */
39 | public class JniDB implements DB {
40 |
41 | private NativeDB db;
42 | private NativeComparator comparator;
43 | private NativeLogger logger;
44 |
45 | public JniDB(NativeDB db, NativeComparator comparator, NativeLogger logger) {
46 | this.db = db;
47 | this.comparator = comparator;
48 | this.logger = logger;
49 | }
50 |
51 | public void close() {
52 | if( db!=null ) {
53 | db.delete();
54 | db = null;
55 | if(comparator!=null){
56 | comparator.delete();
57 | comparator = null;
58 | }
59 | if(logger!=null) {
60 | logger.delete();
61 | logger = null;
62 | }
63 | }
64 | }
65 |
66 |
67 | public byte[] get(byte[] key) throws DBException {
68 | if( db==null ) {
69 | throw new DBException("Closed");
70 | }
71 | return get(key, new ReadOptions());
72 | }
73 |
74 | public byte[] get(byte[] key, ReadOptions options) throws DBException {
75 | if( db==null ) {
76 | throw new DBException("Closed");
77 | }
78 | try {
79 | return db.get(convert(options), key);
80 | } catch (NativeDB.DBException e) {
81 | if(e.isNotFound()) {
82 | return null;
83 | }
84 | throw new DBException(e.getMessage(), e);
85 | }
86 | }
87 |
88 | public DBIterator iterator() {
89 | return iterator(new ReadOptions());
90 | }
91 |
92 | public DBIterator iterator(ReadOptions options) {
93 | if( db==null ) {
94 | throw new DBException("Closed");
95 | }
96 | return new JniDBIterator(db.iterator(convert(options)));
97 | }
98 |
99 | public void put(byte[] key, byte[] value) throws DBException {
100 | put(key, value, new WriteOptions());
101 | }
102 |
103 | public void delete(byte[] key) throws DBException {
104 | delete(key, new WriteOptions());
105 | }
106 |
107 | public void write(WriteBatch updates) throws DBException {
108 | write(updates, new WriteOptions());
109 | }
110 |
111 | public WriteBatch createWriteBatch() {
112 | return new JniWriteBatch(new NativeWriteBatch());
113 | }
114 |
115 | public Snapshot put(byte[] key, byte[] value, WriteOptions options) throws DBException {
116 | if( db==null ) {
117 | throw new DBException("Closed");
118 | }
119 | try {
120 | db.put(convert(options), key, value);
121 | return null;
122 | } catch (NativeDB.DBException e) {
123 | throw new DBException(e.getMessage(), e);
124 | }
125 | }
126 |
127 | public Snapshot delete(byte[] key, WriteOptions options) throws DBException {
128 | if( db==null ) {
129 | throw new DBException("Closed");
130 | }
131 | try {
132 | db.delete(convert(options), key);
133 | return null;
134 | } catch (NativeDB.DBException e) {
135 | throw new DBException(e.getMessage(), e);
136 | }
137 | }
138 |
139 | public Snapshot write(WriteBatch updates, WriteOptions options) throws DBException {
140 | if( db==null ) {
141 | throw new DBException("Closed");
142 | }
143 | try {
144 | db.write(convert(options), ((JniWriteBatch) updates).writeBatch());
145 | return null;
146 | } catch (NativeDB.DBException e) {
147 | throw new DBException(e.getMessage(), e);
148 | }
149 | }
150 |
151 | public Snapshot getSnapshot() {
152 | if( db==null ) {
153 | throw new DBException("Closed");
154 | }
155 | return new JniSnapshot(db, db.getSnapshot());
156 | }
157 |
158 | public long[] getApproximateSizes(Range... ranges) {
159 | if( db==null ) {
160 | throw new DBException("Closed");
161 | }
162 | NativeRange args[] = new NativeRange[ranges.length];
163 | for (int i = 0; i < args.length; i++) {
164 | args[i] = new NativeRange(ranges[i].start(), ranges[i].limit());
165 | }
166 | return db.getApproximateSizes(args);
167 | }
168 |
169 | public String getProperty(String name) {
170 | if( db==null ) {
171 | throw new DBException("Closed");
172 | }
173 | return db.getProperty(name);
174 | }
175 |
176 | private NativeReadOptions convert(ReadOptions options) {
177 | if(options==null) {
178 | return null;
179 | }
180 | NativeReadOptions rc = new NativeReadOptions();
181 | rc.fillCache(options.fillCache());
182 | rc.verifyChecksums(options.verifyChecksums());
183 | if(options.snapshot()!=null) {
184 | rc.snapshot(((JniSnapshot) options.snapshot()).snapshot());
185 | }
186 | return rc;
187 | }
188 |
189 | private NativeWriteOptions convert(WriteOptions options) {
190 | if(options==null) {
191 | return null;
192 | }
193 | NativeWriteOptions rc = new NativeWriteOptions();
194 | rc.sync(options.sync());
195 | if(options.snapshot()) {
196 | throw new UnsupportedOperationException("WriteOptions snapshot not supported");
197 | }
198 | return rc;
199 | }
200 |
201 | public void compactRange(byte[] begin, byte[] end) throws DBException {
202 | if( db==null ) {
203 | throw new DBException("Closed");
204 | }
205 | db.compactRange(begin, end);
206 | }
207 |
208 | public void suspendCompactions() throws InterruptedException {
209 | throw new UnsupportedOperationException();
210 | }
211 |
212 | public void resumeCompactions() {
213 | throw new UnsupportedOperationException();
214 | }
215 |
216 | }
217 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/native-package/autotools/missing:
--------------------------------------------------------------------------------
1 | #! /bin/sh
2 | # Common wrapper for a few potentially missing GNU programs.
3 |
4 | scriptversion=2012-06-26.16; # UTC
5 |
6 | # Copyright (C) 1996-2013 Free Software Foundation, Inc.
7 | # Originally written by Fran,cois Pinard , 1996.
8 |
9 | # This program is free software; you can redistribute it and/or modify
10 | # it under the terms of the GNU General Public License as published by
11 | # the Free Software Foundation; either version 2, or (at your option)
12 | # any later version.
13 |
14 | # This program is distributed in the hope that it will be useful,
15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | # GNU General Public License for more details.
18 |
19 | # You should have received a copy of the GNU General Public License
20 | # along with this program. If not, see .
21 |
22 | # As a special exception to the GNU General Public License, if you
23 | # distribute this file as part of a program that contains a
24 | # configuration script generated by Autoconf, you may include it under
25 | # the same distribution terms that you use for the rest of that program.
26 |
27 | if test $# -eq 0; then
28 | echo 1>&2 "Try '$0 --help' for more information"
29 | exit 1
30 | fi
31 |
32 | case $1 in
33 |
34 | --is-lightweight)
35 | # Used by our autoconf macros to check whether the available missing
36 | # script is modern enough.
37 | exit 0
38 | ;;
39 |
40 | --run)
41 | # Back-compat with the calling convention used by older automake.
42 | shift
43 | ;;
44 |
45 | -h|--h|--he|--hel|--help)
46 | echo "\
47 | $0 [OPTION]... PROGRAM [ARGUMENT]...
48 |
49 | Run 'PROGRAM [ARGUMENT]...', returning a proper advice when this fails due
50 | to PROGRAM being missing or too old.
51 |
52 | Options:
53 | -h, --help display this help and exit
54 | -v, --version output version information and exit
55 |
56 | Supported PROGRAM values:
57 | aclocal autoconf autoheader autom4te automake makeinfo
58 | bison yacc flex lex help2man
59 |
60 | Version suffixes to PROGRAM as well as the prefixes 'gnu-', 'gnu', and
61 | 'g' are ignored when checking the name.
62 |
63 | Send bug reports to ."
64 | exit $?
65 | ;;
66 |
67 | -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
68 | echo "missing $scriptversion (GNU Automake)"
69 | exit $?
70 | ;;
71 |
72 | -*)
73 | echo 1>&2 "$0: unknown '$1' option"
74 | echo 1>&2 "Try '$0 --help' for more information"
75 | exit 1
76 | ;;
77 |
78 | esac
79 |
80 | # Run the given program, remember its exit status.
81 | "$@"; st=$?
82 |
83 | # If it succeeded, we are done.
84 | test $st -eq 0 && exit 0
85 |
86 | # Also exit now if we it failed (or wasn't found), and '--version' was
87 | # passed; such an option is passed most likely to detect whether the
88 | # program is present and works.
89 | case $2 in --version|--help) exit $st;; esac
90 |
91 | # Exit code 63 means version mismatch. This often happens when the user
92 | # tries to use an ancient version of a tool on a file that requires a
93 | # minimum version.
94 | if test $st -eq 63; then
95 | msg="probably too old"
96 | elif test $st -eq 127; then
97 | # Program was missing.
98 | msg="missing on your system"
99 | else
100 | # Program was found and executed, but failed. Give up.
101 | exit $st
102 | fi
103 |
104 | perl_URL=http://www.perl.org/
105 | flex_URL=http://flex.sourceforge.net/
106 | gnu_software_URL=http://www.gnu.org/software
107 |
108 | program_details ()
109 | {
110 | case $1 in
111 | aclocal|automake)
112 | echo "The '$1' program is part of the GNU Automake package:"
113 | echo "<$gnu_software_URL/automake>"
114 | echo "It also requires GNU Autoconf, GNU m4 and Perl in order to run:"
115 | echo "<$gnu_software_URL/autoconf>"
116 | echo "<$gnu_software_URL/m4/>"
117 | echo "<$perl_URL>"
118 | ;;
119 | autoconf|autom4te|autoheader)
120 | echo "The '$1' program is part of the GNU Autoconf package:"
121 | echo "<$gnu_software_URL/autoconf/>"
122 | echo "It also requires GNU m4 and Perl in order to run:"
123 | echo "<$gnu_software_URL/m4/>"
124 | echo "<$perl_URL>"
125 | ;;
126 | esac
127 | }
128 |
129 | give_advice ()
130 | {
131 | # Normalize program name to check for.
132 | normalized_program=`echo "$1" | sed '
133 | s/^gnu-//; t
134 | s/^gnu//; t
135 | s/^g//; t'`
136 |
137 | printf '%s\n' "'$1' is $msg."
138 |
139 | configure_deps="'configure.ac' or m4 files included by 'configure.ac'"
140 | case $normalized_program in
141 | autoconf*)
142 | echo "You should only need it if you modified 'configure.ac',"
143 | echo "or m4 files included by it."
144 | program_details 'autoconf'
145 | ;;
146 | autoheader*)
147 | echo "You should only need it if you modified 'acconfig.h' or"
148 | echo "$configure_deps."
149 | program_details 'autoheader'
150 | ;;
151 | automake*)
152 | echo "You should only need it if you modified 'Makefile.am' or"
153 | echo "$configure_deps."
154 | program_details 'automake'
155 | ;;
156 | aclocal*)
157 | echo "You should only need it if you modified 'acinclude.m4' or"
158 | echo "$configure_deps."
159 | program_details 'aclocal'
160 | ;;
161 | autom4te*)
162 | echo "You might have modified some maintainer files that require"
163 | echo "the 'automa4te' program to be rebuilt."
164 | program_details 'autom4te'
165 | ;;
166 | bison*|yacc*)
167 | echo "You should only need it if you modified a '.y' file."
168 | echo "You may want to install the GNU Bison package:"
169 | echo "<$gnu_software_URL/bison/>"
170 | ;;
171 | lex*|flex*)
172 | echo "You should only need it if you modified a '.l' file."
173 | echo "You may want to install the Fast Lexical Analyzer package:"
174 | echo "<$flex_URL>"
175 | ;;
176 | help2man*)
177 | echo "You should only need it if you modified a dependency" \
178 | "of a man page."
179 | echo "You may want to install the GNU Help2man package:"
180 | echo "<$gnu_software_URL/help2man/>"
181 | ;;
182 | makeinfo*)
183 | echo "You should only need it if you modified a '.texi' file, or"
184 | echo "any other file indirectly affecting the aspect of the manual."
185 | echo "You might want to install the Texinfo package:"
186 | echo "<$gnu_software_URL/texinfo/>"
187 | echo "The spurious makeinfo call might also be the consequence of"
188 | echo "using a buggy 'make' (AIX, DU, IRIX), in which case you might"
189 | echo "want to install GNU make:"
190 | echo "<$gnu_software_URL/make/>"
191 | ;;
192 | *)
193 | echo "You might have modified some files without having the proper"
194 | echo "tools for further handling them. Check the 'README' file, it"
195 | echo "often tells you about the needed prerequisites for installing"
196 | echo "this package. You may also peek at any GNU archive site, in"
197 | echo "case some other package contains this missing '$1' program."
198 | ;;
199 | esac
200 | }
201 |
202 | give_advice "$1" | sed -e '1s/^/WARNING: /' \
203 | -e '2,$s/^/ /' >&2
204 |
205 | # Propagate the correct exit status (expected to be 127 for a program
206 | # not found, 63 for a program that failed due to version mismatch).
207 | exit $st
208 |
209 | # Local variables:
210 | # eval: (add-hook 'write-file-hooks 'time-stamp)
211 | # time-stamp-start: "scriptversion="
212 | # time-stamp-format: "%:y-%02m-%02d.%02H"
213 | # time-stamp-time-zone: "UTC"
214 | # time-stamp-end: "; # UTC"
215 | # End:
216 |
--------------------------------------------------------------------------------
/rocksdbjni-all/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
33 |
34 |
35 | 4.0.0
36 |
37 | org.fusesource.rocksdbjni
38 | rocksdbjni-project
39 | 99-master-SNAPSHOT
40 |
41 |
42 | org.fusesource.rocksdbjni
43 | rocksdbjni-all
44 | 99-master-SNAPSHOT
45 | bundle
46 |
47 | ${project.artifactId}
48 | An uber jar which contains all the rocksdbjni platform libraries and dependencies
49 |
50 |
51 |
52 | org.fusesource.rocksdbjni
53 | rocksdbjni
54 | 99-master-SNAPSHOT
55 | provided
56 |
57 |
58 | org.fusesource.rocksdbjni
59 | rocksdbjni-osx
60 | 1.8
61 | provided
62 |
63 |
64 | org.fusesource.rocksdbjni
65 | rocksdbjni-linux32
66 | 1.8
67 | provided
68 |
69 |
70 | org.fusesource.rocksdbjni
71 | rocksdbjni-linux64
72 | 1.8
73 | provided
74 |
75 |
76 | org.fusesource.rocksdbjni
77 | rocksdbjni-win32
78 | 1.8
79 | provided
80 |
81 |
82 | org.fusesource.rocksdbjni
83 | rocksdbjni-win64
84 | 1.8
85 | provided
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 | org.apache.felix
96 | maven-bundle-plugin
97 | 2.3.7
98 | true
99 | true
100 |
101 |
102 | ${project.artifactId}
103 | ${project.groupId}.${project.artifactId}
104 |
105 | org.fusesource.rocksdbjni;version=${project.version},
106 | org.iq80.leveldb*;version=${leveldb-api-version},
107 |
108 |
109 | org.fusesource.hawtjni*,org.fusesource.rocksdbjni.internal*,!*
110 | RocksDB JNI
111 | ${project.version}
112 |
113 | *;groupId=org.fusesource.rocksdbjni;inline=META-INF/native/*,
114 |
115 | true
116 |
117 | META-INF/native/windows32/rocksdbjni.dll;osname=Win32;processor=x86,
118 | META-INF/native/windows64/rocksdbjni.dll;osname=Win32;processor=x86-64,
119 | META-INF/native/osx/librocksdbjni.jnilib;osname=macosx;processor=x86,
120 | META-INF/native/osx/librocksdbjni.jnilib;osname=macosx;processor=x86-64,
121 | META-INF/native/linux32/librocksdbjni.so;osname=Linux;processor=x86,
122 | META-INF/native/linux64/librocksdbjni.so;osname=Linux;processor=x86-64
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 | release
133 |
134 |
135 |
136 | org.fusesource.rocksdbjni
137 | rocksdbjni
138 | 99-master-SNAPSHOT
139 | sources
140 | true
141 |
142 |
143 | org.iq80.leveldb
144 | leveldb-api
145 | ${leveldb-api-version}
146 | sources
147 | true
148 |
149 |
150 | org.fusesource.hawtjni
151 | hawtjni-runtime
152 | ${hawtjni-version}
153 | sources
154 | true
155 |
156 |
157 |
158 |
159 |
160 |
161 | maven-source-plugin
162 |
163 | true
164 |
165 |
166 |
167 | maven-assembly-plugin
168 |
169 |
170 | uber-sources-jar
171 | package
172 |
173 | single
174 |
175 |
176 |
177 | ${basedir}/src/main/descriptors/uber-sources.xml
178 |
179 | true
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
33 |
34 |
35 | 4.0.0
36 |
37 | org.fusesource
38 | fusesource-pom
39 | 1.9
40 |
41 |
42 | org.fusesource.rocksdbjni
43 | rocksdbjni-project
44 | 99-master-SNAPSHOT
45 | pom
46 |
47 | ${project.artifactId}
48 | rocksdbjni is a jni library for accessing rocksdb.
49 |
50 |
51 | rocksdbjni
52 | rocksdbjni
53 | UTF-8
54 | 1.9
55 | 0.6
56 |
57 |
58 |
59 | rocksdbjni
60 |
61 |
62 | http://${forge-project-id}.fusesource.org
63 | 2009
64 |
65 |
66 | github
67 | https://github.com/fusesource/rocksdbjni/issues
68 |
69 |
70 |
71 |
72 | ${forge-project-id} dev
73 | ${forge-project-id}-dev@fusesource.org
74 | ${forge-project-id}-dev-subscribe@fusesource.org
75 |
76 |
77 | ${forge-project-id} commits
78 | ${forge-project-id}-commits@fusesource.org
79 | ${forge-project-id}-commits-subscribe@fusesource.org
80 |
81 |
82 |
83 |
84 |
85 | The BSD 3-Clause License
86 | http://www.opensource.org/licenses/BSD-3-Clause
87 | repo
88 |
89 |
90 |
91 |
92 | scm:git:git://github.com/fusesource/rocksdbjni.git
93 | scm:git:git@github.com:fusesource/rocksdbjni.git
94 | https://github.com/fusesource/rocksdbjni
95 |
96 |
97 |
98 |
99 | website.fusesource.org
100 | website
101 | dav:http://fusesource.com/forge/dav/${forge-project-id}/maven/${project.version}
102 |
103 |
104 |
105 |
106 |
107 | chirino
108 | Hiram Chirino
109 | hiram@hiramchirino.com
110 | http://hiramchirino.com
111 | GMT-5
112 |
113 |
114 |
115 |
116 |
117 | junit
118 | junit
119 | 4.7
120 | test
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 | org.apache.maven.plugins
130 | maven-clean-plugin
131 | 2.3
132 |
133 |
134 |
135 |
136 | org.apache.maven.plugins
137 | maven-compiler-plugin
138 |
139 | 1.5
140 | 1.5
141 |
142 |
143 |
144 |
145 | org.apache.maven.plugins
146 | maven-surefire-plugin
147 | 2.4.3
148 |
149 | true
150 | once
151 | -ea
152 | false
153 | ${project.build.directory}
154 |
155 | **/*Test.java
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 | org.codehaus.mojo
166 | jxr-maven-plugin
167 | 2.0-beta-1
168 |
169 | true
170 |
171 |
172 |
173 | org.apache.maven.plugins
174 | maven-javadoc-plugin
175 | 2.6
176 |
177 | *.internal
178 | true
179 |
180 | http://java.sun.com/j2se/1.5.0/docs/api
181 |
182 |
183 |
184 |
185 | org.apache.maven.plugins
186 | maven-project-info-reports-plugin
187 | 2.1.1
188 |
189 |
190 |
191 | index
192 | sumary
193 | plugins
194 | dependencies
195 | mailing-list
196 | issue-tracking
197 | license
198 | scm
199 |
200 |
201 |
202 |
203 |
204 | org.codehaus.mojo
205 | surefire-report-maven-plugin
206 | 2.0-beta-1
207 |
208 |
209 | org.apache.maven.plugins
210 | maven-plugin-plugin
211 | 2.5
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 | download
220 |
221 |
222 | fusesource.nexus.snapshot
223 | FuseSource Community Snapshot Repository
224 | http://repo.fusesource.com/nexus/content/groups/public-snapshots
225 |
226 |
227 | sonatype-nexus
228 | Sonatype Nexus
229 | https://oss.sonatype.org/content/repositories/public
230 | true
231 | true
232 |
233 |
234 |
235 |
236 | fusesource.nexus.snapshot
237 | FuseSource Community Snapshot Repository
238 | http://repo.fusesource.com/nexus/content/groups/public-snapshots
239 |
240 |
241 |
242 |
243 |
244 | full
245 |
246 | rocksdbjni-osx
247 | rocksdbjni-linux32
248 | rocksdbjni-linux64
249 | rocksdbjni-win32
250 | rocksdbjni-win64
251 | rocksdbjni-all
252 |
253 |
254 |
255 |
256 | all
257 |
258 | rocksdbjni-all
259 |
260 |
261 |
262 | osx
263 |
264 | rocksdbjni-osx
265 |
266 |
267 |
268 |
269 | linux32
270 |
271 | rocksdbjni-linux32
272 |
273 |
274 |
275 |
276 | linux64
277 |
278 | rocksdbjni-linux64
279 |
280 |
281 |
282 |
283 | win32
284 |
285 | true
286 |
287 |
288 | rocksdbjni-win32
289 |
290 |
291 |
292 |
293 | win64
294 |
295 | true
296 |
297 |
298 | rocksdbjni-win64
299 |
300 |
301 |
302 |
303 |
304 |
--------------------------------------------------------------------------------
/rocksdbjni/src/main/java/org/fusesource/rocksdbjni/internal/NativeBuffer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2011, FuseSource Corp. All rights reserved.
3 | *
4 | * http://fusesource.com
5 | *
6 | * Redistribution and use in source and binary forms, with or without
7 | * modification, are permitted provided that the following conditions are
8 | * met:
9 | *
10 | * * Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * * Redistributions in binary form must reproduce the above
13 | * copyright notice, this list of conditions and the following disclaimer
14 | * in the documentation and/or other materials provided with the
15 | * distribution.
16 | * * Neither the name of FuseSource Corp. nor the names of its
17 | * contributors may be used to endorse or promote products derived from
18 | * this software without specific prior written permission.
19 | *
20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 | package org.fusesource.rocksdbjni.internal;
33 |
34 | import org.fusesource.hawtjni.runtime.JniArg;
35 | import org.fusesource.hawtjni.runtime.JniClass;
36 | import org.fusesource.hawtjni.runtime.JniMethod;
37 | import org.fusesource.hawtjni.runtime.PointerMath;
38 |
39 | import java.util.concurrent.Callable;
40 | import java.util.concurrent.atomic.AtomicInteger;
41 |
42 | import static org.fusesource.hawtjni.runtime.ArgFlag.*;
43 |
44 | /**
45 | * A NativeBuffer allocates a native buffer on the heap. It supports
46 | * creating sub slices/views of that buffer and manages reference tracking
47 | * so that the the native buffer is freed once all NativeBuffer views
48 | * are deleted.
49 | *
50 | * @author Hiram Chirino
51 | */
52 | public class NativeBuffer extends NativeObject {
53 |
54 | @JniClass
55 | static class NativeBufferJNI {
56 | static {
57 | NativeDB.LIBRARY.load();
58 | }
59 |
60 | @JniMethod(cast="void *")
61 | public static final native long malloc(
62 | @JniArg(cast="size_t") long size);
63 |
64 | public static final native void free(
65 | @JniArg(cast="void *") long self);
66 |
67 | // public static final native void buffer_copy (
68 | // @JniArg(cast="const void *") long src,
69 | // @JniArg(cast="size_t") long srcPos,
70 | // @JniArg(cast="void *") long dest,
71 | // @JniArg(cast="size_t") long destPos,
72 | // @JniArg(cast="size_t") long length);
73 |
74 | public static final native void buffer_copy (
75 | @JniArg(cast="const void *", flags={NO_OUT, CRITICAL}) byte[] src,
76 | @JniArg(cast="size_t") long srcPos,
77 | @JniArg(cast="void *") long dest,
78 | @JniArg(cast="size_t") long destPos,
79 | @JniArg(cast="size_t") long length);
80 |
81 | public static final native void buffer_copy (
82 | @JniArg(cast="const void *") long src,
83 | @JniArg(cast="size_t") long srcPos,
84 | @JniArg(cast="void *", flags={NO_IN, CRITICAL}) byte[] dest,
85 | @JniArg(cast="size_t") long destPos,
86 | @JniArg(cast="size_t") long length);
87 |
88 | // @JniMethod(cast="void *")
89 | // public static final native long memset (
90 | // @JniArg(cast="void *") long buffer,
91 | // int c,
92 | // @JniArg(cast="size_t") long num);
93 |
94 | }
95 |
96 | private static class Allocation extends NativeObject {
97 | private final AtomicInteger retained = new AtomicInteger(0);
98 |
99 | private Allocation(long size) {
100 | super(NativeBufferJNI.malloc(size));
101 | }
102 |
103 | void retain() {
104 | assertAllocated();
105 | retained.incrementAndGet();
106 | }
107 |
108 | void release() {
109 | assertAllocated();
110 | int r = retained.decrementAndGet();
111 | if( r < 0 ) {
112 | throw new Error("The object has already been deleted.");
113 | } else if( r==0 ) {
114 | NativeBufferJNI.free(self);
115 | self = 0;
116 | }
117 | }
118 | }
119 |
120 | private static class Pool {
121 | private final NativeBuffer.Pool prev;
122 | Allocation allocation;
123 | long pos;
124 | long remaining;
125 | int chunk;
126 |
127 | public Pool(int chunk, Pool prev) {
128 | this.chunk = chunk;
129 | this.prev = prev;
130 | }
131 |
132 | NativeBuffer create(long size) {
133 | if( size >= chunk ) {
134 | Allocation allocation = new Allocation(size);
135 | return new NativeBuffer(allocation, allocation.self, size);
136 | }
137 |
138 | if( remaining < size ) {
139 | delete();
140 | }
141 |
142 | if( allocation == null ) {
143 | allocate();
144 | }
145 |
146 | NativeBuffer rc = new NativeBuffer(allocation, pos, size);
147 | pos = PointerMath.add(pos, size);
148 | remaining -= size;
149 | return rc;
150 | }
151 |
152 | private void allocate() {
153 | allocation = new NativeBuffer.Allocation(chunk);
154 | allocation.retain();
155 | remaining = chunk;
156 | pos = allocation.self;
157 | }
158 |
159 | public void delete() {
160 | if( allocation!=null ) {
161 | allocation.release();
162 | allocation = null;
163 | }
164 | }
165 | }
166 |
167 | private final Allocation allocation;
168 | private final long capacity;
169 |
170 | static final private ThreadLocal CURRENT_POOL = new ThreadLocal();
171 |
172 | static public NativeBuffer create(long capacity) {
173 | Pool pool = CURRENT_POOL.get();
174 | if( pool == null ) {
175 | Allocation allocation = new Allocation(capacity);
176 | return new NativeBuffer(allocation, allocation.self, capacity);
177 | } else {
178 | return pool.create(capacity);
179 | }
180 | }
181 |
182 |
183 | public static void pushMemoryPool(int size) {
184 | Pool original = CURRENT_POOL.get();
185 | Pool next = new Pool(size, original);
186 | CURRENT_POOL.set(next);
187 | }
188 |
189 | public static void popMemoryPool() {
190 | Pool next = CURRENT_POOL.get();
191 | next.delete();
192 | if( next.prev == null ) {
193 | CURRENT_POOL.remove();
194 | } else {
195 | CURRENT_POOL.set(next.prev);
196 | }
197 | }
198 |
199 | static public NativeBuffer create(byte[] data) {
200 | if( data == null ) {
201 | return null;
202 | } else {
203 | return create(data, 0 , data.length);
204 | }
205 | }
206 |
207 | static public NativeBuffer create(String data) {
208 | return create(cbytes(data));
209 | }
210 |
211 | static public NativeBuffer create(byte[] data, int offset, int length) {
212 | NativeBuffer rc = create(length);
213 | rc.write(0, data, offset, length);
214 | return rc;
215 | }
216 |
217 | private NativeBuffer(Allocation allocation, long self, long capacity) {
218 | super(self);
219 | this.capacity = capacity;
220 | this.allocation = allocation;
221 | this.allocation.retain();
222 | }
223 |
224 | public NativeBuffer slice(long offset, long length) {
225 | assertAllocated();
226 | if( length < 0 ) throw new IllegalArgumentException("length cannot be negative");
227 | if( offset < 0 ) throw new IllegalArgumentException("offset cannot be negative");
228 | if( offset+length >= capacity) throw new ArrayIndexOutOfBoundsException("offset + length exceed the length of this buffer");
229 | return new NativeBuffer(allocation, PointerMath.add(self, offset), length);
230 | }
231 |
232 | static byte[] cbytes(String strvalue) {
233 | byte[] value = strvalue.getBytes();
234 | // expand by 1 so we get a null at the end.
235 | byte[] rc = new byte[value.length+1];
236 | System.arraycopy(value, 0, rc, 0, value.length);
237 | return rc;
238 | }
239 |
240 | public NativeBuffer head(long length) {
241 | return slice(0, length);
242 | }
243 |
244 | public NativeBuffer tail(long length) {
245 | if( capacity-length < 0) throw new ArrayIndexOutOfBoundsException("capacity-length cannot be less than zero");
246 | return slice(capacity-length, length);
247 | }
248 |
249 | public void delete() {
250 | allocation.release();
251 | }
252 |
253 | public long capacity() {
254 | return capacity;
255 | }
256 |
257 | public void write(long at, byte []source, int offset, int length) {
258 | assertAllocated();
259 | if( length < 0 ) throw new IllegalArgumentException("length cannot be negative");
260 | if( offset < 0 ) throw new IllegalArgumentException("offset cannot be negative");
261 | if( at < 0 ) throw new IllegalArgumentException("at cannot be negative");
262 | if( at+length > capacity ) throw new ArrayIndexOutOfBoundsException("at + length exceeds the capacity of this object");
263 | if( offset+length > source.length) throw new ArrayIndexOutOfBoundsException("offset + length exceed the length of the source buffer");
264 | NativeBufferJNI.buffer_copy(source, offset, self, at, length);
265 | }
266 |
267 | public void read(long at, byte []target, int offset, int length) {
268 | assertAllocated();
269 | if( length < 0 ) throw new IllegalArgumentException("length cannot be negative");
270 | if( offset < 0 ) throw new IllegalArgumentException("offset cannot be negative");
271 | if( at < 0 ) throw new IllegalArgumentException("at cannot be negative");
272 | if( at+length > capacity ) throw new ArrayIndexOutOfBoundsException("at + length exceeds the capacity of this object");
273 | if( offset+length > target.length) throw new ArrayIndexOutOfBoundsException("offset + length exceed the length of the target buffer");
274 | NativeBufferJNI.buffer_copy(self, at, target, offset, length);
275 | }
276 |
277 | public byte[] toByteArray() {
278 | if( capacity > Integer.MAX_VALUE ) {
279 | throw new OutOfMemoryError("Native buffer larger than the largest allowed Java byte[]");
280 | }
281 | byte [] rc = new byte[(int) capacity];
282 | read(0, rc, 0, rc.length);
283 | return rc;
284 | }
285 | }
286 |
--------------------------------------------------------------------------------