Repository: incubator-unomi Updated Branches: refs/heads/master 38489feed -> 15ba3c9e3
UNOMI-99 Improve network unavailable and connection timeout handling - Try to improve error handling. - Avoid going to persistence API if requesting a condition type using a null id. 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/15ba3c9e Tree: http://git-wip-us.apache.org/repos/asf/incubator-unomi/tree/15ba3c9e Diff: http://git-wip-us.apache.org/repos/asf/incubator-unomi/diff/15ba3c9e Branch: refs/heads/master Commit: 15ba3c9e30126b66413e15c19e9a9e5e7e491110 Parents: 38489fe Author: Serge Huber <[email protected]> Authored: Fri Jun 16 13:58:24 2017 +0200 Committer: Serge Huber <[email protected]> Committed: Fri Jun 16 13:58:24 2017 +0200 ---------------------------------------------------------------------- .../services/services/ClusterServiceImpl.java | 26 +++++++++++--------- .../services/DefinitionsServiceImpl.java | 3 +++ 2 files changed, 17 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/15ba3c9e/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 da54208..095e2d4 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 @@ -260,6 +260,8 @@ public class ClusterServiceImpl implements ClusterService { handleTimeouts(serviceUrl, ce); } catch (java.rmi.ConnectException ce) { handleTimeouts(serviceUrl, ce); + } catch (java.rmi.ConnectIOException coie) { + handleTimeouts(serviceUrl, coie); } catch (IOException e) { logger.error("Error retrieving remote JMX data", e); } catch (MalformedObjectNameException e) { @@ -276,19 +278,19 @@ public class ClusterServiceImpl implements ClusterService { } 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. + Throwable rootCause = throwable; + while (rootCause.getCause() != null) { + rootCause = rootCause.getCause(); + } + logger.warn("JMX RMI Connection error, will reconnect on next request. Active debug logging for access to detailed stack trace. Root cause=" + rootCause.getMessage()); + logger.debug("Detailed stacktrace", throwable); + JMXConnector jmxConnector = jmxConnectors.remove(serviceUrl); + try { + if (jmxConnector != null) { + jmxConnector.close(); } - } else { - logger.error("Error retrieving remote JMX data", throwable); + } catch (Throwable t) { + // ignore any exception when closing a timed out connection. } } http://git-wip-us.apache.org/repos/asf/incubator-unomi/blob/15ba3c9e/services/src/main/java/org/apache/unomi/services/services/DefinitionsServiceImpl.java ---------------------------------------------------------------------- diff --git a/services/src/main/java/org/apache/unomi/services/services/DefinitionsServiceImpl.java b/services/src/main/java/org/apache/unomi/services/services/DefinitionsServiceImpl.java index e839836..caaadf5 100644 --- a/services/src/main/java/org/apache/unomi/services/services/DefinitionsServiceImpl.java +++ b/services/src/main/java/org/apache/unomi/services/services/DefinitionsServiceImpl.java @@ -286,6 +286,9 @@ public class DefinitionsServiceImpl implements DefinitionsService, SynchronousBu } public ConditionType getConditionType(String id) { + if (id == null) { + return null; + } ConditionType type = conditionTypeById.get(id); if (type == null) { type = persistenceService.load(id, ConditionType.class);
