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

📄 systemstatus.java

📁 这是一个用java和xml编写的流媒体服务器管理软件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
  /**   * This is where this object starts from.   * @param hostname Host to connect to.   * @param port Port that host is listening on.   *    * @throws SNMPClientException when a connection error occurs.   * @throws SystemStatusException when there is a GUI error.   *    */  void init(String aHostname,             int aPort) throws SNMPClientException, SystemStatusException  {    System.out.println("starting init");    System.out.println("init called with aHostname: " + aHostname + " aPort "                        + new Integer(aPort).toString());    hostname = aHostname;    port = aPort;  }  /**   * Method declaration   *    *    * @param numberString   *    */  private void handleVersionNumber(String numberString)  {    int newVersionNumber = 0;    try    {      newVersionNumber = Integer.parseInt(numberString);      versionNumber = newVersionNumber;    }    catch (NumberFormatException e)    {      System.out.println("version number " + numberString                          + " threw NumberFormatException: " + e.getMessage());    }  }  private void handleError(String errorMessage)  {    System.out.println("Error: " + errorMessage);    JOptionPane.showMessageDialog(this, errorMessage, "Error",             JOptionPane.ERROR_MESSAGE);  }  /**   * This inner class handles SAX callbacks.   */  class SAXHandler extends DefaultHandler  {    /**     * static definitions for tags     */    private final static String ERROR = "error";    private final static String VERSION = "version";    private final static String DATA = "data";    private final static String SERVERCONFIG = "serverconfig";    private final static String IP = "ip";    private final static String PORT = "port";    private final static String SERVERTYPE = "servertype";    private final static String SERVERSTATUS = "serverstatus";    /**     * When an element comes in, this is set to the element type     */    private Vector elementTypes;    /**     * Receive notification of the start of an element.     * @param uri Ignored.     * @param localName Ignored.     * @param rawName The raw XML name.     * @param attrs the attributes attached to the element.     * If there are no attributes, an empty Attributes object.     */    public void startElement(String uri, String localName, String rawName,             Attributes attributes)    {      // if rawName is ERROR that will be handled in      // characters method.      if (rawName.equals(DATA))      {        elementTypes = new Vector();        String version = attributes.getValue(VERSION);        // uncomment for debugging        // System.out.println("VERSION is " + version);        if (version != null)        {          handleVersionNumber(version);        }      }      else if (rawName.equals(SERVERCONFIG))      {        String ip = attributes.getValue(IP);        String port = attributes.getValue(PORT);        String type = attributes.getValue(SERVERTYPE);        String status = attributes.getValue(SERVERSTATUS);        try        {          changeEvent(ip, port, type, status);        }        catch (Exception e)        {          System.out.println("GUI changeEvent threw " + e.getMessage());        }      }      elementTypes.add(rawName);      // the character data will now be handled by the characters method.    }   // startElement    /**     * Receive notification of the end of an element.     * @param namespaceuri Ignored.     * @param localName Ignored.     * @param rawName The raw XML name.     */    public void endElement(String namespaceuri, String localName,             String rawName)    {      if (rawName.equals(ERROR))      {        System.out.println("name is error");      }      else if (rawName.equals(VERSION))      {        System.out.println("name is version");      }      String lastElementType =         (String) (elementTypes.remove(elementTypes.size() - 1));      if (!rawName.equals(lastElementType))      {        System.out.println("Element mismatch: ending " + rawName                            + " but lastElementType is " + lastElementType);      }    }   // endElement    /**     * Method declaration     *      *      * @param ch     * @param start     * @param length     *      */    public void characters(char[] ch, int start, int length)    {      String lastElementType = (String) (elementTypes.lastElement());      if (lastElementType.equalsIgnoreCase(ERROR))      {        handleError(new String(ch, start, length));      }    }  }}/** * This class encapsulates a single object identifier as a number, a String name * describing the associated object, String ip address and String port name. * Instances of this class are passed directly to the DefaultMutableTreeNode constructor * to act as a node. */class OidNode{  final static int ROOT = 0;  final static int HOST = 1;  final static int PORT = 2;  final static int STATUS = 3;  /**   * This identifier is used to find a unique node.   * No two siblings may have the same identifier.   */  private String identifier;  /**   * This string is sent to the SNMP Manager for a start or stop request.   * It is only needed by tyep PORT.   */  private String descriptorString = "";  /**   * The parent of the DefaultMutableTreeNode that created this user object.   */  private DefaultMutableTreeNode parentNode;  /**   * This type is used instead of subclassing.   */  private int type;  /**   * Empty if no alarms are raised.   */  private Vector alarms = new Vector();  /**   *    */  public int getType()  {    return type;  }  /**   * @return true if an alarm should be raised.   */  public synchronized boolean isAlarmed()  {    if (alarms.isEmpty())    {      return false;    }    return true;  }  public void setDescriptorString(String host, String port, String type)  {    descriptorString = (host + ":" + port + "," + type);  }  public String getDescriptorString()  {    return descriptorString;  }  /**   * Used by this class and by child node to raise or   * clear an alarm.   *    * @param newValue True if alarm should be raised.   * @param requester Object requesting that alarm be raised.   * This object will be added to the queue of objects that   * have requested an alarm be raised. The alarm will not   * be cleared until all objects that raised an alarm have   * cleared it.   */  protected synchronized void setAlarmed(boolean newValue, Object requester)  {    if (newValue)    {      /*       * We are raising an alarm. If the requester is not       * already in the alarms queue, then put it there.       */      if (!alarms.contains(requester))      {        alarms.add(requester);      }    }    else    {      /*       * We are clearing an alarm. Remove the requester frm       * the alarm queue.       */      alarms.remove(requester);    }    if (parentNode != null)    {      ((OidNode) (parentNode.getUserObject())).setAlarmed(newValue, this);    }  }  /**   * display string of the node.   */  private String displayString;  /**   * Constructor for creating the node   */  public OidNode(String id, DefaultMutableTreeNode theParentNode, int aType)  {    identifier = id;    parentNode = theParentNode;    type = aType;  }  /**   * Returns the name of the node   */  public String getIdentifier()  {    return identifier;  }  public String getDisplayString()  {    return displayString;  }  /**   * Sets the displayString of the node   */  public void setDisplayString(String newDisplay)  {    displayString = newDisplay;    if (type == STATUS)    {      if (displayString.equals("Inactive"))      {        setAlarmed(true, this);      }      else      {        setAlarmed(false, this);      }    }  }  /**   * Return the display String so that the tree's cell renderer will display   * each node correctly.   */  public String toString()  {    return displayString;  }}/** * $RCSfile: SystemStatus.java,v $ *  * @author $Author: bko $, $Date: 2002/09/26 01:14:01 $ * @version $Revision: 1.14 $ */class SNMPCellRenderer extends DefaultTreeCellRenderer{  /**   */  public SNMPCellRenderer()  {    super();    setOpenIcon(SNMPApplet.blueball);    setClosedIcon(SNMPApplet.blueball);  }  /**   *    * @param tree   * @param value   * @param sel   * @param expanded   * @param leaf   * @param row   * @param hasFocus   *    * @return   */  public Component getTreeCellRendererComponent(JTree tree, Object value,           boolean sel, boolean expanded, boolean leaf, int row,           boolean hasFocus)  {    // value is a DefaultMutableTreeNode    boolean isAlarmed = false;    if (value instanceof DefaultMutableTreeNode)    {      isAlarmed =         ((OidNode) ((DefaultMutableTreeNode) value).getUserObject()).isAlarmed();    }    if (isAlarmed)    {      if (leaf)      {        setLeafIcon(SNMPApplet.redball);      }      else      {        setClosedIcon(SNMPApplet.redball);        setOpenIcon(SNMPApplet.redball);      }    }    else    {      setLeafIcon(SNMPApplet.blueball);      setClosedIcon(SNMPApplet.blueball);      setOpenIcon(SNMPApplet.blueball);    }    return super.getTreeCellRendererComponent(tree, value, sel, expanded,             leaf, row, hasFocus);  }}

⌨️ 快捷键说明

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