|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| package org.apache.hivemind.management.mbeans; |
|
16 |
| |
|
17 |
| import java.rmi.NoSuchObjectException; |
|
18 |
| import java.rmi.Remote; |
|
19 |
| import java.rmi.RemoteException; |
|
20 |
| import java.rmi.registry.LocateRegistry; |
|
21 |
| import java.rmi.registry.Registry; |
|
22 |
| import java.rmi.server.UnicastRemoteObject; |
|
23 |
| |
|
24 |
| import javax.management.MBeanRegistration; |
|
25 |
| import javax.management.MBeanServer; |
|
26 |
| import javax.management.ObjectName; |
|
27 |
| |
|
28 |
| |
|
29 |
| |
|
30 |
| |
|
31 |
| |
|
32 |
| |
|
33 |
| |
|
34 |
| |
|
35 |
| |
|
36 |
| |
|
37 |
| public class NamingService implements NamingServiceMBean, MBeanRegistration |
|
38 |
| { |
|
39 |
| private int _port; |
|
40 |
| |
|
41 |
| private Remote _registry; |
|
42 |
| |
|
43 |
| private boolean _running; |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
2
| public NamingService()
|
|
49 |
| { |
|
50 |
2
| this(Registry.REGISTRY_PORT);
|
|
51 |
| } |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
2
| public NamingService(int port)
|
|
57 |
| { |
|
58 |
2
| _port = port;
|
|
59 |
| } |
|
60 |
| |
|
61 |
2
| public void setPort(int port)
|
|
62 |
| { |
|
63 |
2
| _port = port;
|
|
64 |
| } |
|
65 |
| |
|
66 |
2
| public int getPort()
|
|
67 |
| { |
|
68 |
2
| return _port;
|
|
69 |
| } |
|
70 |
| |
|
71 |
3
| public boolean isRunning()
|
|
72 |
| { |
|
73 |
3
| return _running;
|
|
74 |
| } |
|
75 |
| |
|
76 |
2
| public void start() throws RemoteException
|
|
77 |
| { |
|
78 |
2
| if (!isRunning())
|
|
79 |
| { |
|
80 |
2
| _registry = LocateRegistry.createRegistry(getPort());
|
|
81 |
0
| _running = true;
|
|
82 |
| } |
|
83 |
| } |
|
84 |
| |
|
85 |
1
| public void stop() throws NoSuchObjectException
|
|
86 |
| { |
|
87 |
1
| if (isRunning())
|
|
88 |
| { |
|
89 |
0
| _running = !UnicastRemoteObject.unexportObject(_registry, true);
|
|
90 |
| } |
|
91 |
| } |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
2
| public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception
|
|
98 |
| { |
|
99 |
2
| return name;
|
|
100 |
| } |
|
101 |
| |
|
102 |
| |
|
103 |
| |
|
104 |
| |
|
105 |
2
| public void postRegister(Boolean arg0)
|
|
106 |
| { |
|
107 |
| } |
|
108 |
| |
|
109 |
| |
|
110 |
| |
|
111 |
| |
|
112 |
1
| public void preDeregister() throws Exception
|
|
113 |
| { |
|
114 |
| } |
|
115 |
| |
|
116 |
| |
|
117 |
| |
|
118 |
| |
|
119 |
1
| public void postDeregister()
|
|
120 |
| { |
|
121 |
1
| try
|
|
122 |
| { |
|
123 |
1
| stop();
|
|
124 |
| } |
|
125 |
| catch (NoSuchObjectException ignore) |
|
126 |
| { |
|
127 |
| } |
|
128 |
| } |
|
129 |
| } |