forked from facebook/rocksdb
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add event listeners to RocksJava (facebook#7425)
Summary: Allows adding event listeners in RocksJava. * Adds listeners getter and setter in `Options` and `DBOptions` classes. * Adds `EventListener` Java interface and base class for implementing custom event listener callbacks - `AbstractEventListener`, which has an underlying native callback class implementing C++ `EventListener` class. * `AbstractEventListener` class has mechanism for selectively enabling its callback methods in order to prevent invoking Java method if it is not implemented. This decreases performance cost in case only subset of event listener callback methods is needed - the JNI code for remaining "no-op" callbacks is not executed. * The code is covered by unit tests in `EventListenerTest.java`, there are also tests added for setting/getting listeners field in `OptionsTest.java` and `DBOptionsTest.java`. Pull Request resolved: facebook#7425 Reviewed By: pdillinger Differential Revision: D24063390 Pulled By: jay-zhuang fbshipit-source-id: 508c359538983d6b765e70d9989c351794a944ee
- Loading branch information
1 parent
b99fe1a
commit 6528ecc
Showing
36 changed files
with
4,324 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved. | ||
// This source code is licensed under both the GPLv2 (found in the | ||
// COPYING file in the root directory) and Apache 2.0 License | ||
// (found in the LICENSE.Apache file in the root directory). | ||
// | ||
// This file implements the "bridge" between Java and C++ for | ||
// rocksdb::EventListener. | ||
|
||
#include <jni.h> | ||
|
||
#include <memory> | ||
|
||
#include "include/org_rocksdb_AbstractEventListener.h" | ||
#include "rocksjni/event_listener_jnicallback.h" | ||
#include "rocksjni/portal.h" | ||
|
||
/* | ||
* Class: org_rocksdb_AbstractEventListener | ||
* Method: createNewEventListener | ||
* Signature: (J)J | ||
*/ | ||
jlong Java_org_rocksdb_AbstractEventListener_createNewEventListener( | ||
JNIEnv* env, jobject jobj, jlong jenabled_event_callback_values) { | ||
auto enabled_event_callbacks = | ||
ROCKSDB_NAMESPACE::EnabledEventCallbackJni::toCppEnabledEventCallbacks( | ||
jenabled_event_callback_values); | ||
auto* sptr_event_listener = | ||
new std::shared_ptr<ROCKSDB_NAMESPACE::EventListener>( | ||
new ROCKSDB_NAMESPACE::EventListenerJniCallback( | ||
env, jobj, enabled_event_callbacks)); | ||
return reinterpret_cast<jlong>(sptr_event_listener); | ||
} | ||
|
||
/* | ||
* Class: org_rocksdb_AbstractEventListener | ||
* Method: disposeInternal | ||
* Signature: (J)V | ||
*/ | ||
void Java_org_rocksdb_AbstractEventListener_disposeInternal(JNIEnv*, jobject, | ||
jlong jhandle) { | ||
delete reinterpret_cast<std::shared_ptr<ROCKSDB_NAMESPACE::EventListener>*>( | ||
jhandle); | ||
} |
Oops, something went wrong.