package com.vci.server; import org.apache.commons.lang3.StringUtils; import com.vci.common.log.ServerWithLog4j; import com.vci.server.conf.IceServerProperties; import com.vci.server.conf.ServiceConf; import com.vci.server.conf.ServiceTempl; import com.vci.server.mw.ServerContextInterceptor; import com.zeroc.Ice.Communicator; import com.zeroc.Ice.InitializationData; import com.zeroc.Ice.ObjectAdapter; import com.zeroc.Ice.Util; public class ServiceManagerMain { private static final String locatorKey = "--Ice.Default.Locator"; public static void main(String[] args) { System.out.println(""); System.out.println("\t***************************************************************"); System.out.println("\t* VCI-Platform V2024 www.vci-tech.com *"); System.out.println("\t* (C)Beijing Hongbo Yuanda Sciense and Technology Co. , Ltd. *"); System.out.println("\t***************************************************************"); System.out.println(""); ServiceConf conf = ServiceConf.ReadConf(); if (conf == null) { System.out.println("读取服务配置文件【service.xml】失败,请确认配置是否正确!"); return; } // 设置APP_HOME系统属性 String appHome = System.getProperty("user.dir"); ServiceTempl[] templs = conf.getServiceTempls(); int nCount = templs.length; ServerWithLog4j.logger.info("共配置了" + "【" + nCount + "】个服务"); InitializationData initData = new InitializationData(); initData.properties = Util.createProperties(args); String value = IceServerProperties.getStringProperty("Ice.MessageSizeMax"); if (!StringUtils.isBlank(value)) initData.properties.setProperty("Ice.MessageSizeMax", value); value = IceServerProperties.Endpoints(); initData.properties.setProperty(locatorKey, value); try(Communicator communicator = Util.initialize(initData)) { // Shut down the communicator on Ctrl+C Runtime.getRuntime().addShutdownHook(new Thread(() -> communicator.shutdown())); ObjectAdapter adapter = communicator.createObjectAdapterWithEndpoints(IceServerProperties.Adapter(), IceServerProperties.Endpoints()); //ObjectAdapter adapter = communicator.createObjectAdapter(IceProperties.Endpoints()); for (ServiceTempl templ : templs) { String entry = templ.getEntry(); ServerWithLog4j.logger.debug(entry); Class cl = Class.forName(entry); com.zeroc.Ice.Object ob = (com.zeroc.Ice.Object) ( cl.newInstance()); BaseService service = (BaseService)ob; String name = cl.getTypeName(); if (service != null) { name = service.getServiceName(); } adapter.add(new ServerContextInterceptor(ob), Util.stringToIdentity(name)); //adapter.add(ob, Util.stringToIdentity(bs.getServiceName())); ServerWithLog4j.logger.info(name + " started"); } adapter.activate(); ServerWithLog4j.logger.info("Service Started!"); communicator.waitForShutdown(); } catch (Exception e) { e.printStackTrace(); } } }