- /**
- * 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 Exception
- */
- public<RET> RET same(SecuritySetter<HttpURLConnection> ss, Retryable<RET> retryable) throws APIException, CadiException, LocatorException {
- RET ret = null;
- boolean retry = true;
- Rcli<HttpURLConnection> client = retryable.lastClient();
- try {
- do {
- Item item;
- // if no previous state, get the best
- if(retryable.item()==null) {
- item = loc.best();
- if(item==null) {
- throw new LocatorException("No Services Found for " + loc);
- }
- retryable.item(item);
- retryable.lastClient = null;
- }
- if(client==null) {
- item = retryable.item();
- URI uri=loc.get(item);
- if(uri==null) {
- loc.invalidate(retryable.item());
- if(loc.hasItems()) {
- retryable.item(loc.next(retryable.item()));
- continue;
- } else {
- throw new LocatorException("No clients available for " + loc.toString());
- }
- }
- client = new HRcli(this, uri,item,ss)
- .connectionTimeout(connectionTimeout)
- .readTimeout(readTimeout)
- .apiVersion(apiVersion);
- } else {
- client.setSecuritySetter(ss);
- }
-
- retry = false;
- try {
- ret = retryable.code(client);
- } catch (APIException | CadiException e) {
- item = retryable.item();
- loc.invalidate(item);
- retryable.item(loc.next(item));
- try {
- Throwable ec = e.getCause();
- if(ec instanceof java.net.ConnectException) {
- 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()) {
- access.log(Level.WARN,"Socket prematurely closed, trying next available service");
- retry = true;
- } else {
- throw new CadiException("Socket prematurely closed, no more services to try");
- }
- } else if(ec instanceof SocketException) {
- if("java.net.SocketException: Connection reset".equals(ec.getMessage())) {
- access.log(Level.ERROR, ec.getMessage(), " can mean Certificate Expiration or TLS Protocol issues");
- }
- retryable.item(null);
- throw e;
- } else {
- retryable.item(null);
- throw e;
- }
- } finally {
- client = null;
- }
- } catch (ConnectException e) {
- item = retryable.item();
- loc.invalidate(item);
- retryable.item(loc.next(item));
- }
- } while(retry);
- } finally {
- retryable.lastClient = client;
- }
- 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) throws LocatorException, CadiException, APIException {
- return oneOf(ss,retryable,true,null);
- }
+ /**
+ * 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 Exception
+ */
+ public<RET> RET same(SecuritySetter<HttpURLConnection> ss, Retryable<RET> retryable) throws APIException, CadiException, LocatorException {
+ RET ret = null;
+ boolean retry = true;
+ Rcli<HttpURLConnection> client = retryable.lastClient();
+ try {
+ do {
+ Item item;
+ // if no previous state, get the best
+ if (retryable.item()==null) {
+ item = loc.best();
+ if (item==null) {
+ throw new LocatorException("No Services Found for " + loc);
+ }
+ retryable.item(item);
+ retryable.lastClient = null;
+ }
+ if (client==null) {
+ item = retryable.item();
+ URI uri=loc.get(item);
+ if (uri==null) {
+ loc.invalidate(retryable.item());
+ if (loc.hasItems()) {
+ retryable.item(loc.next(retryable.item()));
+ continue;
+ } else {
+ throw new LocatorException("No clients available for " + loc.toString());
+ }
+ }
+ client = new HRcli(this, uri,item,ss)
+ .connectionTimeout(connectionTimeout)
+ .readTimeout(readTimeout)
+ .apiVersion(apiVersion);
+ } else {
+ client.setSecuritySetter(ss);
+ }
+
+ retry = false;
+ try {
+ ret = retryable.code(client);
+ } catch (APIException | CadiException e) {
+ item = retryable.item();
+ loc.invalidate(item);
+ retryable.item(loc.next(item));
+ try {
+ Throwable ec = e.getCause();
+ if (ec instanceof java.net.ConnectException) {
+ 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()) {
+ access.log(Level.WARN,"Socket prematurely closed, trying next available service");
+ retry = true;
+ } else {
+ throw new CadiException("Socket prematurely closed, no more services to try");
+ }
+ } else if (ec instanceof SocketException) {
+ if ("java.net.SocketException: Connection reset".equals(ec.getMessage())) {
+ access.log(Level.ERROR, ec.getMessage(), " can mean Certificate Expiration or TLS Protocol issues");
+ }
+ retryable.item(null);
+ throw e;
+ } else {
+ retryable.item(null);
+ throw e;
+ }
+ } finally {
+ client = null;
+ }
+ } catch (ConnectException e) {
+ item = retryable.item();
+ loc.invalidate(item);
+ retryable.item(loc.next(item));
+ }
+ } while (retry);
+ } finally {
+ retryable.lastClient = client;
+ }
+ 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) throws LocatorException, CadiException, APIException {
+ return oneOf(ss,retryable,true,null);
+ }