Configurable shutdown hook

This commit is contained in:
Andrea Cavalli 2021-10-06 20:43:57 +02:00
parent c39f101002
commit aa1d93d97a
3 changed files with 17 additions and 11 deletions

View File

@ -107,9 +107,11 @@ To use TDLight Java you need to include one or more native dependencies:
- `tdlight-natives-osx-amd64`
## Usage
An example on how to use TDLight Java can be found here: [Example.java](https://github.com/tdlight-team/tdlight-java/blob/master/example/src/main/java/it.tdlight.example/Example.java)
### Advanced usage
If you want to disable the automatic runtime shutdown hook, you should set the property `it.tdlight.enableShutdownHooks` to `false`
### TDLight methods documentation
[TdApi JavaDoc](https://tdlight-team.github.io/tdlight-docs)

View File

@ -191,11 +191,13 @@ public final class InternalClient implements ClientEventsHandler, TelegramClient
}
private void onJVMShutdown() {
try {
logger.info(TG_MARKER, "Client {} is shutting down because the JVM is shutting down", clientId);
this.send(new TdApi.Close(), result -> {}, ex -> {});
} catch (Throwable ex) {
logger.debug("Failed to send shutdown request to session {}", clientId);
if ("true".equalsIgnoreCase(System.getProperty("it.tdlight.enableShutdownHooks", "true"))) {
try {
logger.info(TG_MARKER, "Client {} is shutting down because the JVM is shutting down", clientId);
this.send(new TdApi.Close(), result -> {}, ex -> {});
} catch (Throwable ex) {
logger.debug("Failed to send shutdown request to session {}", clientId);
}
}
}

View File

@ -310,11 +310,13 @@ public final class InternalReactiveClient implements ClientEventsHandler, Reacti
}
private void onJVMShutdown() {
try {
logger.info(TG_MARKER, "Client {} is shutting down because the JVM is shutting down", clientId);
sendCloseAndIgnoreResponse();
} catch (Throwable ex) {
logger.debug("Failed to send shutdown request to session {}", clientId);
if ("true".equalsIgnoreCase(System.getProperty("it.tdlight.enableShutdownHooks", "true"))) {
try {
logger.info(TG_MARKER, "Client {} is shutting down because the JVM is shutting down", clientId);
sendCloseAndIgnoreResponse();
} catch (Throwable ex) {
logger.debug("Failed to send shutdown request to session {}", clientId);
}
}
}