forked from zeroc-ice/ice-demos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Server.java
61 lines (53 loc) · 1.75 KB
/
Server.java
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
//
// Copyright (c) ZeroC, Inc. All rights reserved.
//
public class Server
{
static class ShutdownHook extends Thread
{
@Override
public void
run()
{
_communicator.destroy();
}
ShutdownHook(Ice.Communicator communicator)
{
_communicator = communicator;
}
private final Ice.Communicator _communicator;
}
public static void
main(String[] args)
{
int status = 0;
Ice.StringSeqHolder argsHolder = new Ice.StringSeqHolder(args);
//
// Try with resources block - communicator is automatically destroyed
// at the end of this try block
//
try(Ice.Communicator communicator = Ice.Util.initialize(argsHolder))
{
//
// Install shutdown hook to (also) destroy communicator during JVM shutdown.
// This ensures the communicator gets destroyed when the user interrupts the application with Ctrl-C.
//
Runtime.getRuntime().addShutdownHook(new ShutdownHook(communicator));
if(argsHolder.value.length > 0)
{
System.err.println("too many arguments");
status = 1;
}
else
{
Ice.ObjectAdapter adapter = communicator.createObjectAdapter("Hello");
Ice.Properties properties = communicator.getProperties();
Ice.Identity id = Ice.Util.stringToIdentity(properties.getProperty("Identity"));
adapter.add(new HelloI(properties.getProperty("Ice.ProgramName")), id);
adapter.activate();
communicator.waitForShutdown();
}
}
System.exit(status);
}
}