Configurable shutdown hook
This commit is contained in:
parent
c39f101002
commit
aa1d93d97a
@ -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)
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user