Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/management/ImplementationVersion/ImplVersionCommand.java
38838 views
/*1* Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24*/2526import javax.management.MBeanServer;27import javax.management.MBeanServerFactory;28import javax.management.ObjectName;2930public class ImplVersionCommand {3132public static void main(String[] args) throws Exception {33// Instantiate the MBean server34//35System.out.println("Create the MBean server");36MBeanServer mbs = MBeanServerFactory.createMBeanServer();3738// Get the JMX implementation version from the MBeanServerDelegateMBean39//40System.out.println("Get the JMX implementation version");41ObjectName mbsdName =42new ObjectName("JMImplementation:type=MBeanServerDelegate");43String mbsdAttribute = "ImplementationVersion";44String mbsdVersion = (String) mbs.getAttribute(mbsdName, mbsdAttribute);4546// Display JMX implementation version and JVM implementation version47//48System.out.println("JMX implementation version = " +49mbsdVersion);50System.out.println("Java Runtime implementation version = " +51args[0]);5253// Check JMX implementation version vs. JVM implementation version54//55if (Boolean.valueOf(args[1]).booleanValue()) {56if (!mbsdVersion.equals(args[0]))57throw new IllegalArgumentException(58"JMX and Java Runtime implementation versions do not match!");59// Test OK!60//61System.out.println("JMX and Java Runtime implementation " +62"versions match!");63} else {64// Test OK!65//66System.out.println("JMX and Java Runtime implementation " +67"versions do not match because the test " +68"is using an unbundled version of JMX!");69}70System.out.println("Bye! Bye!");71}72}737475