diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2020-02-28 21:00:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-28 21:00:20 +0100 |
commit | d7d45b7ffb89d8c9f870a647e709ae60fe9ab762 (patch) | |
tree | 0d716afecb251e885aedf468bdeb465a73dc3e7f | |
parent | a814b598a28ebeae8d20dea5e027f0fa7aa6eee8 (diff) | |
parent | e0b4c97765340ed15935afd35b90792be1646256 (diff) |
Merge pull request #12382 from vespa-engine/balder/pre-connect-to-backend
Connect early as you know you will need them soon.
-rw-r--r-- | container-search/src/main/java/com/yahoo/search/dispatch/rpc/RpcClient.java | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/dispatch/rpc/RpcClient.java b/container-search/src/main/java/com/yahoo/search/dispatch/rpc/RpcClient.java index a2821892358..52cb2b4c061 100644 --- a/container-search/src/main/java/com/yahoo/search/dispatch/rpc/RpcClient.java +++ b/container-search/src/main/java/com/yahoo/search/dispatch/rpc/RpcClient.java @@ -44,13 +44,14 @@ class RpcClient implements Client { // The current shared connection. This will be recycled when it becomes invalid. // All access to this must be synchronized - private Target target = null; + private Target target; public RpcNodeConnection(String hostname, int port, Supervisor supervisor) { this.supervisor = supervisor; this.hostname = hostname; this.port = port; description = "rpc node connection to " + hostname + ":" + port; + target = supervisor.connect(new Spec(hostname, port)); } @Override @@ -79,17 +80,16 @@ class RpcClient implements Client { private void invokeAsync(Request req, double timeout, RequestWaiter waiter) { // TODO: Consider replacing this by a watcher on the target synchronized(this) { // ensure we have exactly 1 valid connection across threads - if (target == null || ! target.isValid()) + if (! target.isValid()) { target = supervisor.connect(new Spec(hostname, port)); + } } target.invokeAsync(req, timeout, waiter); } @Override public void close() { - if (target != null) { - target.close(); - } + target.close(); } @Override |