1 // Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2 //  This source code is licensed under both the GPLv2 (found in the
3 //  COPYING file in the root directory) and Apache 2.0 License
4 //  (found in the LICENSE.Apache file in the root directory).
5 //
6 // This file implements the callback "bridge" between Java and C++ for
7 // ROCKSDB_NAMESPACE::TransactionNotifier.
8 
9 #include "rocksjni/transaction_notifier_jnicallback.h"
10 #include "rocksjni/portal.h"
11 
12 namespace ROCKSDB_NAMESPACE {
13 
TransactionNotifierJniCallback(JNIEnv * env,jobject jtransaction_notifier)14 TransactionNotifierJniCallback::TransactionNotifierJniCallback(JNIEnv* env,
15     jobject jtransaction_notifier) : JniCallback(env, jtransaction_notifier) {
16   // we cache the method id for the JNI callback
17   m_jsnapshot_created_methodID =
18       AbstractTransactionNotifierJni::getSnapshotCreatedMethodId(env);
19 }
20 
SnapshotCreated(const Snapshot * newSnapshot)21 void TransactionNotifierJniCallback::SnapshotCreated(
22     const Snapshot* newSnapshot) {
23   jboolean attached_thread = JNI_FALSE;
24   JNIEnv* env = getJniEnv(&attached_thread);
25   assert(env != nullptr);
26 
27   env->CallVoidMethod(m_jcallback_obj,
28       m_jsnapshot_created_methodID, reinterpret_cast<jlong>(newSnapshot));
29 
30   if(env->ExceptionCheck()) {
31     // exception thrown from CallVoidMethod
32     env->ExceptionDescribe();  // print out exception to stderr
33     releaseJniEnv(attached_thread);
34     return;
35   }
36 
37   releaseJniEnv(attached_thread);
38 }
39 }  // namespace ROCKSDB_NAMESPACE
40