summaryrefslogtreecommitdiffstats
path: root/container-search/src/main/java/com/yahoo/fs4
diff options
context:
space:
mode:
authorOlli Virtanen <olli.virtanen@oath.com>2018-10-22 14:39:59 +0200
committerOlli Virtanen <olli.virtanen@oath.com>2018-10-22 14:39:59 +0200
commitedf46c3e106da961c522add0691dfa090d8637a1 (patch)
tree01d8dfe9bf6b3c50b024877d144181092af6192f /container-search/src/main/java/com/yahoo/fs4
parented5b6938cb9c5005beb100cac2ce492fc2435b05 (diff)
Test connection to content node before committing to using it
Diffstat (limited to 'container-search/src/main/java/com/yahoo/fs4')
-rw-r--r--container-search/src/main/java/com/yahoo/fs4/mplex/Backend.java25
1 files changed, 25 insertions, 0 deletions
diff --git a/container-search/src/main/java/com/yahoo/fs4/mplex/Backend.java b/container-search/src/main/java/com/yahoo/fs4/mplex/Backend.java
index 2a90e746378..202ee94383f 100644
--- a/container-search/src/main/java/com/yahoo/fs4/mplex/Backend.java
+++ b/container-search/src/main/java/com/yahoo/fs4/mplex/Backend.java
@@ -354,6 +354,31 @@ public class Backend implements ConnectionFactory {
}
/**
+ * Attempt to establish a connection without sending messages and then
+ * return it to the pool. The assumption is that if the probing is
+ * successful, the connection will be used soon after. There should be
+ * minimal overhead since the connection is cached.
+ */
+ public boolean probeConnection() {
+ if (shutdownInitiated) {
+ return false;
+ }
+
+ FS4Connection connection = null;
+ try {
+ connection = getConnection();
+ } catch (IOException ignored) {
+ // connection is null
+ } finally {
+ if (connection != null) {
+ returnConnection(connection);
+ }
+ }
+
+ return connection != null;
+ }
+
+ /**
* This method should be used to ensure graceful shutdown of the backend.
*/
public void shutdown() {