田源
2025-01-16 404966637eda6881a0f17683c5aacc7c1c34aed8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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();
        }
 
    }
}