diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DataStoreServer.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DataStoreServer.java index 46e3bbe87da6153e558eef17d61bc2bd64ffc862..1d24af3cac8b6d5e5e48dd4a52e03ee8e21dda61 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DataStoreServer.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/DataStoreServer.java @@ -56,10 +56,14 @@ import org.springframework.web.context.WebApplicationContext; import com.googlecode.jsonrpc4j.spring.JsonServiceExporter; import com.marathon.util.spring.StreamSupportingHttpInvokerServiceExporter; +import ch.systemsx.cisd.base.exceptions.CheckedExceptionTunnel; import ch.systemsx.cisd.common.api.IRpcServiceNameServer; import ch.systemsx.cisd.common.api.RpcServiceInterfaceVersionDTO; +import ch.systemsx.cisd.common.api.retry.RetryCaller; +import ch.systemsx.cisd.common.api.retry.config.RetryConfiguration; import ch.systemsx.cisd.common.exceptions.ConfigurationFailureException; import ch.systemsx.cisd.common.exceptions.EnvironmentFailureException; +import ch.systemsx.cisd.common.logging.Log4jSimpleLogger; import ch.systemsx.cisd.common.logging.LogCategory; import ch.systemsx.cisd.common.logging.LogFactory; import ch.systemsx.cisd.common.logging.LogInitializer; @@ -171,6 +175,7 @@ public class DataStoreServer } catch (final Exception ex) { operationLog.error("Failed to start server.", ex); + throw CheckedExceptionTunnel.wrapIfNecessary(ex); } } @@ -426,23 +431,60 @@ public class DataStoreServer return configParams.isUseNIO() ? new SelectChannelConnector() : new SocketConnector(); } } - - private final static void selfTest(final ApplicationContext applicationContext) + + private static class RetryingSelfTest extends RetryCaller<Void, RuntimeException> { - IEncapsulatedOpenBISService dataSetService = applicationContext.getDataSetService(); - final int version = dataSetService.getVersion(); - if (IServer.VERSION != version) + private final ApplicationContext applicationContext; + + RetryingSelfTest(ApplicationContext applicationContext) { - throw new ConfigurationFailureException( - "This client has the wrong service version for the server (client: " - + IServer.VERSION + ", server: " + version + ")."); + super(new RetryConfiguration() + { + @Override + public float getWaitingTimeBetweenRetriesIncreasingFactor() + { + return 2; + } + + @Override + public int getWaitingTimeBetweenRetries() + { + return 5000; + } + + @Override + public int getMaximumNumberOfRetries() + { + return 5; + } + }, new Log4jSimpleLogger(operationLog)); + this.applicationContext = applicationContext; } - if (operationLog.isInfoEnabled()) + + @Override + protected Void call() throws RuntimeException { - operationLog.info("openBIS service (interface version " + version + ") is reachable"); + IEncapsulatedOpenBISService dataSetService = applicationContext.getDataSetService(); + final int version = dataSetService.getVersion(); + if (IServer.VERSION != version) + { + throw new ConfigurationFailureException( + "This client has the wrong service version for the server (client: " + + IServer.VERSION + ", server: " + version + ")."); + } + if (operationLog.isInfoEnabled()) + { + operationLog.info("openBIS service (interface version " + version + ") is reachable"); + } + return null; } } + private final static void selfTest(final ApplicationContext applicationContext) + { + new RetryingSelfTest(applicationContext).callWithRetry(); + } + public static ConfigParameters getConfigParameters() { if (configParameters == null) diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/EncapsulatedOpenBISService.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/EncapsulatedOpenBISService.java index 3a64aac5aacdeedba982d804891f7142631cbeb8..a1fc378dcf25b6f7ebf22bf998aa078a31e6da16 100644 --- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/EncapsulatedOpenBISService.java +++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/generic/server/EncapsulatedOpenBISService.java @@ -25,7 +25,10 @@ import org.apache.commons.lang.time.DateUtils; import org.apache.log4j.Logger; import org.springframework.beans.factory.FactoryBean; +import ch.systemsx.cisd.common.api.retry.RetryCaller; +import ch.systemsx.cisd.common.api.retry.config.RetryConfiguration; import ch.systemsx.cisd.common.exceptions.UserFailureException; +import ch.systemsx.cisd.common.logging.Log4jSimpleLogger; import ch.systemsx.cisd.common.logging.LogCategory; import ch.systemsx.cisd.common.logging.LogFactory; import ch.systemsx.cisd.openbis.common.api.client.ServiceFinder; @@ -114,15 +117,55 @@ public final class EncapsulatedOpenBISService implements IEncapsulatedOpenBISSer private IServiceConversationClientManagerLocal conversationClient; - public static IServiceForDataStoreServer createOpenBisService(String openBISURL, String timeout) + private static class RetryingOpenBisCreator extends + RetryCaller<IServiceForDataStoreServer, RuntimeException> { - OpenBisServiceFactory factory = - new OpenBisServiceFactory(openBISURL, ResourceNames.ETL_SERVICE_URL); - if (timeout.startsWith("$")) + private final String openBISURL; + + private String timeout; + + RetryingOpenBisCreator(String openBISURL, String timeout) { - return factory.createService(); + super(new RetryConfiguration() + { + @Override + public float getWaitingTimeBetweenRetriesIncreasingFactor() + { + return 2; + } + + @Override + public int getWaitingTimeBetweenRetries() + { + return 5000; + } + + @Override + public int getMaximumNumberOfRetries() + { + return 5; + } + }, new Log4jSimpleLogger(operationLog)); + this.openBISURL = openBISURL; + this.timeout = timeout; } - return factory.createService(normalizeTimeout(timeout)); + + @Override + protected IServiceForDataStoreServer call() throws RuntimeException + { + OpenBisServiceFactory factory = + new OpenBisServiceFactory(openBISURL, ResourceNames.ETL_SERVICE_URL); + if (timeout.startsWith("$")) + { + return factory.createService(); + } + return factory.createService(normalizeTimeout(timeout)); + } + } + + public static IServiceForDataStoreServer createOpenBisService(String openBISURL, String timeout) + { + return new RetryingOpenBisCreator(openBISURL, timeout).callWithRetry(); } /**