final String errorMessage = "Found multiple common-proxy-handler-configs, only one is allowed";
LOGGER.error(errorMessage);
for (File commonHandlerConfig : commonProxyHandlerConfigFiles) {
LOGGER.error(commonHandlerConfig.getAbsolutePath());
}
throw new PlatformException(errorMessage);
}
}
// locate and load the individual proxy handler bean XML files using the common proxy handler beans context as parent
File[] proxyHandlerBeansFiles = FileLocator.findFiles(ServiceProxyFrameworkConstants.SPRING_PROXY_HANDLER_CONFIG);
for (File proxyHandlerBeansFile : proxyHandlerBeansFiles) {
HandlerConfigInfo handlerConfigInfo = new HandlerConfigInfo(proxyHandlerBeansFile);
// load the proxy handler's appcontext
this.loadProxyHandlerContext(handlerConfigInfo);
LOGGER.info("Loaded: " + proxyHandlerBeansFile);
}
// add the proxy listener beans to the contexts list (these have the thrift handlers)
File[] proxyListenerBeanFiles = FileLocator.findFiles(ServiceProxyFrameworkConstants.SPRING_PROXY_LISTENER_CONFIG);
for (File proxyListenerBeanFile : proxyListenerBeanFiles) {
// locate and load the service proxy listener defined in the file identified by {@link ServiceProxyFrameworkConstants#SPRING_PROXY_LISTENER_CONFIG}
AbstractApplicationContext listenerContext = new FileSystemXmlApplicationContext(
new String[]{FILE_PREFIX + proxyListenerBeanFile.getAbsolutePath()},
ServiceProxyComponentContainer.getCommonProxyHandlerBeansContext()
);
this.handlerConfigInfoList.add(new HandlerConfigInfo(proxyListenerBeanFile, null, listenerContext));
LOGGER.info("Loaded: " + proxyListenerBeanFile);
}
// store reference to the TaskContext
this.taskContext = (TaskContext) ServiceProxyComponentContainer.getCommonProxyHandlerBeansContext().getBean(ServiceProxyComponentContainer.TASK_CONTEXT_BEAN);
// load all registries
for (HandlerConfigInfo handlerConfigInfo : handlerConfigInfoList) {
// handler registries
String[] registryBeans = handlerConfigInfo.getProxyHandlerContext().getBeanNamesForType(AbstractHandlerRegistry.class);
for (String registryBean : registryBeans) {
AbstractHandlerRegistry<T> registry = (AbstractHandlerRegistry<T>) handlerConfigInfo.getProxyHandlerContext().getBean(registryBean);
LOGGER.info("Found handler registry: " + registry.getClass().getName() + " in file : " + handlerConfigInfo.getXmlConfigFile().getAbsolutePath());
// ensure that the same registry is not added twice in any of the config files
if (this.configService.getDeployedRegistries().contains(registry)) {
LOGGER.error("Error initializing registry: " + registry.getClass().getName() + ". Duplicate reference in location : " + handlerConfigInfo.getXmlConfigFile().getAbsolutePath());
throw new PlatformException("Error initializing registry: " + registry.getClass().getName() + ". Duplicate reference in location : " + handlerConfigInfo.getXmlConfigFile().getAbsolutePath());
}
// init the Registry
try {
AbstractHandlerRegistry.InitedHandlerInfo<T>[] initedHandlerInfos = registry.init(this.handlerConfigInfoList, this.taskContext);
LOGGER.info("Initialized handler registry: " + registry.getClass().getName());
//Add the file path of each inited handler to SPConfigService (for configuration console)
for (AbstractHandlerRegistry.InitedHandlerInfo<T> initedHandlerInfo : initedHandlerInfos) {
if (initedHandlerInfo == null) {
System.out.println("Handler is nul!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! " + " Size is : " + initedHandlerInfos.length);
}
this.configService.addHandlerConfigPath(initedHandlerInfo.getHandlerConfigInfo().getXmlConfigFile(), initedHandlerInfo.getInitedHandler());
}
} catch (Exception e) {
LOGGER.error("Error initializing registry: " + registry.getClass().getName());
throw new PlatformException("Error initializing registry: " + registry.getClass().getName(), e);
}
// add registry to config
this.configService.addHandlerRegistry(registry);
// add registry to local list
this.registries.add(registry);
}
// add all network servers to config
String[] networkServerBeans = handlerConfigInfo.getProxyHandlerContext().getBeanNamesForType(AbstractNetworkServer.class);
for (String networkServerBean : networkServerBeans) {
AbstractNetworkServer networkServer = (AbstractNetworkServer) handlerConfigInfo.getProxyHandlerContext().getBean(networkServerBean);
// init the server
try {
networkServer.init();
} catch (Exception e) {
LOGGER.error("Error initializeing network server: " + networkServer.getServerType() + ": " + networkServer.getServerEndpoint());
throw new PlatformException("Error initializeing network server: " + networkServer.getServerType() + ": " + networkServer.getServerEndpoint(), e);
}
configService.addDeployedNetworkServer(networkServer);
}
}