Add closeable webhook
This commit is contained in:
parent
4b4364f32d
commit
dee9941a1f
|
@ -1,5 +1,8 @@
|
||||||
package org.telegram.telegrambots.updatesreceivers;
|
package org.telegram.telegrambots.updatesreceivers;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import org.glassfish.grizzly.http.server.HttpServer;
|
import org.glassfish.grizzly.http.server.HttpServer;
|
||||||
import org.glassfish.grizzly.ssl.SSLContextConfigurator;
|
import org.glassfish.grizzly.ssl.SSLContextConfigurator;
|
||||||
import org.glassfish.grizzly.ssl.SSLEngineConfigurator;
|
import org.glassfish.grizzly.ssl.SSLEngineConfigurator;
|
||||||
|
@ -19,12 +22,13 @@ import java.net.URI;
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* Webhook to receive updates
|
* Webhook to receive updates
|
||||||
*/
|
*/
|
||||||
public class DefaultWebhook implements Webhook {
|
public class DefaultWebhook implements Webhook, Closeable {
|
||||||
private String keystoreServerFile;
|
private String keystoreServerFile;
|
||||||
private String keystoreServerPwd;
|
private String keystoreServerPwd;
|
||||||
private String internalUrl;
|
private String internalUrl;
|
||||||
|
|
||||||
private final RestApi restApi;
|
private final RestApi restApi;
|
||||||
|
private HttpServer grizzlyServer;
|
||||||
|
|
||||||
public DefaultWebhook() {
|
public DefaultWebhook() {
|
||||||
this.restApi = new RestApi();
|
this.restApi = new RestApi();
|
||||||
|
@ -67,6 +71,7 @@ public class DefaultWebhook implements Webhook {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
this.grizzlyServer = grizzlyServer;
|
||||||
grizzlyServer.start();
|
grizzlyServer.start();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new TelegramApiException("Error starting webhook server", e);
|
throw new TelegramApiException("Error starting webhook server", e);
|
||||||
|
@ -83,4 +88,16 @@ public class DefaultWebhook implements Webhook {
|
||||||
throw new TelegramApiException("Can't find or access server keystore file.");
|
throw new TelegramApiException("Can't find or access server keystore file.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
try {
|
||||||
|
grizzlyServer.shutdown(1, TimeUnit.MINUTES).get();
|
||||||
|
} catch (ExecutionException ex) {
|
||||||
|
throw new IOException("Failed to stop grizzly server", ex.getCause());
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
// timeout
|
||||||
|
}
|
||||||
|
grizzlyServer.shutdownNow();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user