* @throws Exception
* the exception
*/
public static void load(ServiceListConfiguration serviceListConfiguration) throws Exception {
Map<String, ServiceConfiguration> serviceConfigurationMap = serviceListConfiguration.getServiceConfigurations();
ServiceRegistry serviceRegistry = AppContext.getServiceRegistry();
for (ServiceConfiguration serviceConfiguration : serviceConfigurationMap.values()) {
String serviceTypeString = serviceConfiguration.getType();
ServiceType serviceType = ServiceType.getType(serviceTypeString);
RemoteNodeConfiguration remoteNode = serviceConfiguration.getRemoteNodeConfiguration();
String remotNodeName = null;
if (remoteNode != null) {
remotNodeName = remoteNode.getName();
serviceType = ServiceConfiguration.adaptServiceTypeIfCascService(serviceType, remotNodeName);
}
String serviceName = serviceConfiguration.getName();
// instantiate right type of service
Service service = null;
switch (serviceType) {
case CASCADED_SESSION_SERVICE:
Server server = AppContext.getServerRegistry().getServer(remotNodeName);
if (server == null) {
throw new SCMPValidatorException(SCMPError.V_WRONG_CONFIGURATION_FILE, " host=" + remotNodeName
+ " configured for service=" + serviceName + " is not configured");
}
service = new CascadedSessionService(serviceName, (CascadedSC) server);
break;
case CASCADED_PUBLISH_SERVICE:
server = AppContext.getServerRegistry().getServer(remotNodeName);
if (server == null) {
throw new SCMPValidatorException(SCMPError.V_WRONG_CONFIGURATION_FILE, " host=" + remotNodeName
+ " configured for service=" + serviceName + " is not configured");
}
service = new CascadedPublishService(serviceName, (CascadedSC) server,
serviceConfiguration.getNoDataIntervalSeconds());
break;
case CASCADED_CACHE_GUARDIAN:
server = AppContext.getServerRegistry().getServer(remotNodeName);
if (server == null) {
throw new SCMPValidatorException(SCMPError.V_WRONG_CONFIGURATION_FILE, " host=" + remotNodeName
+ " configured for cache guardian =" + serviceName + " is not configured");
}
service = new CascadedCacheGuardian(serviceName, (CascadedSC) server,
serviceConfiguration.getNoDataIntervalSeconds());
break;
case CASCADED_FILE_SERVICE:
server = AppContext.getServerRegistry().getServer(remotNodeName);
if (server == null) {
throw new SCMPValidatorException(SCMPError.V_WRONG_CONFIGURATION_FILE, " host=" + remotNodeName
+ " configured for service=" + serviceName + " is not configured");
}
service = new CascadedFileService(serviceName, (CascadedSC) server);
break;
case SESSION_SERVICE:
service = new SessionService(serviceName);
break;
case PUBLISH_SERVICE:
service = new PublishService(serviceName);
break;
case CACHE_GUARDIAN:
service = new CacheGuardian(serviceName);
break;
case FILE_SERVICE:
server = AppContext.getServerRegistry().getServer(remotNodeName);
if (server == null) {
throw new SCMPValidatorException(SCMPError.V_WRONG_CONFIGURATION_FILE, " host=" + remotNodeName
+ " configured for service=" + serviceName + " is not configured");
}
service = new FileService(serviceName, (FileServer) server, serviceConfiguration.getPath(),
serviceConfiguration.getUploadScript(), serviceConfiguration.getListScript());
break;
case UNDEFINED:
default:
throw new SCMPValidatorException(SCMPError.V_WRONG_CONFIGURATION_FILE,
"wrong serviceType, serviceName/serviceType=" + serviceName + Constants.SLASH + serviceTypeString);
}
service.setEnabled(serviceConfiguration.getEnabled());
serviceRegistry.addService(service.getName(), service);
}
}