16
16
*/
17
17
package org .apache .logging .log4j .core ;
18
18
19
+ import static org .apache .logging .log4j .core .jmx .internal .JmxUtil .isJmxDisabled ;
19
20
import static org .apache .logging .log4j .core .util .ShutdownCallbackRegistry .SHUTDOWN_HOOK_MARKER ;
20
21
21
22
import edu .umd .cs .findbugs .annotations .SuppressFBWarnings ;
@@ -370,12 +371,7 @@ public boolean stop(final long timeout, final TimeUnit timeUnit) {
370
371
}
371
372
372
373
this .setStopping ();
373
- try {
374
- Server .unregisterLoggerContext (getName ()); // LOG4J2-406, LOG4J2-500
375
- } catch (final LinkageError | Exception e ) {
376
- // LOG4J2-1506 Hello Android, GAE
377
- LOGGER .error ("Unable to unregister MBeans" , e );
378
- }
374
+ unregisterJmxBeans ();
379
375
if (shutdownCallback != null ) {
380
376
shutdownCallback .cancel ();
381
377
shutdownCallback = null ;
@@ -407,6 +403,17 @@ public boolean stop(final long timeout, final TimeUnit timeUnit) {
407
403
return true ;
408
404
}
409
405
406
+ private void unregisterJmxBeans () {
407
+ if (!isJmxDisabled ()) {
408
+ try {
409
+ Server .unregisterLoggerContext (getName ()); // LOG4J2-406, LOG4J2-500
410
+ } catch (final LinkageError | Exception error ) {
411
+ // LOG4J2-1506 Hello Android, GAE
412
+ LOGGER .error ("Unable to unregister MBeans" , error );
413
+ }
414
+ }
415
+ }
416
+
410
417
/**
411
418
* Gets the name.
412
419
*
@@ -638,12 +645,8 @@ public Configuration setConfiguration(final Configuration config) {
638
645
639
646
firePropertyChangeEvent (new PropertyChangeEvent (this , PROPERTY_CONFIG , prev , config ));
640
647
641
- try {
642
- Server .reregisterMBeansAfterReconfigure ();
643
- } catch (final LinkageError | Exception e ) {
644
- // LOG4J2-716: Android has no java.lang.management
645
- LOGGER .error ("Could not reconfigure JMX" , e );
646
- }
648
+ registerJmxBeans ();
649
+
647
650
// AsyncLoggers update their nanoClock when the configuration changes
648
651
Log4jLogEvent .setNanoClock (configuration .getNanoClock ());
649
652
@@ -653,6 +656,17 @@ public Configuration setConfiguration(final Configuration config) {
653
656
}
654
657
}
655
658
659
+ private static void registerJmxBeans () {
660
+ if (!isJmxDisabled ()) {
661
+ try {
662
+ Server .reregisterMBeansAfterReconfigure ();
663
+ } catch (final LinkageError | Exception error ) {
664
+ // LOG4J2-716: Android has no java.lang.management
665
+ LOGGER .error ("Could not reconfigure JMX" , error );
666
+ }
667
+ }
668
+ }
669
+
656
670
private void firePropertyChangeEvent (final PropertyChangeEvent event ) {
657
671
for (final PropertyChangeListener listener : propertyChangeListeners ) {
658
672
listener .propertyChange (event );
0 commit comments