|
84 | 84 | ;; need the fully qualified class name because this fn is later used in a |
85 | 85 | ;; macro from a different ns |
86 | 86 | (defn ^org.apache.http.impl.conn.PoolingClientConnectionManager |
87 | | - make-reusable-conn-manager |
| 87 | + make-reusable-conn-manager* |
88 | 88 | "Given an timeout and optional insecure? flag, create a |
89 | | - PoolingClientConnectionManager with <timeout> seconds set as the timeout value." |
| 89 | + PoolingClientConnectionManager with <timeout> seconds set as the |
| 90 | + timeout value." |
90 | 91 | [{:keys [timeout insecure? keystore trust-store] :as config}] |
91 | 92 | (let [registry (cond |
92 | 93 | insecure? insecure-scheme-registry |
|
95 | 96 | (get-keystore-scheme-registry config) |
96 | 97 |
|
97 | 98 | :else regular-scheme-registry)] |
98 | | - (PoolingClientConnectionManager. |
| 99 | + (PoolingClientConnectionManager. |
99 | 100 | registry timeout java.util.concurrent.TimeUnit/SECONDS))) |
100 | 101 |
|
101 | | -;; needed to import/define this here since it being called outside the client ns |
102 | 102 | (def dmcpr ConnPerRouteBean/DEFAULT_MAX_CONNECTIONS_PER_ROUTE) |
103 | 103 |
|
104 | | -(defn make-manager |
105 | | - "returns reusable PoolingClientConnectionManager" |
106 | | - [opts] |
107 | | - (let [timeout# (or (:timeout opts) 5) |
108 | | - threads# (or (:threads opts) 4) |
109 | | - default-per-route# (or (:default-per-route opts) dmcpr) |
110 | | - insecure?# (:insecure? opts) |
111 | | - leftovers# (dissoc opts :timeout :threads :insecure?)] |
112 | | - (doto (make-reusable-conn-manager |
113 | | - (merge {:timeout timeout# |
114 | | - :insecure? insecure?#} |
115 | | - leftovers#)) |
116 | | - (.setMaxTotal threads#) |
117 | | - (.setDefaultMaxPerRoute default-per-route#)))) |
| 104 | +(defn make-reusable-conn-manager |
| 105 | + "Creates a default pooling connection manager with the specified options. |
| 106 | +
|
| 107 | + The following options are supported: |
118 | 108 |
|
| 109 | + :timeout - Time that connections are left open before automatically closing |
| 110 | + default: 5 |
| 111 | + :threads - Maximum number of threads that will be used for connecting |
| 112 | + default: 4 |
| 113 | + :default-per-route - Maximum number of simultaneous connections per host |
| 114 | + default: 2 |
| 115 | + :insecure? - Boolean flag to specify allowing insecure HTTPS connections |
| 116 | + default: false |
119 | 117 |
|
| 118 | + :keystore - keystore file to be used for connection manager |
| 119 | + :keystore-pass - keystore password |
| 120 | + :trust-store - trust store file to be used for connection manager |
| 121 | + :trust-store-pass - trust store password |
120 | 122 |
|
121 | | -(defn shutdown-manager |
| 123 | + Note that :insecure? and :keystore/:trust-store options are mutually exclusive |
| 124 | +
|
| 125 | + If the value 'nil' is specified or the value is not set, the default value |
| 126 | + will be used." |
| 127 | + [opts] |
| 128 | + (let [timeout (or (:timeout opts) 5) |
| 129 | + threads (or (:threads opts) 4) |
| 130 | + default-per-route (or (:default-per-route opts) dmcpr) |
| 131 | + insecure? (:insecure? opts) |
| 132 | + leftovers (dissoc opts :timeout :threads :insecure?)] |
| 133 | + (doto (make-reusable-conn-manager* (merge {:timeout timeout |
| 134 | + :insecure? insecure?} |
| 135 | + leftovers)) |
| 136 | + (.setMaxTotal threads) |
| 137 | + (.setDefaultMaxPerRoute default-per-route)))) |
| 138 | + |
| 139 | +(defn shutdown-manager |
122 | 140 | "Define function to shutdown manager" |
123 | 141 | [manager] |
124 | | - (doto manager (.shutdown))) |
| 142 | + (and manager (.shutdown manager))) |
125 | 143 |
|
126 | | -;; connection manager to be rebound during request execution |
127 | | -(def ^{:dynamic true} *connection-manager* nil) |
| 144 | +(def ^{:dynamic true |
| 145 | + :doc "connection manager to be rebound during request execution"} |
| 146 | + *connection-manager* nil) |
0 commit comments