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 .util .HashMap ;
@@ -417,18 +418,6 @@ private JMXConnectorServer createServer(String serverName,
417
418
RMIClientSocketFactory registryCsf , RMIServerSocketFactory registrySsf ,
418
419
RMIClientSocketFactory serverCsf , RMIServerSocketFactory serverSsf ) {
419
420
420
- // Create the RMI registry
421
- Registry registry ;
422
- try {
423
- registry = LocateRegistry .createRegistry (
424
- theRmiRegistryPort , registryCsf , registrySsf );
425
- } catch (RemoteException e ) {
426
- log .error (sm .getString (
427
- "jmxRemoteLifecycleListener.createRegistryFailed" ,
428
- serverName , Integer .toString (theRmiRegistryPort )), e );
429
- return null ;
430
- }
431
-
432
421
if (bindAddress == null ) {
433
422
bindAddress = "localhost" ;
434
423
}
@@ -449,11 +438,20 @@ private JMXConnectorServer createServer(String serverName,
449
438
cs = new RMIConnectorServer (serviceUrl , theEnv , server ,
450
439
ManagementFactory .getPlatformMBeanServer ());
451
440
cs .start ();
452
- registry .bind ("jmxrmi" , server .toStub ());
441
+ Remote jmxServer = server .toStub ();
442
+ // Create the RMI registry
443
+ try {
444
+ new JmxRegistry (theRmiRegistryPort , registryCsf , registrySsf , "jmxrmi" , jmxServer );
445
+ } catch (RemoteException e ) {
446
+ log .error (sm .getString (
447
+ "jmxRemoteLifecycleListener.createRegistryFailed" ,
448
+ serverName , Integer .toString (theRmiRegistryPort )), e );
449
+ return null ;
450
+ }
453
451
log .info (sm .getString ("jmxRemoteLifecycleListener.start" ,
454
452
Integer .toString (theRmiRegistryPort ),
455
453
Integer .toString (theRmiServerPort ), serverName ));
456
- } catch (IOException | AlreadyBoundException e ) {
454
+ } catch (IOException e ) {
457
455
log .error (sm .getString (
458
456
"jmxRemoteLifecycleListener.createServerFailed" ,
459
457
serverName ), e );
@@ -589,4 +587,39 @@ public boolean equals(Object obj) {
589
587
return true ;
590
588
}
591
589
}
590
+
591
+
592
+ private static class JmxRegistry extends sun .rmi .registry .RegistryImpl {
593
+ private static final long serialVersionUID = -3772054804656428217L ;
594
+ private final String jmxName ;
595
+ private final Remote jmxServer ;
596
+ public JmxRegistry (int port , RMIClientSocketFactory csf ,
597
+ RMIServerSocketFactory ssf , String jmxName , Remote jmxServer ) throws RemoteException {
598
+ super (port , csf , ssf );
599
+ this .jmxName = jmxName ;
600
+ this .jmxServer = jmxServer ;
601
+ }
602
+ @ Override
603
+ public Remote lookup (String name )
604
+ throws RemoteException , NotBoundException {
605
+ return (jmxName .equals (name )) ? jmxServer : null ;
606
+ }
607
+ @ Override
608
+ public void bind (String name , Remote obj )
609
+ throws RemoteException , AlreadyBoundException , AccessException {
610
+ }
611
+ @ Override
612
+ public void unbind (String name )
613
+ throws RemoteException , NotBoundException , AccessException {
614
+ }
615
+ @ Override
616
+ public void rebind (String name , Remote obj )
617
+ throws RemoteException , AccessException {
618
+ }
619
+ @ Override
620
+ public String [] list () throws RemoteException {
621
+ return new String [] { jmxName };
622
+ }
623
+ }
624
+
592
625
}
0 commit comments