@ -1,12 +1,12 @@
// Copyright (c) 2014 , Facebook, Inc. All rights reserved.
// Copyright (c) 2015 , Facebook, Inc. All rights reserved.
// This source code is licensed under the BSD-style license found in the
// LICENSE file in the root directory of this source tree. An additional grant
// of patent rights can be found in the PATENTS file in the same directory.
//
// This file implements the callback "bridge" between Java and C++ for
// rocksdb::Comparato r.
// rocksdb::Logge r.
# include "include/org_rocksdb_Abstract Logger.h"
# include "include/org_rocksdb_Logger.h"
# include "rocksjni/loggerjnicallback.h"
# include "rocksjni/portal.h"
@ -14,15 +14,15 @@
namespace rocksdb {
LoggerJniCallback : : LoggerJniCallback (
JNIEnv * env , jobject jAbstractL ogger ) {
JNIEnv * env , jobject jl ogger ) {
const jint rs = env - > GetJavaVM ( & m_jvm ) ;
assert ( rs = = JNI_OK ) ;
// Note: we want to access the Java Logger instance
// across multiple method calls, so we create a global ref
m_jAbstract Logger = env - > NewGlobalRef ( jAbstractL ogger ) ;
m_jLogMethodId = Abstract LoggerJni: : getLogMethodId ( env ) ;
m_jLogger = env - > NewGlobalRef ( jl ogger ) ;
m_jLogMethodId = LoggerJni : : getLogMethodId ( env ) ;
}
/**
@ -44,6 +44,27 @@ void LoggerJniCallback::Logv(const InfoLogLevel log_level,
const char * format , va_list ap ) {
if ( GetInfoLogLevel ( ) < = log_level ) {
JNIEnv * env = getJniEnv ( ) ;
// determine InfoLogLevel java enum instance
jobject jlog_level ;
switch ( log_level ) {
case rocksdb : : InfoLogLevel : : DEBUG_LEVEL :
jlog_level = InfoLogLevelJni : : DEBUG_LEVEL ( env ) ;
break ;
case rocksdb : : InfoLogLevel : : INFO_LEVEL :
jlog_level = InfoLogLevelJni : : INFO_LEVEL ( env ) ;
break ;
case rocksdb : : InfoLogLevel : : ERROR_LEVEL :
jlog_level = InfoLogLevelJni : : ERROR_LEVEL ( env ) ;
break ;
case rocksdb : : InfoLogLevel : : FATAL_LEVEL :
jlog_level = InfoLogLevelJni : : FATAL_LEVEL ( env ) ;
break ;
default :
jlog_level = InfoLogLevelJni : : FATAL_LEVEL ( env ) ;
break ;
}
// We try twice: the first time with a fixed-size stack allocated buffer,
// and the second time with a much larger dynamically allocated buffer.
char buffer [ 500 ] ;
@ -77,26 +98,9 @@ void LoggerJniCallback::Logv(const InfoLogLevel log_level,
assert ( p < limit ) ;
* p + + = ' \0 ' ;
// determine InfoLogLevel java enum instance
jobject jlog_level ;
switch ( log_level ) {
case rocksdb : : InfoLogLevel : : DEBUG_LEVEL :
jlog_level = InfoLogLevelJni : : DEBUG_LEVEL ( env ) ;
break ;
case rocksdb : : InfoLogLevel : : INFO_LEVEL :
jlog_level = InfoLogLevelJni : : INFO_LEVEL ( env ) ;
break ;
case rocksdb : : InfoLogLevel : : ERROR_LEVEL :
jlog_level = InfoLogLevelJni : : ERROR_LEVEL ( env ) ;
case rocksdb : : InfoLogLevel : : FATAL_LEVEL :
jlog_level = InfoLogLevelJni : : FATAL_LEVEL ( env ) ;
default :
jlog_level = InfoLogLevelJni : : FATAL_LEVEL ( env ) ;
break ;
}
// pass java string to callback handler
env - > CallVoidMethod (
m_jAbstract Logger ,
m_jLogger ,
m_jLogMethodId ,
jlog_level ,
env - > NewStringUTF ( base ) ) ;
@ -112,18 +116,18 @@ void LoggerJniCallback::Logv(const InfoLogLevel log_level,
LoggerJniCallback : : ~ LoggerJniCallback ( ) {
JNIEnv * env = getJniEnv ( ) ;
env - > DeleteGlobalRef ( m_jAbstract Logger ) ;
env - > DeleteGlobalRef ( m_jLogger ) ;
m_jvm - > DetachCurrentThread ( ) ;
}
} // namespace rocksdb
/*
* Class : org_rocksdb_Abstract Logger
* Class : org_rocksdb_Logger
* Method : createNewLoggerOptions
* Signature : ( J ) V
*/
void Java_org_rocksdb_Abstract Logger_createNewLoggerOptions (
void Java_org_rocksdb_Logger_createNewLoggerOptions (
JNIEnv * env , jobject jobj , jlong joptions ) {
rocksdb : : LoggerJniCallback * c =
new rocksdb : : LoggerJniCallback ( env , jobj ) ;
@ -133,15 +137,15 @@ void Java_org_rocksdb_AbstractLogger_createNewLoggerOptions(
std : : shared_ptr < rocksdb : : LoggerJniCallback > * pLoggerJniCallback =
new std : : shared_ptr < rocksdb : : LoggerJniCallback > ;
* pLoggerJniCallback = std : : shared_ptr < rocksdb : : LoggerJniCallback > ( c ) ;
rocksdb : : Abstract LoggerJni: : setHandle ( env , jobj , pLoggerJniCallback ) ;
rocksdb : : LoggerJni : : setHandle ( env , jobj , pLoggerJniCallback ) ;
}
/*
* Class : org_rocksdb_Abstract Logger
* Class : org_rocksdb_Logger
* Method : createNewLoggerDbOptions
* Signature : ( J ) V
*/
void Java_org_rocksdb_Abstract Logger_createNewLoggerDbOptions (
void Java_org_rocksdb_Logger_createNewLoggerDbOptions (
JNIEnv * env , jobject jobj , jlong jdb_options ) {
rocksdb : : LoggerJniCallback * c =
new rocksdb : : LoggerJniCallback ( env , jobj ) ;
@ -151,15 +155,15 @@ void Java_org_rocksdb_AbstractLogger_createNewLoggerDbOptions(
std : : shared_ptr < rocksdb : : LoggerJniCallback > * pLoggerJniCallback =
new std : : shared_ptr < rocksdb : : LoggerJniCallback > ;
* pLoggerJniCallback = std : : shared_ptr < rocksdb : : LoggerJniCallback > ( c ) ;
rocksdb : : Abstract LoggerJni: : setHandle ( env , jobj , pLoggerJniCallback ) ;
rocksdb : : LoggerJni : : setHandle ( env , jobj , pLoggerJniCallback ) ;
}
/*
* Class : org_rocksdb_Abstract Logger
* Class : org_rocksdb_Logger
* Method : setInfoLogLevel
* Signature : ( JB ) V
*/
void Java_org_rocksdb_Abstract Logger_setInfoLogLevel (
void Java_org_rocksdb_Logger_setInfoLogLevel (
JNIEnv * env , jobject jobj , jlong jhandle , jbyte jlog_level ) {
std : : shared_ptr < rocksdb : : LoggerJniCallback > * handle =
reinterpret_cast < std : : shared_ptr < rocksdb : : LoggerJniCallback > * > ( jhandle ) ;
@ -167,11 +171,11 @@ void Java_org_rocksdb_AbstractLogger_setInfoLogLevel(
}
/*
* Class : org_rocksdb_Abstract Logger
* Class : org_rocksdb_Logger
* Method : infoLogLevel
* Signature : ( J ) B
*/
jbyte Java_org_rocksdb_Abstract Logger_infoLogLevel (
jbyte Java_org_rocksdb_Logger_infoLogLevel (
JNIEnv * env , jobject jobj , jlong jhandle ) {
std : : shared_ptr < rocksdb : : LoggerJniCallback > * handle =
reinterpret_cast < std : : shared_ptr < rocksdb : : LoggerJniCallback > * > ( jhandle ) ;
@ -179,11 +183,11 @@ jbyte Java_org_rocksdb_AbstractLogger_infoLogLevel(
}
/*
* Class : org_rocksdb_Abstract Logger
* Class : org_rocksdb_Logger
* Method : disposeInternal
* Signature : ( J ) V
*/
void Java_org_rocksdb_Abstract Logger_disposeInternal (
void Java_org_rocksdb_Logger_disposeInternal (
JNIEnv * env , jobject jobj , jlong jhandle ) {
std : : shared_ptr < rocksdb : : LoggerJniCallback > * handle =
reinterpret_cast < std : : shared_ptr < rocksdb : : LoggerJniCallback > * > ( jhandle ) ;