From 7d1bbf9b372e41121198be2b9f0f322d58b8d014 Mon Sep 17 00:00:00 2001
From: Matthew Swift <matthew.swift@forgerock.com>
Date: Wed, 18 Sep 2013 16:28:59 +0000
Subject: [PATCH] Backport fix for OPENDJ-1058 – HeartbeatConnectionFactory does not actively shutdown dead connections

---
 opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/Connections.java |   31 ++++++++++++++++++++++---------
 1 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/Connections.java b/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/Connections.java
index 985c887..3b0b6df 100644
--- a/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/Connections.java
+++ b/opendj-ldap-sdk/src/main/java/org/forgerock/opendj/ldap/Connections.java
@@ -245,7 +245,8 @@
      * Creates a new heart-beat connection factory which will create connections
      * using the provided connection factory and periodically ping any created
      * connections in order to detect that they are still alive every 10 seconds
-     * using the default scheduler.
+     * using the default scheduler. Connections will be marked as having failed
+     * if a heart-beat takes longer than 500ms.
      *
      * @param factory
      *            The connection factory to use for creating connections.
@@ -254,7 +255,8 @@
      *             If {@code factory} was {@code null}.
      */
     public static ConnectionFactory newHeartBeatConnectionFactory(final ConnectionFactory factory) {
-        return new HeartBeatConnectionFactory(factory);
+        return new HeartBeatConnectionFactory(factory, 10000, 500, TimeUnit.MILLISECONDS, null,
+                null);
     }
 
     /**
@@ -267,6 +269,9 @@
      *            The connection factory to use for creating connections.
      * @param interval
      *            The interval between keepalive pings.
+     * @param timeout
+     *            The heart-beat timeout after which a connection will be marked
+     *            as failed.
      * @param unit
      *            The time unit for the interval between keepalive pings.
      * @return The new heart-beat connection factory.
@@ -276,8 +281,8 @@
      *             If {@code factory} or {@code unit} was {@code null}.
      */
     public static ConnectionFactory newHeartBeatConnectionFactory(final ConnectionFactory factory,
-            final long interval, final TimeUnit unit) {
-        return new HeartBeatConnectionFactory(factory, interval, unit);
+            final long interval, final long timeout, final TimeUnit unit) {
+        return new HeartBeatConnectionFactory(factory, interval, timeout, unit, null, null);
     }
 
     /**
@@ -290,6 +295,9 @@
      *            The connection factory to use for creating connections.
      * @param interval
      *            The interval between keepalive pings.
+     * @param timeout
+     *            The heart-beat timeout after which a connection will be marked
+     *            as failed.
      * @param unit
      *            The time unit for the interval between keepalive pings.
      * @param heartBeat
@@ -302,8 +310,9 @@
      *             {@code null}.
      */
     public static ConnectionFactory newHeartBeatConnectionFactory(final ConnectionFactory factory,
-            final long interval, final TimeUnit unit, final SearchRequest heartBeat) {
-        return new HeartBeatConnectionFactory(factory, interval, unit, heartBeat);
+            final long interval, final long timeout, final TimeUnit unit,
+            final SearchRequest heartBeat) {
+        return new HeartBeatConnectionFactory(factory, interval, timeout, unit, heartBeat, null);
     }
 
     /**
@@ -316,6 +325,9 @@
      *            The connection factory to use for creating connections.
      * @param interval
      *            The interval between keepalive pings.
+     * @param timeout
+     *            The heart-beat timeout after which a connection will be marked
+     *            as failed.
      * @param unit
      *            The time unit for the interval between keepalive pings.
      * @param heartBeat
@@ -331,9 +343,10 @@
      *             {@code null}.
      */
     public static ConnectionFactory newHeartBeatConnectionFactory(final ConnectionFactory factory,
-            final long interval, final TimeUnit unit, final SearchRequest heartBeat,
-            final ScheduledExecutorService scheduler) {
-        return new HeartBeatConnectionFactory(factory, interval, unit, heartBeat, scheduler);
+            final long interval, final long timeout, final TimeUnit unit,
+            final SearchRequest heartBeat, final ScheduledExecutorService scheduler) {
+        return new HeartBeatConnectionFactory(factory, interval, timeout, unit, heartBeat,
+                scheduler);
     }
 
     /**

--
Gitblit v1.10.0