forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 0
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 Azure#57 from WindowsAzure/dev
Dev
- Loading branch information
Showing
48 changed files
with
1,078 additions
and
1,509 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
99 changes: 99 additions & 0 deletions
99
...in/java/com/microsoft/windowsazure/services/core/utils/pipeline/ClientConfigSettings.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,99 @@ | ||
/** | ||
* Copyright 2012 Microsoft Corporation | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.microsoft.windowsazure.services.core.utils.pipeline; | ||
|
||
import com.sun.jersey.api.client.Client; | ||
import com.sun.jersey.api.client.config.ClientConfig; | ||
import com.sun.jersey.api.client.filter.LoggingFilter; | ||
|
||
/** | ||
* Class used for injecting timeout settings into the various places that need it. | ||
* | ||
*/ | ||
public class ClientConfigSettings { | ||
private static final int DEFAULT_TIMEOUT_MS = 90 * 1000; | ||
|
||
private final Integer connectTimeout; | ||
private final Integer readTimeout; | ||
private final boolean shouldLog; | ||
|
||
/** | ||
* Construct a {@link ClientConfigSettings} object with the default | ||
* settings. | ||
*/ | ||
public ClientConfigSettings() { | ||
connectTimeout = Integer.valueOf(null); | ||
readTimeout = Integer.valueOf(null); | ||
shouldLog = false; | ||
} | ||
|
||
/** | ||
* Construct a {@link ClientConfigSettings} object wit the given | ||
* settings. | ||
* | ||
* @param connectTimeout | ||
* Connection timeout in milliseconds | ||
* @param readTimeout | ||
* read timeout in milliseconds | ||
* @param shouldLog | ||
* if true, add logging filter to clients. | ||
*/ | ||
public ClientConfigSettings(Object connectTimeout, Object readTimeout, boolean shouldLog) { | ||
this.connectTimeout = getTimeout(connectTimeout); | ||
this.readTimeout = getTimeout(readTimeout); | ||
this.shouldLog = shouldLog; | ||
} | ||
|
||
/** | ||
* Update the given {@link ClientConfig} object with the appropriate | ||
* settings from configuration. | ||
* | ||
* @param clientConfig | ||
* object to update. | ||
*/ | ||
public void applyConfig(ClientConfig clientConfig) { | ||
clientConfig.getProperties().put(ClientConfig.PROPERTY_CONNECT_TIMEOUT, connectTimeout); | ||
clientConfig.getProperties().put(ClientConfig.PROPERTY_READ_TIMEOUT, readTimeout); | ||
} | ||
|
||
/** | ||
* Update the given {@link client} object with the appropriate settings | ||
* from configuration. | ||
* | ||
* @param client | ||
*/ | ||
public void applyConfig(Client client) { | ||
if (shouldLog) { | ||
client.addFilter(new LoggingFilter()); | ||
} | ||
} | ||
|
||
private Integer getTimeout(Object timeoutValue) { | ||
if (timeoutValue == null) { | ||
return new Integer(DEFAULT_TIMEOUT_MS); | ||
} | ||
|
||
if (timeoutValue instanceof Integer) { | ||
return (Integer) timeoutValue; | ||
} | ||
|
||
if (timeoutValue instanceof String) { | ||
return Integer.valueOf((String) timeoutValue); | ||
} | ||
|
||
throw new IllegalArgumentException("timeoutValue"); | ||
} | ||
} |
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
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
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
Oops, something went wrong.