Package com.flipkart.phantom.task.spi.registry

Examples of com.flipkart.phantom.task.spi.registry.HandlerConfigInfo


        if (!FileSystemResource.class.isAssignableFrom(resource.getClass()) ||
                !resource.getFilename().equalsIgnoreCase(ServiceProxyFrameworkConstants.SPRING_PROXY_HANDLER_CONFIG)) {
            throw new UnsupportedOperationException("Proxy handers can be loaded only from files by name : " +
                    ServiceProxyFrameworkConstants.SPRING_PROXY_HANDLER_CONFIG + ". Specified resource is : " + resource.toString());
        }
        loadProxyHandlerContext(new HandlerConfigInfo(((FileSystemResource) resource).getFile()));
    }
View Full Code Here


        }
        // we look up the unique instance of ServiceProxyFrameworkConstants.COMMON_PROXY_CONFIG. This call would throw an exception if multiple are found
        String commonProxyBeansFileName = FileLocator.findUniqueFile(ServiceProxyFrameworkConstants.COMMON_PROXY_CONFIG).getAbsolutePath();
        ServiceProxyComponentContainer.commonProxyHandlerBeansContext = new ClassPathXmlApplicationContext(new String[]{ServiceProxyFrameworkConstants.COMMON_PROXY_CONFIG}, defaultCtxFactory.getCommonBeansContext());
        // add the common proxy beans independently to the list of proxy handler contexts as common handlers are declared there
        this.handlerConfigInfoList.add(new HandlerConfigInfo(new File(commonProxyBeansFileName), null, ServiceProxyComponentContainer.commonProxyHandlerBeansContext));

        // Get the Config Service Bean
        this.configService = (SPConfigServiceImpl<T>) ServiceProxyComponentContainer.commonProxyHandlerBeansContext.getBean(ServiceProxyComponentContainer.CONFIG_SERVICE_BEAN);
        ((SPConfigServiceImpl<T>) this.configService).setComponentContainer(this);

        // Load additional if runtime nature is "server". This context is the new common beans context
        if (RuntimeVariables.getRuntimeNature().equalsIgnoreCase(RuntimeConstants.SERVER)) {
            // we look up the unique instance of ServiceProxyFrameworkConstants.COMMON_PROXY_SERVER_NATURE_CONFIG. This call would throw an exception if multiple are found
            String commonProxyServerNatureBeansFileName = FileLocator.findUniqueFile(ServiceProxyFrameworkConstants.COMMON_PROXY_SERVER_NATURE_CONFIG).getAbsolutePath();
            ServiceProxyComponentContainer.commonProxyHandlerBeansContext = new ClassPathXmlApplicationContext(
                    new String[]{ServiceProxyFrameworkConstants.COMMON_PROXY_SERVER_NATURE_CONFIG},
                    ServiceProxyComponentContainer.getCommonProxyHandlerBeansContext());
            // now add the common server nature proxy hander beans to the contexts list
            this.handlerConfigInfoList.add(new HandlerConfigInfo(new File(commonProxyServerNatureBeansFileName),
                 null,ServiceProxyComponentContainer.getCommonProxyHandlerBeansContext()));
        }

        // locate and load a single common proxy handler bean XML files which is initialized before all other individual handlers
        // in case multiple are found fail the bootstrap.
        File[] commonProxyHandlerConfigFiles = FileLocator.findFiles(ServiceProxyFrameworkConstants.COMMON_PROXY_HANDLER_CONFIG);
        if (commonProxyHandlerConfigFiles.length > 0) {
            if (commonProxyHandlerConfigFiles.length == 1) {
                File commonProxyHandlerConfigFile = commonProxyHandlerConfigFiles[0];
                // load the common proxy handler
                HandlerConfigInfo commonHandlersConfigInfo = new HandlerConfigInfo(commonProxyHandlerConfigFile);
                // set the load order to first order i.e. load before others
                commonHandlersConfigInfo.setLoadOrder(HandlerConfigInfo.FIRST_ORDER);
                this.loadProxyHandlerContext(commonHandlersConfigInfo);
                LOGGER.info("Loaded Common Proxy Handler Config: " + commonProxyHandlerConfigFile);
            } else {
                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());
View Full Code Here

TOP

Related Classes of com.flipkart.phantom.task.spi.registry.HandlerConfigInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.