Skip to content

make MaxConnectionIdleTime configurable #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/main/java/com/emc/object/ObjectConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public abstract class ObjectConfig<T extends ObjectConfig<T>> {
public static final int DEFAULT_CHUNKED_ENCODING_SIZE = 2 * 1024 * 1024; // 2MB to match ECS buffer size
public static final int DEFAULT_CONNECT_TIMEOUT = 15000; // 15 seconds
public static final int DEFAULT_READ_TIMEOUT = 0; // default is infinity
public static final int DEFAULT_MAX_CONNECTION_IDLE_TIME = 0;


// NOTE: if you add a property, make sure you add it to the cloning constructor!
private Protocol protocol;
Expand All @@ -79,6 +81,8 @@ public abstract class ObjectConfig<T extends ObjectConfig<T>> {
private int connectTimeout = DEFAULT_CONNECT_TIMEOUT;
private int readTimeout = DEFAULT_READ_TIMEOUT;
private String sessionToken;
private int maxConnectionIdleTime = DEFAULT_MAX_CONNECTION_IDLE_TIME;


private Map<String, Object> properties = new HashMap<String, Object>();

Expand Down Expand Up @@ -137,6 +141,7 @@ public ObjectConfig(ObjectConfig<T> other) {
this.connectTimeout = other.connectTimeout;
this.readTimeout = other.readTimeout;
this.sessionToken = other.sessionToken;
this.maxConnectionIdleTime = other.maxConnectionIdleTime;
this.properties = new HashMap<String, Object>(other.properties);
}

Expand Down Expand Up @@ -218,6 +223,7 @@ public SmartConfig toSmartConfig() {
// READ_TIMEOUT
smartConfig.setProperty(ClientConfig.PROPERTY_READ_TIMEOUT, readTimeout);

smartConfig.setMaxConnectionIdleTime(maxConnectionIdleTime);

return smartConfig;
}
Expand Down Expand Up @@ -455,6 +461,20 @@ public void setSessionToken(String sessionToken) {
this.sessionToken = sessionToken;
}

@ConfigUriProperty
public int getMaxConnectionIdleTime() {
return maxConnectionIdleTime;
}

/**
* Set the maximum amount of time (in milliseconds) to keep a connection alive and idle.
* This is a hint to the underlying connection pool, and is not guaranteed to be honored.
* A zero value indicates no limit to the life time.
*/
public void setMaxConnectionIdleTime(int maxConnectionIdleTime) {
this.maxConnectionIdleTime = maxConnectionIdleTime;
}

@ConfigUriProperty(converter = ConfigUri.StringPropertyConverter.class)
public Map<String, Object> getProperties() {
return properties;
Expand Down Expand Up @@ -564,6 +584,11 @@ public T withReadTimeout(int readTimeout) {
return (T) this;
}

public T withMaxConnectionIdleTime(int maxConnectionIdleTime) {
setMaxConnectionIdleTime(maxConnectionIdleTime);
return (T) this;
}

@SuppressWarnings("unchecked")
public T withProperty(String propName, Object value) {
setProperty(propName, value);
Expand Down