|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
NamingService.java | 50% | 100% | 100% | 92.9% |
|
1 |
// Copyright 2005 The Apache Software Foundation
|
|
2 |
//
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
5 |
// You may obtain a copy of the License at
|
|
6 |
//
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
//
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
// See the License for the specific language governing permissions and
|
|
13 |
// limitations under the License.
|
|
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 |
* MBean that starts an rmiregistry.
|
|
30 |
* <p>
|
|
31 |
* Calling {@link #start}will launch rmiregistry in the same JVM; this way rmiregistry will have in
|
|
32 |
* its classpath the same classes the JVM has.
|
|
33 |
*
|
|
34 |
* @author Achim Huegen
|
|
35 |
* @since 1.1
|
|
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 |
* Creates a new instance of NamingService with the default rmiregistry port (1099).
|
|
47 |
*/
|
|
48 | 2 |
public NamingService()
|
49 |
{ |
|
50 | 2 |
this(Registry.REGISTRY_PORT);
|
51 |
} |
|
52 |
|
|
53 |
/**
|
|
54 |
* Creates a new instance of NamingService with the specified port.
|
|
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 | 2 |
_running = true;
|
82 |
} |
|
83 |
} |
|
84 |
|
|
85 | 1 |
public void stop() throws NoSuchObjectException |
86 |
{ |
|
87 | 1 |
if (isRunning())
|
88 |
{ |
|
89 | 1 |
_running = !UnicastRemoteObject.unexportObject(_registry, true);
|
90 |
} |
|
91 |
} |
|
92 |
|
|
93 |
/**
|
|
94 |
* @see javax.management.MBeanRegistration#preRegister(javax.management.MBeanServer,
|
|
95 |
* javax.management.ObjectName)
|
|
96 |
*/
|
|
97 | 2 |
public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception |
98 |
{ |
|
99 | 2 |
return name;
|
100 |
} |
|
101 |
|
|
102 |
/**
|
|
103 |
* @see javax.management.MBeanRegistration#postRegister(java.lang.Boolean)
|
|
104 |
*/
|
|
105 | 2 |
public void postRegister(Boolean arg0) |
106 |
{ |
|
107 |
} |
|
108 |
|
|
109 |
/**
|
|
110 |
* @see javax.management.MBeanRegistration#preDeregister()
|
|
111 |
*/
|
|
112 | 1 |
public void preDeregister() throws Exception |
113 |
{ |
|
114 |
} |
|
115 |
|
|
116 |
/**
|
|
117 |
* @see javax.management.MBeanRegistration#postDeregister()
|
|
118 |
*/
|
|
119 | 1 |
public void postDeregister() |
120 |
{ |
|
121 | 1 |
try
|
122 |
{ |
|
123 | 1 |
stop(); |
124 |
} |
|
125 |
catch (NoSuchObjectException ignore)
|
|
126 |
{ |
|
127 |
} |
|
128 |
} |
|
129 |
} |
|