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`
|
- `tdlight-natives-osx-amd64`
|
||||||
|
|
||||||
## Usage
|
## 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)
|
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
|
### TDLight methods documentation
|
||||||
[TdApi JavaDoc](https://tdlight-team.github.io/tdlight-docs)
|
[TdApi JavaDoc](https://tdlight-team.github.io/tdlight-docs)
|
||||||
|
|
||||||
|
@ -191,11 +191,13 @@ public final class InternalClient implements ClientEventsHandler, TelegramClient
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onJVMShutdown() {
|
private void onJVMShutdown() {
|
||||||
try {
|
if ("true".equalsIgnoreCase(System.getProperty("it.tdlight.enableShutdownHooks", "true"))) {
|
||||||
logger.info(TG_MARKER, "Client {} is shutting down because the JVM is shutting down", clientId);
|
try {
|
||||||
this.send(new TdApi.Close(), result -> {}, ex -> {});
|
logger.info(TG_MARKER, "Client {} is shutting down because the JVM is shutting down", clientId);
|
||||||
} catch (Throwable ex) {
|
this.send(new TdApi.Close(), result -> {}, ex -> {});
|
||||||
logger.debug("Failed to send shutdown request to session {}", clientId);
|
} 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() {
|
private void onJVMShutdown() {
|
||||||
try {
|
if ("true".equalsIgnoreCase(System.getProperty("it.tdlight.enableShutdownHooks", "true"))) {
|
||||||
logger.info(TG_MARKER, "Client {} is shutting down because the JVM is shutting down", clientId);
|
try {
|
||||||
sendCloseAndIgnoreResponse();
|
logger.info(TG_MARKER, "Client {} is shutting down because the JVM is shutting down", clientId);
|
||||||
} catch (Throwable ex) {
|
sendCloseAndIgnoreResponse();
|
||||||
logger.debug("Failed to send shutdown request to session {}", clientId);
|
} catch (Throwable ex) {
|
||||||
|
logger.debug("Failed to send shutdown request to session {}", clientId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user