📄 stafjvmlogviewer.java
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF) *//* (C) Copyright IBM Corp. 2007 *//* *//* This software is licensed under the Common Public License (CPL) V1.0. *//*****************************************************************************/package com.ibm.staf;import com.ibm.staf.*;import com.ibm.staf.service.*;import java.io.*;import java.util.*;import javax.swing.*;import javax.swing.border.*;import java.awt.*;import java.awt.event.*;import javax.swing.table.*;import javax.swing.event.TableModelListener;import javax.swing.event.TableModelEvent;public class STAFJVMLogViewer extends JFrame{ static String helpText = "\nSTAFJVMLogViewer Help\n\n" + "Description:\n\n" + "The STAFJVMLogViewer displays a JVM log for a STAF Java service " + "that is\ncurrently registered. You can specify the machine where " + "the STAF Java service\nis registered and you can specify/select " + "the name of the STAF service and it\nwill display it's JVM log.\n\n" + "Parameters:\n\n" + "-machine <Machine where the STAF Java service is registered>\n" + "-serviceName <Java Service Name>\n" + "-displayAll\n" + "-fontName <Font Name>\n" + "-help\n" + "-version\n\n" + "Notes:\n\n" + "1) If the -machine option is not specified, it defaults to local.\n" + "2) If the -serviceName option is not specified, you'll be prompted " + "to select a\nservice registered on the specified machine whose " + "JVM Log you want to display.\n" + "3) If the -displayAll option is not specified, only the entries in " + "the JVM Log\nfrom the last time the JVM was created are shown.\n" + "4) If the -fontName option is not specified, it defaults to the " + "Monospaced\nfont.\n" + "5) If specifying the -help or -version option, it must be the " + "first (and only)\noption specified.\n\n" + "Examples:\n\n" + " java com.ibm.staf.STAFJVMLogViewer\n" + " java com.ibm.staf.STAFJVMLogViewer -serviceName STAX\n" + " java com.ibm.staf.STAFJVMLogViewer -machine server1\n" + " java com.ibm.staf.STAFJVMLogViewer -machine server1 " + "-serviceName CRON"; static String kVersion = "3.0.0"; public static void main(String argv[]) { String machine = "local"; String serviceName = ""; boolean displayAll = false; String fontName = "Monospaced"; int maxArgsAllowed = 7; if (argv.length == 0) { // Do no argument processing } else if (argv.length > maxArgsAllowed) { System.out.println( "\nERROR: Too many arguments. You specified " + argv.length + " arguments, but only up to " + maxArgsAllowed + " arguments are allowed."); System.out.println(helpText); System.exit(1); } else { if (argv[0].equalsIgnoreCase("-help")) { System.out.println(helpText); System.exit(0); } else if (argv[0].equalsIgnoreCase("-version")) { System.out.println(kVersion); System.exit(0); } else { for (int i = 0; i < argv.length; i++) { if (argv[i].equalsIgnoreCase("-machine")) { if ((i+1) >= argv.length) { System.out.println( "\nERROR: Parameter -machine requires a " + "value"); System.out.println(helpText); System.exit(1); } machine = argv[i+1]; i++; } else if (argv[i].equalsIgnoreCase("-serviceName")) { if ((i+1) > argv.length - 1) { System.out.println( "\nERROR: Parameter -serviceName requires " + "a value"); System.out.println(helpText); System.exit(1); } serviceName = argv[i+1]; i++; } else if (argv[i].equalsIgnoreCase("-displayAll")) { displayAll = true; } else if (argv[i].equalsIgnoreCase("-fontName")) { if ((i+1) > argv.length - 1) { System.out.println( "\nERROR: Parameter -fontName requires a " + "value"); System.out.println(helpText); System.exit(1); } fontName = argv[i+1]; i++; } else if (argv[i].equalsIgnoreCase("-version")) { System.out.println( "\nERROR: Parameter -version must be specified " + "as the first and only parameter"); System.out.println(helpText); System.exit(1); } else if (argv[i].equalsIgnoreCase("-help")) { System.out.println( "\nERROR: Parameter -help must be specified as " + "the first and only parameter"); System.out.println(helpText); System.exit(1); } else { System.out.println( "\nERROR: Invalid parameter name: " + argv[i]); System.out.println(helpText); System.exit(1); } } } } new STAFJVMLogViewer(new JFrame(), null, machine, serviceName, displayAll, fontName); } public STAFJVMLogViewer(Component parent, STAFHandle handle, String serviceName) { this(parent, handle, "local", serviceName, false, "Monospaced"); } public STAFJVMLogViewer(Component parent, STAFHandle handle, String machine, String serviceName) { this(parent, handle, machine, serviceName, false, "Monospaced"); } public STAFJVMLogViewer(Component parent, STAFHandle handle, String machine, String serviceName, boolean displayAll, String fontName) { this.parent = parent; fMachine = machine; fServiceName = serviceName; fDisplayAll = displayAll; fFontName = fontName; fJVMLogName = "JVMLog.1"; STAFResult res; // If a handle was specified, don't do a system exit if (handle != null) fSystemExit = false; try { if (handle == null) { fHandle = new STAFHandle("STAFJVMLogViewer"); } else { res = handle.submit2( "local", "HANDLE", "CREATE HANDLE NAME " + "STAFJVMLogViewer"); if (res.rc == 0) { fHandle = new STAFHandle(new Integer(res.result).intValue()); } else { fHandle = handle; } } } catch(STAFException e) { System.out.println("Error registering with STAF, RC: " + e.rc); //e.printStackTrace(); if (! fSystemExit) return; else System.exit(0); } if (serviceName.equals("")) { // Determine the service name whose JVM Log is to be viewed // Get a list of all Java services registered on the specified // machine String request = "LIST SERVICES"; STAFResult result = fHandle.submit2( machine, "SERVICE", request); if (result.rc != 0) { showErrorDialog( parent, "Error submitting request: STAF " + machine + " SERVICE " + request + "\n\n" + "RC:" + result.rc + "\nResult: " + result.result); if (! fSystemExit) return; else System.exit(0); } STAFMarshallingContext mc = STAFMarshallingContext.unmarshall( result.result); java.util.List serviceList = (java.util.List)mc.getRootObject(); Iterator serviceIter = serviceList.iterator(); java.util.List javaServiceList = new ArrayList(); while (serviceIter.hasNext()) { Map serviceMap = (Map)serviceIter.next(); String library = (String)serviceMap.get("library"); if (library.equals("JSTAF")) { String theServiceName = (String)serviceMap.get("name"); javaServiceList.add(theServiceName); } } if (javaServiceList.size() == 0) { showErrorDialog( parent, "No Java services are registered on machine " + machine); if (! fSystemExit) return; else System.exit(0); } // Show a dialog asking the user to select a service. // Convert the list of Java services to an array Object[] possibleValues = javaServiceList.toArray(new Object[0]); Object selectedValue = JOptionPane.showInputDialog( parent, "Choose the service whose JVM Log you want to display", "Select Java Service", JOptionPane.INFORMATION_MESSAGE, null, possibleValues, null); if (selectedValue == null) { // Cancel button was selected if (! fSystemExit) return; else System.exit(1); } serviceName = (String)selectedValue; } // Determine the name of the JVMLog to view as follows: // Submit: STAF <serviceMachine> SERVICE QUERY SERVICE <serviceName> // If successful, the result is a marshalled map. Get the "Options" // value from the map which is a list of the options specified when // registering the service. Iterate through the options list and see // if a value in the list begins with "JVMName=". If so, get it's // JVMName value. Otherwise, assign STAFJVM1 as the JVMName. // The most current JVM Log location is: // {STAF/DataDir}/lang/java/jvm/<JVMName>/JVMLog.1 String JVMName = "STAFJVM1"; // Default JVM Name res = fHandle.submit2(machine, "SERVICE", "QUERY SERVICE " + serviceName); if (res.rc != 0) { String errorMsg = "Error submitting request: STAF " + machine + " SERVICE QUERY SERVICE " + serviceName + "\nRC: " + res.rc + "\nResult: " + res.result; if (res.rc == STAFResult.DoesNotExist) { errorMsg += "\n\nThe " + serviceName + " service is not " + "currently registered on machine " + machine; } JOptionPane.showMessageDialog( parent, errorMsg, "Error Querying Service", JOptionPane.INFORMATION_MESSAGE); if (! fSystemExit) return; else System.exit(0); } try { STAFMarshallingContext mc = STAFMarshallingContext.unmarshall( res.result); Map serviceMap = (HashMap)mc.getRootObject(); java.util.List optionList = (java.util.List)serviceMap.get( "options"); Iterator optionIter = optionList.iterator(); String jvmNameOption = "JVMName="; while (optionIter.hasNext()) { String option = (String)optionIter.next(); if (option.startsWith(jvmNameOption)) { JVMName = (option.substring(jvmNameOption.length())). trim(); break; } } } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog( parent, "Error determining the JVMName for the " + serviceName + " service on machine " + machine, "Error Determining the JVMName", JOptionPane.INFORMATION_MESSAGE); if (! fSystemExit) return; else System.exit(0); } fJVMName = JVMName;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -