You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2013/08/06 08:08:35 UTC

[09/13] git commit: Added LevelDBState.java.

Added LevelDBState.java.

Review: https://reviews.apache.org/r/12492


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/3b3c1497
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/3b3c1497
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/3b3c1497

Branch: refs/heads/master
Commit: 3b3c1497f6a0c1f2ec6d1b4a6916787d819d1756
Parents: 7e6da6d
Author: Benjamin Hindman <be...@gmail.com>
Authored: Wed Jul 10 00:46:32 2013 -0700
Committer: Benjamin Hindman <be...@gmail.com>
Committed: Mon Aug 5 23:08:04 2013 -0700

----------------------------------------------------------------------
 src/Makefile.am                                 |  7 ++++
 .../jni/org_apache_mesos_state_LevelDBState.cpp | 43 ++++++++++++++++++++
 .../org_apache_mesos_state_ZooKeeperState.cpp   |  6 ---
 .../org/apache/mesos/state/LevelDBState.java    | 36 ++++++++++++++++
 4 files changed, 86 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/3b3c1497/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 33ef056..3eae964 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -447,6 +447,7 @@ MESOS_JAR_SOURCE =							\
 	$(srcdir)/java/src/org/apache/mesos/Scheduler.java		\
 	$(srcdir)/java/src/org/apache/mesos/state/AbstractState.java	\
 	$(srcdir)/java/src/org/apache/mesos/state/InMemoryState.java	\
+	$(srcdir)/java/src/org/apache/mesos/state/LevelDBState.java	\
 	$(srcdir)/java/src/org/apache/mesos/state/State.java		\
 	$(srcdir)/java/src/org/apache/mesos/state/Variable.java		\
 	$(srcdir)/java/src/org/apache/mesos/state/ZooKeeperState.java
@@ -522,6 +523,7 @@ libjava_la_SOURCES =							\
 	java/jni/org_apache_mesos_MesosSchedulerDriver.cpp		\
 	java/jni/org_apache_mesos_MesosExecutorDriver.cpp		\
 	java/jni/org_apache_mesos_state_AbstractState.cpp		\
+	java/jni/org_apache_mesos_state_LevelDBState.cpp		\
 	java/jni/org_apache_mesos_state_Variable.cpp			\
 	java/jni/org_apache_mesos_state_ZooKeeperState.cpp		\
 	jvm/jvm.cpp							\
@@ -560,6 +562,7 @@ nodist_libjava_la_SOURCES =						\
 	java/jni/org_apache_mesos_MesosExecutorDriver.h			\
 	java/jni/org_apache_mesos_Log.h					\
 	java/jni/org_apache_mesos_state_AbstractState.h			\
+	java/jni/org_apache_mesos_state_LevelDBState.h			\
 	java/jni/org_apache_mesos_state_Variable.h			\
 	java/jni/org_apache_mesos_state_ZooKeeperState.h
 
@@ -583,6 +586,10 @@ java/jni/org_apache_mesos_state_AbstractState.h: $(MESOS_JAR)
 	$(JAVA_HOME)/bin/javah -d java/jni -classpath		\
           $(PROTOBUF_JAR):java/classes org.apache.mesos.state.AbstractState
 
+java/jni/org_apache_mesos_state_LevelDBState.h: $(MESOS_JAR)
+	$(JAVA_HOME)/bin/javah -d java/jni -classpath		\
+          $(PROTOBUF_JAR):java/classes org.apache.mesos.state.LevelDBState
+
 java/jni/org_apache_mesos_state_Variable.h: $(MESOS_JAR)
 	$(JAVA_HOME)/bin/javah -d java/jni -classpath			\
           $(PROTOBUF_JAR):java/classes org.apache.mesos.state.Variable

http://git-wip-us.apache.org/repos/asf/mesos/blob/3b3c1497/src/java/jni/org_apache_mesos_state_LevelDBState.cpp
----------------------------------------------------------------------
diff --git a/src/java/jni/org_apache_mesos_state_LevelDBState.cpp b/src/java/jni/org_apache_mesos_state_LevelDBState.cpp
new file mode 100644
index 0000000..30f6309
--- /dev/null
+++ b/src/java/jni/org_apache_mesos_state_LevelDBState.cpp
@@ -0,0 +1,43 @@
+#include <jni.h>
+
+#include <string>
+
+#include "state/leveldb.hpp"
+#include "state/state.hpp"
+
+#include "construct.hpp"
+#include "convert.hpp"
+
+using namespace mesos::internal::state;
+
+using std::string;
+
+extern "C" {
+
+/*
+ * Class:     org_apache_mesos_state_LevelDBState
+ * Method:    initialize
+ * Signature: (Ljava/lang/String;)V
+ */
+JNIEXPORT void JNICALL Java_org_apache_mesos_state_LevelDBState_initialize
+  (JNIEnv* env, jobject thiz, jstring jpath)
+{
+  string path = construct<string>(env, jpath);
+
+   // Create the C++ Storage and State instances and initialize the
+   // __storage and __state variables.
+  Storage* storage = new LevelDBStorage(path);
+  State* state = new State(storage);
+
+  jclass clazz = env->GetObjectClass(thiz);
+
+  clazz = env->GetSuperclass(clazz);
+
+  jfieldID __storage = env->GetFieldID(clazz, "__storage", "J");
+  env->SetLongField(thiz, __storage, (jlong) storage);
+
+  jfieldID __state = env->GetFieldID(clazz, "__state", "J");
+  env->SetLongField(thiz, __state, (jlong) state);
+}
+
+} // extern "C" {

http://git-wip-us.apache.org/repos/asf/mesos/blob/3b3c1497/src/java/jni/org_apache_mesos_state_ZooKeeperState.cpp
----------------------------------------------------------------------
diff --git a/src/java/jni/org_apache_mesos_state_ZooKeeperState.cpp b/src/java/jni/org_apache_mesos_state_ZooKeeperState.cpp
index 41f974e..c40e685 100644
--- a/src/java/jni/org_apache_mesos_state_ZooKeeperState.cpp
+++ b/src/java/jni/org_apache_mesos_state_ZooKeeperState.cpp
@@ -1,9 +1,6 @@
 #include <jni.h>
 
 #include <string>
-#include <vector>
-
-#include <process/future.hpp>
 
 #include <stout/duration.hpp>
 
@@ -15,10 +12,7 @@
 
 using namespace mesos::internal::state;
 
-using process::Future;
-
 using std::string;
-using std::vector;
 
 extern "C" {
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/3b3c1497/src/java/src/org/apache/mesos/state/LevelDBState.java
----------------------------------------------------------------------
diff --git a/src/java/src/org/apache/mesos/state/LevelDBState.java b/src/java/src/org/apache/mesos/state/LevelDBState.java
new file mode 100644
index 0000000..d4e7aa9
--- /dev/null
+++ b/src/java/src/org/apache/mesos/state/LevelDBState.java
@@ -0,0 +1,36 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.mesos.state;
+
+/**
+ * Implementation of State that uses LevelDB to store
+ * variables/values.
+ */
+public class LevelDBState extends AbstractState {
+  /**
+   * Constructs a new instance of LevelDBState.
+   *
+   * @param path absolute path to database.
+   */
+  public LevelDBState(String path) {
+    initialize(path);
+  }
+
+  protected native void initialize(String path);
+}