diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2019-05-16 12:05:44 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2019-05-16 12:05:44 +0200 |
commit | ba6711be92d89a0191eaa45400c75f7a2b3dfb46 (patch) | |
tree | 3de958074425cb29d243026ad77bb113d03eb1f2 /messagebus | |
parent | ea1409bfa056576f7afa664553e58a7062afe542 (diff) |
- Use double checked locking to ensure that we do not create Policies that we forget to destroy.
- Catch exceptions and close/destroy when necessary.
Diffstat (limited to 'messagebus')
-rwxr-xr-x | messagebus/src/main/java/com/yahoo/messagebus/ProtocolRepository.java | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/messagebus/src/main/java/com/yahoo/messagebus/ProtocolRepository.java b/messagebus/src/main/java/com/yahoo/messagebus/ProtocolRepository.java index ad26475bf74..102e0be923d 100755 --- a/messagebus/src/main/java/com/yahoo/messagebus/ProtocolRepository.java +++ b/messagebus/src/main/java/com/yahoo/messagebus/ProtocolRepository.java @@ -28,7 +28,7 @@ public class ProtocolRepository { */ public void putProtocol(Protocol protocol) { if (protocols.put(protocol.getName(), protocol) != null) { - routingPolicyCache.clear(); + clearPolicyCache(); } } @@ -72,6 +72,10 @@ public class ProtocolRepository { return ret; } synchronized (this) { + ret = routingPolicyCache.get(cacheKey); + if (ret != null) { + return ret; + } Protocol protocol = getProtocol(protocolName); if (protocol == null) { log.log(LogLevel.ERROR, "Protocol '" + protocolName + "' not supported."); @@ -81,6 +85,9 @@ public class ProtocolRepository { ret = protocol.createPolicy(policyName, policyParam); } catch (RuntimeException e) { log.log(LogLevel.ERROR, "Protcol '" + protocolName + "' threw an exception: " + e.getMessage(), e); + if (ret != null) { + ret.destroy(); + } return null; } if (ret == null) { |