From e2aed55b11a7011f8bc3eb0c47f38388f4072988 Mon Sep 17 00:00:00 2001 From: Niels Ulrik Andersen Date: Sun, 19 Nov 2017 16:59:23 +0100 Subject: [PATCH] Clean up a bit in DefaultBotSession --- .../updatesreceivers/DefaultBotSession.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/DefaultBotSession.java b/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/DefaultBotSession.java index 55455b6b..2e310b33 100644 --- a/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/DefaultBotSession.java +++ b/telegrambots/src/main/java/org/telegram/telegrambots/updatesreceivers/DefaultBotSession.java @@ -190,9 +190,7 @@ public class DefaultBotSession implements BotSession { try { List updates = updatesSupplier.getUpdates(); if (updates.isEmpty()) { - if (running) { - lock.wait(500); - } + lock.wait(500); } else { updates.removeIf(x -> x.getUpdateId() < lastReceivedUpdate); lastReceivedUpdate = updates.parallelStream() @@ -211,6 +209,7 @@ public class DefaultBotSession implements BotSession { receivedUpdates.clear(); } BotLogger.debug(LOGTAG, e); + interrupt(); } catch (Exception global) { BotLogger.severe(LOGTAG, global); try { @@ -222,6 +221,7 @@ public class DefaultBotSession implements BotSession { receivedUpdates.clear(); } BotLogger.debug(LOGTAG, e); + interrupt(); } } } @@ -230,7 +230,7 @@ public class DefaultBotSession implements BotSession { BotLogger.debug(LOGTAG, "Reader thread has being closed"); } - private List getUpdatesFromServer() throws InterruptedException, Exception { + private List getUpdatesFromServer() throws IOException { GetUpdates request = new GetUpdates() .setLimit(100) .setTimeout(ApiConstants.GETUPDATES_TIMEOUT) @@ -266,12 +266,13 @@ public class DefaultBotSession implements BotSession { BotLogger.severe(responseContent, LOGTAG, e); } } - } catch (SocketException e) { + } catch (SocketException | InvalidObjectException | TelegramApiRequestException e) { BotLogger.severe(LOGTAG, e); } catch (SocketTimeoutException e) { BotLogger.fine(LOGTAG, e); - } catch (InvalidObjectException | TelegramApiRequestException e) { - BotLogger.severe(LOGTAG, e); + } catch (InterruptedException e) { + BotLogger.fine(LOGTAG, e); + interrupt(); } return Collections.emptyList(); } @@ -279,7 +280,7 @@ public class DefaultBotSession implements BotSession { public interface UpdatesSupplier { - List getUpdates() throws InterruptedException, Exception; + List getUpdates() throws Exception; } private List getUpdateList() { @@ -310,6 +311,7 @@ public class DefaultBotSession implements BotSession { callback.onUpdatesReceived(updates); } catch (InterruptedException e) { BotLogger.debug(LOGTAG, e); + interrupt(); } catch (Exception e) { BotLogger.severe(LOGTAG, e); }