Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/management/jdp/JdpDoSomething.java
38841 views
/*1* Copyright (c) 2012, 2013, 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*/2223import java.io.File;24import java.io.IOException;25import java.io.RandomAccessFile;26import java.util.Objects;2728import sun.management.jdp.JdpJmxPacket;29import sun.management.jdp.JdpException;3031public class JdpDoSomething {3233private static final String lockFileName = "JdpDoSomething.lck";34private static final boolean verbose = false;3536public static boolean getVerbose() {37return verbose;38}3940public static void printJdpPacket(JdpJmxPacket p) {41if (getVerbose()) {42try {43RandomAccessFile f = new RandomAccessFile("out.dmp", "rw");44f.write(p.getPacketData());45f.close();46} catch (IOException e) {47System.out.println("Can't write a dump file: " + e);48}4950System.out.println("Id: " + p.getId());51System.out.println("Jmx: " + p.getJmxServiceUrl());52System.out.println("Main: " + p.getMainClass());53System.out.println("InstanceName: " + p.getInstanceName());54System.out.println("ProccessId: " + p.getProcessId());55System.out.println("BroadcastInterval: " + p.getBroadcastInterval());56System.out.println("Rmi Hostname: " + p.getRmiHostname());5758System.out.flush();59}60}6162public static void compaireJdpPacketEx(JdpJmxPacket p1, JdpJmxPacket p2)63throws JdpException {6465if (!Objects.equals(p1, p1)) {66throw new JdpException("Packet mismatch error");67}6869if (!Objects.equals(p1.getMainClass(), p2.getMainClass())) {70throw new JdpException("Packet mismatch error (main class)");71}7273if (!Objects.equals(p1.getInstanceName(), p2.getInstanceName())) {74throw new JdpException("Packet mismatch error (instance name)");75}76}7778public static void doSomething() {79try {80File lockFile = new File(lockFileName);81lockFile.createNewFile();8283while (lockFile.exists()) {84long datetime = lockFile.lastModified();85long epoch = System.currentTimeMillis() / 1000;8687// Don't allow test app to run more than an hour88if (epoch - datetime > 3600) {89System.err.println("Lock is too old. Aborting");90return;91}92Thread.sleep(1);93}9495} catch (Throwable e) {96System.err.println("Something bad happens:" + e);97}98}99100public static void main(String args[]) throws Exception {101System.err.println("main enter");102doSomething();103System.err.println("main exit");104}105}106107108