+ @SuppressWarnings(value = { "unchecked" })
+ public <T> T callServiceSafe(String path, Map<String, String> parameters,
+ long timeout) {
+ long begin = System.currentTimeMillis();
+ try {
+ Object obj = null;
+ long duration = System.currentTimeMillis() - begin;
+ while (duration < timeout) {
+ try {
+ obj = callServiceLowLevel(path, parameters);
+ } catch (IOException e) {
+ if (log.isTraceEnabled())
+ log.trace("Exception when calling service " + path
+ + " on " + baseUrl, e);
+ }
+
+ if (obj != null)
+ break;
+
+ // wait a bit
+ try {
+ Thread.sleep(retryPeriod);
+ } catch (InterruptedException e) {
+ // silent
+ }
+ }
+
+ if (obj == null)
+ throw new SlcException(
+ "Service "
+ + path
+ + " on "
+ + baseUrl
+ + " did not return an answer after calling it safely for "
+ + duration + " ms.");
+ return (T) obj;
+ } catch (Exception e) {
+ throw new SlcException(
+ "Unexpected exception when safely calling service " + path
+ + " on " + baseUrl, e);
+ }
+ }
+
+ protected Object callServiceLowLevel(String path,
+ Map<String, String> parameters) throws IOException {
+ Assert.notNull(baseUrl, "base url");