This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 727
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #149 from matthewbogner/idle-connection-reaping
New feature: Idle connection reaper - opt-in ability to clean idle connections in the pool periodically.
- Loading branch information
Showing
11 changed files
with
262 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
jest-common/src/main/java/io/searchbox/client/config/idle/IdleConnectionReaper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package io.searchbox.client.config.idle; | ||
|
||
import com.google.common.util.concurrent.AbstractScheduledService; | ||
import io.searchbox.client.config.ClientConfig; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* Used to reap idle connections from the connection manager. | ||
*/ | ||
public class IdleConnectionReaper extends AbstractScheduledService { | ||
|
||
final static Logger logger = LoggerFactory.getLogger(IdleConnectionReaper.class); | ||
|
||
private final ReapableConnectionManager reapableConnectionManager; | ||
private final ClientConfig clientConfig; | ||
|
||
public IdleConnectionReaper(ClientConfig clientConfig, ReapableConnectionManager reapableConnectionManager) { | ||
this.reapableConnectionManager = reapableConnectionManager; | ||
this.clientConfig = clientConfig; | ||
} | ||
|
||
@Override | ||
protected void runOneIteration() throws Exception { | ||
logger.debug("closing idle connections..."); | ||
reapableConnectionManager.closeIdleConnections(clientConfig.getMaxConnectionIdleTime(), | ||
clientConfig.getMaxConnectionIdleTimeDurationTimeUnit()); | ||
} | ||
|
||
@Override | ||
protected Scheduler scheduler() { | ||
return Scheduler.newFixedDelaySchedule(0l, | ||
clientConfig.getMaxConnectionIdleTime(), | ||
clientConfig.getMaxConnectionIdleTimeDurationTimeUnit()); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
jest-common/src/main/java/io/searchbox/client/config/idle/ReapableConnectionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.searchbox.client.config.idle; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
public interface ReapableConnectionManager { | ||
void closeIdleConnections(long idleTimeout, TimeUnit unit); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
jest-droid/src/main/java/com/searchly/jestdroid/DroidReapableConnectionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.searchly.jestdroid; | ||
|
||
import ch.boye.httpclientandroidlib.impl.conn.PoolingClientConnectionManager; | ||
import io.searchbox.client.config.idle.ReapableConnectionManager; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
public class DroidReapableConnectionManager implements ReapableConnectionManager { | ||
|
||
private final PoolingClientConnectionManager connectionManager; | ||
|
||
public DroidReapableConnectionManager(PoolingClientConnectionManager connectionManager) { | ||
this.connectionManager = connectionManager; | ||
} | ||
|
||
@Override | ||
public void closeIdleConnections(long idleTimeout, TimeUnit unit) { | ||
connectionManager.closeIdleConnections(idleTimeout, unit); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file added
BIN
+301 KB
jest/lib/bin/lib/x86_64-MacOSX-gpp/jni/libbarchart-udt-core-2.3.0-SNAPSHOT.jnilib
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
jest/src/main/java/io/searchbox/client/config/idle/HttpReapableConnectionManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.searchbox.client.config.idle; | ||
|
||
import org.apache.http.conn.HttpClientConnectionManager; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
public class HttpReapableConnectionManager implements ReapableConnectionManager { | ||
private final HttpClientConnectionManager connectionManager; | ||
|
||
public HttpReapableConnectionManager(HttpClientConnectionManager connectionManager) { | ||
this.connectionManager = connectionManager; | ||
} | ||
|
||
@Override | ||
public void closeIdleConnections(long idleTimeout, TimeUnit unit) { | ||
connectionManager.closeIdleConnections(idleTimeout, unit); | ||
} | ||
} |
Oops, something went wrong.