Java Binding: add option to not close network thread on shutdown hook
This commit is contained in:
parent
d035d4f30c
commit
a38827b4e6
|
@ -107,10 +107,10 @@ public class FDB {
|
|||
this(apiVersion, true);
|
||||
}
|
||||
|
||||
private FDB(int apiVersion, boolean controlRuntime) {
|
||||
private FDB(int apiVersion, boolean stopOnShutdown) {
|
||||
this.apiVersion = apiVersion;
|
||||
options = new NetworkOptions(this::Network_setOption);
|
||||
if (controlRuntime) {
|
||||
if (stopOnShutdown) {
|
||||
Runtime.getRuntime().addShutdownHook(new Thread(this::stopNetwork));
|
||||
}
|
||||
}
|
||||
|
@ -172,18 +172,31 @@ public class FDB {
|
|||
* the API version of your application after upgrading your client until the
|
||||
* cluster has also been upgraded.
|
||||
*
|
||||
* Note: automatically stops network thread upon runtime shutdown, if this
|
||||
* behavior is undesirable use {@link #selectAPIVersion(int, boolean)}
|
||||
*
|
||||
* @param version the API version required
|
||||
*
|
||||
* @return the FoundationDB API object
|
||||
* @see #selectAPIVersion(int, boolean)
|
||||
*/
|
||||
public static FDB selectAPIVersion(final int version) throws FDBException {
|
||||
return selectAPIVersion(version, true);
|
||||
}
|
||||
|
||||
/**
|
||||
This function is called from C++ if the VM is controlled directly from FDB
|
||||
* Same as {@link #selectAPIVersion(int)} but lets use choose whether you want to close
|
||||
* FDB connection automatically on runtime shutdown or you want to do it manually.
|
||||
*
|
||||
* Dev Note: This function is called from C++ for tests, method signature must be consistent
|
||||
* with JNI call.
|
||||
*
|
||||
* @param version the API version required
|
||||
* @param stopOnShutdown whether you need to stop network thread upon Java runtime shutdown (via
|
||||
* Runtime.getRuntime().addShutdownHook)
|
||||
* @see #selectAPIVersion(int)
|
||||
*/
|
||||
private static synchronized FDB selectAPIVersion(final int version, boolean controlRuntime) throws FDBException {
|
||||
public static synchronized FDB selectAPIVersion(final int version, boolean stopOnShutdown) throws FDBException {
|
||||
if(singleton != null) {
|
||||
if(version != singleton.getAPIVersion()) {
|
||||
throw new IllegalArgumentException(
|
||||
|
@ -197,7 +210,7 @@ public class FDB {
|
|||
throw new IllegalArgumentException("API version not supported (maximum 620)");
|
||||
|
||||
Select_API_version(version);
|
||||
FDB fdb = new FDB(version, controlRuntime);
|
||||
FDB fdb = new FDB(version, stopOnShutdown);
|
||||
|
||||
return singleton = fdb;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue