Add Java API for network busyness

This commit is contained in:
Nim Wijetunga 2021-03-24 23:34:34 +00:00
parent cc083ea1c7
commit b5412b355e
3 changed files with 31 additions and 0 deletions

View File

@ -580,6 +580,17 @@ JNIEXPORT void JNICALL Java_com_apple_foundationdb_FDBDatabase_Database_1setOpti
}
}
JNIEXPORT jdouble JNICALL Java_com_apple_foundationdb_FDBDatabase_Database_1getMainThreadBusyness(JNIEnv* jenv,
jobject,
jlong dbPtr) {
if (!dbPtr) {
throwParamNotNull(jenv);
return 0;
}
FDBDatabase* database = (FDBDatabase*)dbPtr;
return (jdouble) fdb_database_get_main_thread_busyness(database);
}
JNIEXPORT jboolean JNICALL Java_com_apple_foundationdb_FDB_Error_1predicate(JNIEnv* jenv,
jobject,
jint predicate,

View File

@ -80,6 +80,15 @@ public interface Database extends AutoCloseable, TransactionContext {
*/
DatabaseOptions options();
/**
* Returns a value which indicates the saturation of the client
* <br>
* <b>Note:</b> By default, this value is updated every second
*
* @return a value where 0 indicates that the client is idle and 1 (or larger) indicates that the client is saturated.
*/
double getMainThreadBusyness();
/**
* Runs a read-only transactional function against this {@code Database} with retry logic.
* {@link Function#apply(Object) apply(ReadTransaction)} will be called on the

View File

@ -150,6 +150,16 @@ class FDBDatabase extends NativeObjectWrapper implements Database, OptionConsume
}
}
@Override
public double getMainThreadBusyness() {
pointerReadLock.lock();
try {
return Database_getMainThreadBusyness(getPtr());
} finally {
pointerReadLock.unlock();
}
}
@Override
public Executor getExecutor() {
return executor;
@ -163,4 +173,5 @@ class FDBDatabase extends NativeObjectWrapper implements Database, OptionConsume
private native long Database_createTransaction(long cPtr);
private native void Database_dispose(long cPtr);
private native void Database_setOption(long cPtr, int code, byte[] value) throws FDBException;
private native double Database_getMainThreadBusyness(long cPtr);
}