* 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.
private int readTimeout, connectionTimeout;
public final Locator<URI> loc;
private Access access;
-
+
public HMangr(Access access, Locator<URI> loc) throws LocatorException {
readTimeout = 10000;
connectionTimeout=3000;
}
/**
- * Reuse the same service. This is helpful for multiple calls that change service side cached data so that
+ * Reuse the same service. This is helpful for multiple calls that change service side cached data so that
* there is not a speed issue.
- *
+ *
* If the service goes down, another service will be substituted, if available.
- *
+ *
* @param access
* @param loc
* @param ss
* @param item
* @param retryable
* @return
- * @throws URISyntaxException
+ * @throws URISyntaxException
* @throws Exception
*/
public<RET> RET same(SecuritySetter<HttpURLConnection> ss, Retryable<RET> retryable) throws APIException, CadiException, LocatorException {
} else {
client.setSecuritySetter(ss);
}
-
+
retry = false;
try {
ret = retryable.code(client);
try {
Throwable ec = e.getCause();
if (ec instanceof java.net.ConnectException) {
- if (client!=null && loc.hasItems()) {
+ if (client!=null && loc.hasItems()) {
access.log(Level.WARN,"Connection refused, trying next available service");
retry = true;
} else {
throw new CadiException("Connection refused, no more services to try");
}
} else if (ec instanceof java.net.SocketException) {
- if (client!=null && loc.hasItems()) {
+ if (client!=null && loc.hasItems()) {
access.log(Level.WARN,"Socket prematurely closed, trying next available service");
retry = true;
} else {
}
return ret;
}
-
-
+
+
public<RET> RET best(SecuritySetter<HttpURLConnection> ss, Retryable<RET> retryable) throws LocatorException, CadiException, APIException {
retryable.item(loc.best());
return same(ss,retryable);
public<RET> RET all(SecuritySetter<HttpURLConnection> ss, Retryable<RET> retryable,boolean notify) throws LocatorException, CadiException, APIException {
return call(ss,retryable,notify,null);
}
-
+
public <RET> RET allExcept(SecuritySetter<HttpURLConnection> ss, Retryable<RET> retryable,boolean notify, String selfHost) throws LocatorException, CadiException, APIException {
return call(ss,retryable,notify,selfHost);
}
access.log(Level.ERROR,"Connection to",uri,"refused during call to all services");
}
}
-
- if (ret == null && notify)
+
+ if (ret == null && notify)
throw new LocatorException("No available clients to call");
return ret;
}
-
+
public void close() {
// TODO Anything here?
public int readTimeout() {
return readTimeout;
}
-
+
public void connectionTimeout(int t) {
connectionTimeout = t;
}