ludc
2025-01-16 391eec3114a17e68652434c6eae610799d80290e
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
package com.vci.server;
 
import com.vci.server.base.log.PltLogger;
import com.zeroc.Ice.Communicator;
import com.zeroc.Ice.InitializationData;
import com.zeroc.Ice.Util;
import com.zeroc.IceBox.ServiceManagerI;
 
public class PltIceBoxServer {
    static class ShutdownHook extends Thread
    {
        private com.zeroc.Ice.Communicator _communicator;
        private final java.lang.Object _doneMutex = new java.lang.Object();
        private boolean _done = false;
 
        ShutdownHook(com.zeroc.Ice.Communicator communicator)
        {
            _communicator = communicator;
        }
 
        @Override
        public void run()
        {
            _communicator.shutdown();
 
            synchronized(_doneMutex)
            {
                //
                // Wait on the server to finish shutting down before exiting the ShutdownHook. This ensures
                // that all IceBox services have had a chance to shutdown cleanly before the JVM terminates.
                //
                while(!_done)
                {
                    try
                    {
                        _doneMutex.wait();
                    }
                    catch(InterruptedException ex)
                    {
                        break;
                    }
                }
            }
        }
 
        public void done()
        {
            synchronized(_doneMutex)
            {
                _done = true;
                _doneMutex.notify();
            }
        }
    }
 
    private static void usage()
    {
        System.err.println("Usage: com.zeroc.IceBox.Server [options] --Ice.Config=<file>\n");
        System.err.println(
                "Options:\n" +
                        "-h, --help           Show this message.\n" +
                        "-v, --version        Display the Ice version."
        );
    }
 
    public static void main(String[] args) {
//        InitializationData initData = new InitializationData();
//        initData.properties = Util.createProperties();
//        initData.properties.setProperty("Ice.Admin.DelayCreation", "1");
//        initData.logger = new Sl4jLogerI("system");
 
//        Server server = new Server();
//        System.exit(server.main("IceBox.Server", args, initData));
 
        int status = 0;
        java.util.List<String> argSeq = new java.util.ArrayList<String>();
 
        InitializationData initData = new InitializationData();
        initData.properties = Util.createProperties();
        initData.properties.setProperty("Ice.Admin.DelayCreation", "1");
        initData.logger = new PltLogger("system");
        ShutdownHook shutdownHook = null;
 
        try(Communicator communicator = Util.initialize(args, initData, argSeq))
        {
            shutdownHook = new ShutdownHook(communicator);
            Runtime.getRuntime().addShutdownHook(shutdownHook);
 
            status = run(communicator, argSeq);
        }
        finally
        {
            if(shutdownHook != null)
            {
                shutdownHook.done();
            }
        }
 
        System.exit(status);
 
    }
 
    private static int run(Communicator communicator, java.util.List<String> argSeq)
    {
        final String prefix = "IceBox.Service.";
        com.zeroc.Ice.Properties properties = communicator.getProperties();
        java.util.Map<String, String> services = properties.getPropertiesForPrefix(prefix);
 
        java.util.List<String> iceBoxArgs = new java.util.ArrayList<String>(argSeq);
 
        for(String key : services.keySet())
        {
            String name = key.substring(prefix.length());
            iceBoxArgs.removeIf(v -> v.startsWith("--" + name));
        }
 
        for(String arg : iceBoxArgs)
        {
            if(arg.equals("-h") || arg.equals("--help"))
            {
                usage();
                return 0;
            }
            else if(arg.equals("-v") || arg.equals("--version"))
            {
                System.out.println(com.zeroc.Ice.Util.stringVersion());
                return 0;
            }
            else
            {
                System.err.println("IceBox.Server: unknown option `" + arg + "'");
                usage();
                return 1;
            }
        }
 
        ServiceManagerI serviceManagerImpl = new ServiceManagerI(communicator, argSeq.toArray(new String[0]));
        return serviceManagerImpl.run();
    }
}