< prev index next >

src/java.management/share/classes/java/lang/management/ManagementFactory.java

Print this page
rev 14279 : [mq]: 8140281-deprecation-optional.get


 926                                           }))
 927                            .values().stream();
 928         }
 929 
 930         // Finds the first PlatformComponent whose mbeanInterfaceNames() list
 931         // contains the specified class name. An MBean interface can be implemented
 932         // by different MBeans, provided by different platform components.
 933         // For instance the MemoryManagerMXBean interface is implemented both by
 934         // regular memory managers, and garbage collector MXBeans. This method is
 935         // mainly used to verify that there is at least one PlatformComponent
 936         // which provides an implementation of the desired interface.
 937         static PlatformComponent<?> findFirst(Class<?> mbeanIntf)
 938         {
 939             String name = mbeanIntf.getName();
 940             Optional<PlatformComponent<?>> op = getMap().values()
 941                 .stream()
 942                 .filter(pc -> pc.mbeanInterfaceNames().contains(name))
 943                 .findFirst();
 944 
 945             if (op.isPresent()) {
 946                 return op.get();
 947             } else {
 948                 return null;
 949             }
 950         }
 951 
 952         // Finds a PlatformComponent whose mbeanInterface name list contains
 953         // the specified class name, and make sure that one and only one exists.
 954         static PlatformComponent<?> findSingleton(Class<?> mbeanIntf)
 955         {
 956             String name = mbeanIntf.getName();
 957             Optional<PlatformComponent<?>> op = getMap().values()
 958                 .stream()
 959                 .filter(pc -> pc.mbeanInterfaceNames().contains(name))
 960                 .reduce((p1, p2) -> {
 961                     if (p2 != null) {
 962                         throw new IllegalArgumentException(mbeanIntf.getName() +
 963                             " can have more than one instance");
 964                     } else {
 965                         return p1;
 966                     }
 967                 });
 968 
 969             PlatformComponent<?> singleton = op.isPresent() ? op.get() : null;
 970             if (singleton == null) {
 971                 throw new IllegalArgumentException(mbeanIntf.getName() +
 972                     " is not a platform management interface");
 973             }
 974             if (!singleton.isSingleton()) {
 975                 throw new IllegalArgumentException(mbeanIntf.getName() +
 976                     " can have more than one instance");
 977             }
 978             return singleton;
 979         }
 980     }
 981 
 982     static {
 983         AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
 984             System.loadLibrary("management");
 985             return null;
 986         });
 987     }
 988 }


 926                                           }))
 927                            .values().stream();
 928         }
 929 
 930         // Finds the first PlatformComponent whose mbeanInterfaceNames() list
 931         // contains the specified class name. An MBean interface can be implemented
 932         // by different MBeans, provided by different platform components.
 933         // For instance the MemoryManagerMXBean interface is implemented both by
 934         // regular memory managers, and garbage collector MXBeans. This method is
 935         // mainly used to verify that there is at least one PlatformComponent
 936         // which provides an implementation of the desired interface.
 937         static PlatformComponent<?> findFirst(Class<?> mbeanIntf)
 938         {
 939             String name = mbeanIntf.getName();
 940             Optional<PlatformComponent<?>> op = getMap().values()
 941                 .stream()
 942                 .filter(pc -> pc.mbeanInterfaceNames().contains(name))
 943                 .findFirst();
 944 
 945             if (op.isPresent()) {
 946                 return op.getWhenPresent();
 947             } else {
 948                 return null;
 949             }
 950         }
 951 
 952         // Finds a PlatformComponent whose mbeanInterface name list contains
 953         // the specified class name, and make sure that one and only one exists.
 954         static PlatformComponent<?> findSingleton(Class<?> mbeanIntf)
 955         {
 956             String name = mbeanIntf.getName();
 957             Optional<PlatformComponent<?>> op = getMap().values()
 958                 .stream()
 959                 .filter(pc -> pc.mbeanInterfaceNames().contains(name))
 960                 .reduce((p1, p2) -> {
 961                     if (p2 != null) {
 962                         throw new IllegalArgumentException(mbeanIntf.getName() +
 963                             " can have more than one instance");
 964                     } else {
 965                         return p1;
 966                     }
 967                 });
 968 
 969             PlatformComponent<?> singleton = op.isPresent() ? op.getWhenPresent() : null;
 970             if (singleton == null) {
 971                 throw new IllegalArgumentException(mbeanIntf.getName() +
 972                     " is not a platform management interface");
 973             }
 974             if (!singleton.isSingleton()) {
 975                 throw new IllegalArgumentException(mbeanIntf.getName() +
 976                     " can have more than one instance");
 977             }
 978             return singleton;
 979         }
 980     }
 981 
 982     static {
 983         AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
 984             System.loadLibrary("management");
 985             return null;
 986         });
 987     }
 988 }
< prev index next >