transaction_notifier_jnicallback.cc 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. #include "rocksjni/transaction_notifier_jnicallback.h"
  9. #include "rocksjni/portal.h"
  10. namespace ROCKSDB_NAMESPACE {
  11. TransactionNotifierJniCallback::TransactionNotifierJniCallback(JNIEnv* env,
  12. jobject jtransaction_notifier) : JniCallback(env, jtransaction_notifier) {
  13. // we cache the method id for the JNI callback
  14. m_jsnapshot_created_methodID =
  15. AbstractTransactionNotifierJni::getSnapshotCreatedMethodId(env);
  16. }
  17. void TransactionNotifierJniCallback::SnapshotCreated(
  18. const Snapshot* newSnapshot) {
  19. jboolean attached_thread = JNI_FALSE;
  20. JNIEnv* env = getJniEnv(&attached_thread);
  21. assert(env != nullptr);
  22. env->CallVoidMethod(m_jcallback_obj,
  23. m_jsnapshot_created_methodID, reinterpret_cast<jlong>(newSnapshot));
  24. if(env->ExceptionCheck()) {
  25. // exception thrown from CallVoidMethod
  26. env->ExceptionDescribe(); // print out exception to stderr
  27. releaseJniEnv(attached_thread);
  28. return;
  29. }
  30. releaseJniEnv(attached_thread);
  31. }
  32. } // namespace ROCKSDB_NAMESPACE