transaction_notifier_jnicallback.cc 1.4 KB

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