KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > components > net > DefaultCommonsHTTPClientProperties


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.axis.components.net;
17
18 import org.apache.axis.AxisProperties;
19
20 /**
21  * Default property set for the of the multi threaded connection pool
22  * used in the CommonsHTTPSender transport implementation. Values
23  * returned by this implementation are identical to the defaults for
24  * the Commons HTTPClient library itself, unless overridden with
25  * Axis properties.
26  *
27  * @author Eric Friedman
28  */

29 public class DefaultCommonsHTTPClientProperties implements CommonsHTTPClientProperties {
30
31     /** the key for the Axis Property that controls the maximum total connections
32         allowed in the httpclient pool */

33     public static final String JavaDoc MAXIMUM_TOTAL_CONNECTIONS_PROPERTY_KEY =
34         "axis.http.client.maximum.total.connections";
35
36     /** the key for the Axis Property that controls the maximum connections
37         per host allowed by the httpclient pool */

38     public static final String JavaDoc MAXIMUM_CONNECTIONS_PER_HOST_PROPERTY_KEY =
39         "axis.http.client.maximum.connections.per.host";
40
41     /** the key for the Axis Property that sets the connection pool timeout
42         for the httpclient pool */

43     public static final String JavaDoc CONNECTION_POOL_TIMEOUT_KEY =
44         "axis.http.client.connection.pool.timeout";
45
46     /** the key for the Axis Property that sets the default connection timeout
47         for the httpclient, can be overriden by the MessageContext */

48     public static final String JavaDoc CONNECTION_DEFAULT_CONNECTION_TIMEOUT_KEY =
49         "axis.http.client.connection.default.connection.timeout";
50
51     /** the key for the Axis Property that sets the read timeout
52         for the httpclient */

53     public static final String JavaDoc CONNECTION_DEFAULT_SO_TIMEOUT_KEY =
54         "axis.http.client.connection.default.so.timeout";
55
56     /**
57      * Convert the value for <tt>property</tt> into an int or, if none is found,
58      * use the <tt>dephault</tt> value instead.
59      *
60      * @return an integer value
61      */

62     protected final int getIntegerProperty(String JavaDoc property, String JavaDoc dephault) {
63         return Integer.parseInt(AxisProperties.getProperty(property, dephault));
64     }
65
66     /**
67      * Return the integer value associated with the property
68      * axis.http.client.maximum.total.connections or a default of 20.
69      *
70      * @return a whole integer
71      */

72     public int getMaximumTotalConnections() {
73         int i = getIntegerProperty(MAXIMUM_TOTAL_CONNECTIONS_PROPERTY_KEY, "20");
74         if (i < 1) {
75             throw new IllegalStateException JavaDoc(MAXIMUM_TOTAL_CONNECTIONS_PROPERTY_KEY + " must be > 1");
76         }
77         return i;
78     }
79
80     /**
81      * Return the integer value associated with the property
82      * axis.http.client.maximum.connections.per.host or a default of 2.
83      *
84      * @return a whole integer
85      */

86     public int getMaximumConnectionsPerHost() {
87         int i = getIntegerProperty(MAXIMUM_CONNECTIONS_PER_HOST_PROPERTY_KEY, "2");
88         if (i < 1) {
89             throw new IllegalStateException JavaDoc(MAXIMUM_CONNECTIONS_PER_HOST_PROPERTY_KEY + " must be > 1");
90         }
91         return i;
92     }
93
94     /**
95      * Return the integer value associated with the property
96      * axis.http.client.connection.pool.timeout or a default of 0.
97      *
98      * @return an integer >= 0
99      */

100     public int getConnectionPoolTimeout() {
101         int i = getIntegerProperty(CONNECTION_POOL_TIMEOUT_KEY, "0");
102         if (i < 0) {
103             throw new IllegalStateException JavaDoc(CONNECTION_POOL_TIMEOUT_KEY + " must be >= 0");
104         }
105         return i;
106     }
107
108     /**
109      * Return the integer value associated with the property
110      * axis.http.client.connection.default.connection.timeout or a default of 0.
111      *
112      * @return an integer >= 0
113      */

114     public int getDefaultConnectionTimeout() {
115         int i = getIntegerProperty(CONNECTION_DEFAULT_CONNECTION_TIMEOUT_KEY, "0");
116         if (i < 0) {
117             throw new IllegalStateException JavaDoc(CONNECTION_DEFAULT_CONNECTION_TIMEOUT_KEY + " must be >= 0");
118         }
119         return i;
120     }
121
122     /**
123      * Return the integer value associated with the property
124      * axis.http.client.connection.default.so.timeout or a default of 0.
125      *
126      * @return an integer >= 0
127      */

128     public int getDefaultSoTimeout() {
129         int i = getIntegerProperty(CONNECTION_DEFAULT_SO_TIMEOUT_KEY, "0");
130         if (i < 0) {
131             throw new IllegalStateException JavaDoc(CONNECTION_DEFAULT_SO_TIMEOUT_KEY + " must be >= 0");
132         }
133         return i;
134     }
135 }
136
Popular Tags