You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by ji...@apache.org on 2017/12/21 22:28:34 UTC
[8/8] mesos git commit: Added Log.Reader.catchup() method to Java
bindings.
Added Log.Reader.catchup() method to Java bindings.
The new method is a wrapper for Log::Reader::catchup() method of the C++
Replicated Log API.
Review: https://reviews.apache.org/r/62288/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/310c2c61
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/310c2c61
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/310c2c61
Branch: refs/heads/master
Commit: 310c2c6129e09097f5d31431f754e2285b3c3f58
Parents: 49c9161
Author: Ilya Pronin <ip...@twopensource.com>
Authored: Thu Dec 21 12:50:04 2017 -0800
Committer: Jie Yu <yu...@gmail.com>
Committed: Thu Dec 21 12:50:04 2017 -0800
----------------------------------------------------------------------
src/java/jni/org_apache_mesos_Log.cpp | 41 +++++++++++++++++++++++++++++
src/java/src/org/apache/mesos/Log.java | 17 ++++++++++++
2 files changed, 58 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/310c2c61/src/java/jni/org_apache_mesos_Log.cpp
----------------------------------------------------------------------
diff --git a/src/java/jni/org_apache_mesos_Log.cpp b/src/java/jni/org_apache_mesos_Log.cpp
index eb0f54b..e5e632c 100644
--- a/src/java/jni/org_apache_mesos_Log.cpp
+++ b/src/java/jni/org_apache_mesos_Log.cpp
@@ -234,6 +234,47 @@ JNIEXPORT jobject JNICALL Java_org_apache_mesos_Log_00024Reader_ending
/*
* Class: org_apache_mesos_Log_Reader
+ * Method: catchup
+ * Signature: (JLjava/util/concurrent/TimeUnit;)Lorg/apache/mesos/Log/Position;
+ */
+JNIEXPORT jobject JNICALL Java_org_apache_mesos_Log_00024Reader_catchup
+ (JNIEnv* env, jobject thiz, jlong jtimeout, jobject junit)
+{
+ // Read out __reader.
+ jclass clazz = env->GetObjectClass(thiz);
+ jfieldID __reader = env->GetFieldID(clazz, "__reader", "J");
+ Log::Reader* reader = (Log::Reader*)env->GetLongField(thiz, __reader);
+
+ // long seconds = unit.toSeconds(time);
+ clazz = env->GetObjectClass(junit);
+ jmethodID toSeconds = env->GetMethodID(clazz, "toSeconds", "(J)J");
+ jlong jseconds = env->CallLongMethod(junit, toSeconds, jtimeout);
+
+ Future<Log::Position> position = reader->catchup();
+
+ if (!position.await(Seconds(jseconds))) {
+ // Timed out while trying to catchup the log.
+ position.discard();
+ clazz = env->FindClass("java/util/concurrent/TimeoutException");
+ env->ThrowNew(clazz, "Timed out while attempting to catchup");
+ return nullptr;
+ } else if (!position.isReady()) {
+ // Failed to catchup the log.
+ clazz = env->FindClass("org/apache/mesos/Log$OperationFailedException");
+ env->ThrowNew(
+ clazz,
+ (position.isFailed()
+ ? position.failure().c_str() : "Discarded future"));
+ return nullptr;
+ }
+
+ jobject jposition = convert<Log::Position>(env, position.get());
+ return jposition;
+}
+
+
+/*
+ * Class: org_apache_mesos_Log_Reader
* Method: initialize
* Signature: (Lorg/apache/mesos/Log;)V
*/
http://git-wip-us.apache.org/repos/asf/mesos/blob/310c2c61/src/java/src/org/apache/mesos/Log.java
----------------------------------------------------------------------
diff --git a/src/java/src/org/apache/mesos/Log.java b/src/java/src/org/apache/mesos/Log.java
index f53d9eb..f00f457 100644
--- a/src/java/src/org/apache/mesos/Log.java
+++ b/src/java/src/org/apache/mesos/Log.java
@@ -238,6 +238,23 @@ public class Log {
*/
public native Position ending();
+ /**
+ * Attempts to catch-up positions from the log for reading.
+ *
+ * @param timeout Max number of time units to wait before a
+ * {@link TimeoutException}.
+ * @param unit Type of time units used for the timeout, e.g. seconds,
+ * minutes, etc.
+ *
+ * @return The ending position of the caught-up range.
+ *
+ * @throws TimeoutException If the catch-up doesn't happen before
+ * the timeout.
+ * @throws OperationFailedException If the catch-up fails.
+ */
+ public native Position catchup(long timeout, TimeUnit unit)
+ throws TimeoutException, OperationFailedException;
+
protected native void initialize(Log log);
protected native void finalize();