UNOMI-99 Improve network unavailable and connection timeout handling - Try to improve error handling.
Signed-off-by: Serge Huber <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/incubator-unomi/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-unomi/commit/f597a69a Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/f597a69a Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/f597a69a Branch: refs/heads/feature-UNOMI-5-KARAF4 Commit: f597a69a2cec921cb86eafd6c8e04e880f7ab7a2 Parents: 9cfa2a0 Author: Serge Huber <[email protected]> Authored: Tue Jun 13 22:27:48 2017 +0200 Committer: Serge Huber <[email protected]> Committed: Tue Jun 13 22:27:48 2017 +0200 ---------------------------------------------------------------------- .../services/services/ClusterServiceImpl.java | 34 ++++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/f597a69a/services/src/main/java/org/apache/unomi/services/services/ClusterServiceImpl.java ---------------------------------------------------------------------- diff --git a/services/src/main/java/org/apache/unomi/services/services/ClusterServiceImpl.java b/services/src/main/java/org/apache/unomi/services/services/ClusterServiceImpl.java index a77b978..da54208 100644 --- a/services/src/main/java/org/apache/unomi/services/services/ClusterServiceImpl.java +++ b/services/src/main/java/org/apache/unomi/services/services/ClusterServiceImpl.java @@ -257,20 +257,9 @@ public class ClusterServiceImpl implements ClusterService { } catch (MalformedURLException e) { logger.error("Error connecting to remote JMX server", e); } catch (ConnectException ce) { - if (ce.getMessage() != null && - (ce.getMessage().contains("timed out") || ce.getMessage().contains("Network is unreachable"))) { - logger.warn("RMI Connection timed out or network is unreachable, will reconnect on next request."); - JMXConnector jmxConnector = jmxConnectors.remove(serviceUrl); - try { - if (jmxConnector != null) { - jmxConnector.close(); - } - } catch (Throwable t) { - // ignore any exception when closing a timed out connection. - } - } else { - logger.error("Error retrieving remote JMX data", ce); - } + handleTimeouts(serviceUrl, ce); + } catch (java.rmi.ConnectException ce) { + handleTimeouts(serviceUrl, ce); } catch (IOException e) { logger.error("Error retrieving remote JMX data", e); } catch (MalformedObjectNameException e) { @@ -286,6 +275,23 @@ public class ClusterServiceImpl implements ClusterService { return new ArrayList<ClusterNode>(clusterNodes.values()); } + private void handleTimeouts(String serviceUrl, Throwable throwable) { + if (throwable.getMessage() != null && + (throwable.getMessage().contains("timed out") || throwable.getMessage().contains("Network is unreachable"))) { + logger.warn("RMI Connection timed out or network is unreachable, will reconnect on next request."); + JMXConnector jmxConnector = jmxConnectors.remove(serviceUrl); + try { + if (jmxConnector != null) { + jmxConnector.close(); + } + } catch (Throwable t) { + // ignore any exception when closing a timed out connection. + } + } else { + logger.error("Error retrieving remote JMX data", throwable); + } + } + @Override public void purge(Date date) { persistenceService.purge(date);
