25
25
import java .net .ServerSocket ;
26
26
import java .net .Socket ;
27
27
import java .net .UnknownHostException ;
28
+ import java .rmi .AccessException ;
28
29
import java .rmi .AlreadyBoundException ;
30
+ import java .rmi .NotBoundException ;
31
+ import java .rmi .Remote ;
29
32
import java .rmi .RemoteException ;
30
- import java .rmi .registry .LocateRegistry ;
31
- import java .rmi .registry .Registry ;
32
33
import java .rmi .server .RMIClientSocketFactory ;
33
34
import java .rmi .server .RMIServerSocketFactory ;
34
35
import java .security .NoSuchAlgorithmException ;
@@ -300,18 +301,6 @@ private JMXConnectorServer createServer(String serverName,
300
301
RMIClientSocketFactory registryCsf , RMIServerSocketFactory registrySsf ,
301
302
RMIClientSocketFactory serverCsf , RMIServerSocketFactory serverSsf ) {
302
303
303
- // Create the RMI registry
304
- Registry registry ;
305
- try {
306
- registry = LocateRegistry .createRegistry (
307
- theRmiRegistryPort , registryCsf , registrySsf );
308
- } catch (RemoteException e ) {
309
- log .error (sm .getString (
310
- "jmxRemoteLifecycleListener.createRegistryFailed" ,
311
- serverName , Integer .toString (theRmiRegistryPort )), e );
312
- return null ;
313
- }
314
-
315
304
if (bindAddress == null ) {
316
305
bindAddress = "localhost" ;
317
306
}
@@ -332,11 +321,20 @@ private JMXConnectorServer createServer(String serverName,
332
321
cs = new RMIConnectorServer (serviceUrl , theEnv , server ,
333
322
ManagementFactory .getPlatformMBeanServer ());
334
323
cs .start ();
335
- registry .bind ("jmxrmi" , server .toStub ());
324
+ Remote jmxServer = server .toStub ();
325
+ // Create the RMI registry
326
+ try {
327
+ new JmxRegistry (theRmiRegistryPort , registryCsf , registrySsf , "jmxrmi" , jmxServer );
328
+ } catch (RemoteException e ) {
329
+ log .error (sm .getString (
330
+ "jmxRemoteLifecycleListener.createRegistryFailed" ,
331
+ serverName , Integer .toString (theRmiRegistryPort )), e );
332
+ return null ;
333
+ }
336
334
log .info (sm .getString ("jmxRemoteLifecycleListener.start" ,
337
335
Integer .toString (theRmiRegistryPort ),
338
336
Integer .toString (theRmiServerPort ), serverName ));
339
- } catch (IOException | AlreadyBoundException e ) {
337
+ } catch (IOException e ) {
340
338
log .error (sm .getString (
341
339
"jmxRemoteLifecycleListener.createServerFailed" ,
342
340
serverName ), e );
@@ -492,4 +490,39 @@ public boolean equals(Object obj) {
492
490
return true ;
493
491
}
494
492
}
493
+
494
+
495
+ private static class JmxRegistry extends sun .rmi .registry .RegistryImpl {
496
+ private static final long serialVersionUID = -3772054804656428217L ;
497
+ private final String jmxName ;
498
+ private final Remote jmxServer ;
499
+ public JmxRegistry (int port , RMIClientSocketFactory csf ,
500
+ RMIServerSocketFactory ssf , String jmxName , Remote jmxServer ) throws RemoteException {
501
+ super (port , csf , ssf );
502
+ this .jmxName = jmxName ;
503
+ this .jmxServer = jmxServer ;
504
+ }
505
+ @ Override
506
+ public Remote lookup (String name )
507
+ throws RemoteException , NotBoundException {
508
+ return (jmxName .equals (name )) ? jmxServer : null ;
509
+ }
510
+ @ Override
511
+ public void bind (String name , Remote obj )
512
+ throws RemoteException , AlreadyBoundException , AccessException {
513
+ }
514
+ @ Override
515
+ public void unbind (String name )
516
+ throws RemoteException , NotBoundException , AccessException {
517
+ }
518
+ @ Override
519
+ public void rebind (String name , Remote obj )
520
+ throws RemoteException , AccessException {
521
+ }
522
+ @ Override
523
+ public String [] list () throws RemoteException {
524
+ return new String [] { jmxName };
525
+ }
526
+ }
527
+
495
528
}
0 commit comments