View Javadoc
1   /*
2    * Copyright (C) 2005-2015 Schlichtherle IT Services.
3    * All rights reserved. Use is subject to license terms.
4    */
5   package net.java.truecommons.jmx.sl;
6   
7   import javax.annotation.concurrent.Immutable;
8   import javax.management.MBeanServer;
9   import net.java.truecommons.jmx.spi.MBeanServerDecorator;
10  import net.java.truecommons.jmx.spi.MBeanServerProvider;
11  import net.java.truecommons.services.Container;
12  import net.java.truecommons.services.ServiceLocator;
13  
14  /**
15   * A container of the singleton MBean server.
16   * The MBean server is created by using a {@link ServiceLocator} to search for
17   * advertised implementations of the factory service specification class
18   * {@link MBeanServerProvider}
19   * and the decorator service specification class
20   * {@link MBeanServerDecorator}.
21   *
22   * @since  TrueCommons 2.3
23   * @author Christian Schlichtherle
24   */
25  @Immutable
26  public final class MBeanServerLocator implements Container<MBeanServer> {
27  
28      /** The singleton instance of this class. */
29      public static final MBeanServerLocator SINGLETON = new MBeanServerLocator();
30  
31      private MBeanServerLocator() { }
32  
33      @Override
34      public MBeanServer get() { return Lazy.mbs; }
35  
36      /** A static data utility class used for lazy initialization. */
37      private static final class Lazy {
38          static final MBeanServer mbs
39                  = new ServiceLocator(MBeanServerLocator.class)
40                  .container(MBeanServerProvider.class, MBeanServerDecorator.class)
41                  .get();
42      }
43  }