⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 staxmonitorlogviewer.java

📁 Software Testing Automation Framework (STAF)的开发代码
💻 JAVA
字号:
/*****************************************************************************//* Software Testing Automation Framework (STAF)                              *//* (C) Copyright IBM Corp. 2002, 2004                                        *//*                                                                           *//* This software is licensed under the Common Public License (CPL) V1.0.     *//*****************************************************************************/package com.ibm.staf.service.stax;import com.ibm.staf.*;import com.ibm.staf.service.*;import java.io.*;import java.util.*;import javax.swing.*;import java.awt.*;class STAXMonitorLogViewer extends JFrame{    static String helpText = "\nSTAXMonitorLogViewer Help\n\n" +        "-name <STAX Log Name>\n" +        "-machine <STAX Service Machine Name>\n" +        "-machineNickname <STAX Service Machine Nickname>\n" +        "-fontName <Font Name>\n" +        "-help\n" + "-version";    static String kVersion = "3.1.0";    public static void main(String argv[])    {        new STAXMonitorLogViewer(new JFrame(), null, argv);    }    public STAXMonitorLogViewer(Component parent, STAFHandle handle,        String argv[])    {        this.parent = parent;        STAFResult res;        // If a handle was specified, don't do a system exit        if (handle != null)            fSystemExit = false;        if (argv.length < 1)        {            System.out.println("Must specify at least one parameter:  " +                               "-name, -help, or -version");            System.out.println(helpText);            System.exit(1);        }        else if (argv.length > 8)        {            System.out.println("Too many parameters");            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("-name"))                    {                        if ((i+1) > argv.length - 1)                        {                            System.out.println(                                "Parameter -name requires a value");                            System.out.println(helpText);                            System.exit(1);                        }                        fLogName = argv[i+1];                        i++;                    }                    else if (argv[i].equalsIgnoreCase("-machine"))                    {                        if ((i+1) >= argv.length)                        {                            System.out.println(                                "Parameter -machine requires a value");                            System.out.println(helpText);                            System.exit(1);                        }                        fMachine = argv[i+1];                        i++;                    }                    else if (argv[i].equalsIgnoreCase("-machineNickname"))                    {                        if ((i+1) >= argv.length)                        {                            System.out.println(                                "Parameter -machineNickname requires a value");                            System.out.println(helpText);                            System.exit(1);                        }                        fMachineNickname = argv[i+1];                        i++;                    }                    else if (argv[i].equalsIgnoreCase("-fontName"))                    {                        if ((i+1) > argv.length - 1)                        {                            System.out.println(                                "Parameter -fontName requires a value");                            System.out.println(helpText);                            System.exit(1);                        }                        fFontName = argv[i+1];                        i++;                    }                    else                    {                        System.out.println(                            "Invalid parameter name: " + argv[i]);                        System.out.println(helpText);                        System.exit(1);                    }                }            }        }        if (fLogName == null)        {            System.out.println(helpText);            System.exit(1);        }                try        {            if (handle == null)            {                fHandle = new STAFHandle("STAFLogViewer");            }            else            {                res = handle.submit2(                    "local", "HANDLE", "CREATE HANDLE NAME " +                    "STAXMonitorLogViewer");                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 (fLogName.indexOf("_Service") > -1)        {            // Find the last start record in the service log file whose            // message begins with "JobID: 1"            res = fHandle.submit2(                fMachine, "LOG", "QUERY MACHINE " + fMachineNickname +                " LOGNAME " + fLogName + " LEVELMASK Start CSCONTAINS " +                STAFUtil.wrapData("JobID: 1,") + " LAST 1");            if (res.rc != 0)            {                if (res.rc == 48)                {                    JOptionPane.showMessageDialog(                        parent, "Log " + fLogName + " for machine " +                        fMachineNickname + " on machine " + fMachine +                        " does not exist",                        "Log Does Not Exist",                        JOptionPane.INFORMATION_MESSAGE);                }                else                {                    JOptionPane.showMessageDialog(                        parent, "Error querying log " + fLogName +                        " for machine " + fMachineNickname + " on machine " +                        fMachine + ". RC=" + res.rc, "Error Querying Log",                        JOptionPane.INFORMATION_MESSAGE);                }                if (! fSystemExit)                    return;                else                    System.exit(0);            }            // Unmarshall the output from the request (1 record) and get            // the log record's timestamp            try            {                STAFMarshallingContext outputContext =                    STAFMarshallingContext.unmarshall(res.result);                java.util.List outputList =                     (java.util.List)outputContext.getRootObject();                if (outputList.size() == 0)                {                    JOptionPane.showMessageDialog(                        parent, "Log " + fLogName + " has no entries",                        "No Log Entries",                        JOptionPane.INFORMATION_MESSAGE);                                    if (! fSystemExit)                        return;                    else                        System.exit(0);                }                Map logRecord = (Map)outputList.get(0);                fStartDateTime = (String)logRecord.get("timestamp");            }            catch (Exception e)            {                fStartDateTime = null;                e.printStackTrace();            }            if (fStartDateTime == null)            {                JOptionPane.showMessageDialog(                    parent, "Log " + fLogName + " has invalid format.  " +                    "Log record doesn't contain key: 'timestamp'",                    "Invalid Log Format",                    JOptionPane.INFORMATION_MESSAGE);                if (! fSystemExit)                    return;                else                    System.exit(0);            }            fStartDateTime = fStartDateTime.replace('-', '@');        }        else        {            if (fLogName.endsWith("_User"))            {                fJobLogName = fLogName.substring(0, fLogName.length() - 5);            }            else            {                fJobLogName = fLogName;            }            // Find the last start record in the STAX job log file whose            // message begins with "JobID: "            res = fHandle.submit2(                fMachine, "LOG",                "QUERY MACHINE " + fMachineNickname + " LOGNAME " +                fJobLogName + " LEVELMASK Start CSCONTAINS " +                STAFUtil.wrapData("JobID: ") + " LAST 1");            if (res.rc != 0)            {                if (res.rc == 48)                {                    JOptionPane.showMessageDialog(                        parent, "Log " + fJobLogName + " for machine " +                        fMachineNickname + " on machine " + fMachine +                        " does not exist", "Log Does Not Exist",                        JOptionPane.INFORMATION_MESSAGE);                }                else                {                    JOptionPane.showMessageDialog(                        parent, "Error querying log " + fJobLogName +                        " for machine " + fMachineNickname + " on machine " +                        fMachine + ". RC=" + res.rc, "Error Querying Log",                        JOptionPane.INFORMATION_MESSAGE);                }                if (! fSystemExit)                    return;                else                    System.exit(0);            }            // Unmarshall the output from the request (1 record) and get            // the log record's timestamp            try            {                STAFMarshallingContext outputContext =                    STAFMarshallingContext.unmarshall(res.result);                java.util.List outputList =                     (java.util.List)outputContext.getRootObject();                if (outputList.size() == 0)                {                    JOptionPane.showMessageDialog(                        parent, "Log " + fJobLogName + " has no entries",                        "No Job Log Entries",                        JOptionPane.INFORMATION_MESSAGE);                                    if (! fSystemExit)                        return;                    else                        System.exit(0);                }                Map logRecord = (Map)outputList.get(0);                fStartDateTime = (String)logRecord.get("timestamp");            }            catch (Exception e)            {                fStartDateTime = null;                e.printStackTrace();            }                        if (fStartDateTime == null)            {                JOptionPane.showMessageDialog(                    parent, "Log " + fJobLogName + " has invalid format.  " +                    "LogRecord doesn't contain key: 'timestamp'",                    "Invalid Log Format",                    JOptionPane.INFORMATION_MESSAGE);                if (! fSystemExit)                    return;                else                    System.exit(0);            }            fStartDateTime = fStartDateTime.replace('-', '@');        }        String startDateTime = "";        if (fStartDateTime != null)        {            startDateTime = " FROM " + fStartDateTime;        }        String queryRequest = "QUERY ALL MACHINE " + fMachineNickname +            " LOGNAME " + fLogName + startDateTime;        STAFLogViewer logViewer = new STAFLogViewer(parent,                                                    fHandle,                                                    fMachine,                                                    "LOG",                                                    queryRequest,                                                    "",                                                    fFontName);    }    private STAFHandle fHandle;    private String fMachine = "local";    private String fMachineNickname = "{STAF/Config/MachineNickname}";    private String fLogName = null;    private String fJobLogName;    private String fStartTimestamp;    private String fFontName = "Dialog";    boolean fSystemExit = true;    String fStartDateTime = null;    Component parent;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -