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

📄 annexmodemstatusbean.java

📁 snmp zip 包开发snmp协议
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    int ret = -1;    if (modemHash.contains(node))    {        boolean found = false;        Enumeration e = modemHash.elements();        while (e.hasMoreElements() && !found)        {            TreeNode n = (TreeNode) e.nextElement();            found = (n == node);             ret++;        }    }    return ret;}/** * Returns the parent <code>TreeNode</code> of the receiver. */public TreeNode getParent(){    return parent;}/** * Returns true if the receiver allows children. */public boolean getAllowsChildren(){    return true;}/** * Returns true if the receiver is a leaf. */public boolean isLeaf(){    return false;}/** * This method starts the action of the bean. It will initialises  * all variables before starting. */public void action(){    if (isHostPortReachable())    {        lastUpdateDate = new Date();        isGetNextInFlight = false;        setRunning(true);    }}/** * Implements the running of the bean. * * It will send the Pdu, if the previous one is not still in flight. * @see SNMPRunBean#isRunning() */public void run(){    while (context != null && isRunning())    {        if (isGetNextInFlight == false)        {            // start the GetNext loop again            isGetNextInFlight = true;            pduGetNext = new GetNextPdu_vec(context, NR_PORT_OID);            pduGetNext.addObserver(this);            pduGetNext.addOid(charPortIndex);            pduGetNext.addOid(charPortName);            pduGetNext.addOid(charPortOperStatus);            try            {                pduGetNext.send();            }            catch (PduException exc)            {                System.out.println("PduException " + exc.getMessage());            }            catch (IOException exc)            {                System.out.println("IOException " + exc.getMessage());            }        }        try        {            Thread.sleep(interval);        }         catch (InterruptedException ix)        {            ;        }    }}/** * This method is called when the Pdu response is received. When all * answers are received it will fire the property change event. * */public void update(Observable obs, Object ov){    boolean loopHasEnded = false;    if (obs instanceof GetNextPdu_vec)    {        int portIndex, portStatus;        String portName;        varbind [] var;        pduGetNext = (GetNextPdu_vec) obs;        if (pduGetNext.isTimedOut() == false)        {            if (pduGetNext.getErrorStatus() == AsnObject.SNMP_ERR_NOERROR)            {                var = (varbind []) ov;                if (var[0].getOid().toString().startsWith(charPortIndex))                {                    portIndex = ((AsnInteger)  var[0].getValue()).getValue();                    portName  = ((AsnOctets)   var[1].getValue()).getValue();                    portStatus = ((AsnInteger) var[2].getValue()).getValue();                    Long indexInt = new Long(portIndex);                    if (portStatus == portUP)                    {                        // I've found a port that has status up                        // Store it for later use.                        PortInfo pStatus =                                 (PortInfo) modemHash.get(indexInt);                        if (pStatus == null)                        {                            pStatus = new PortInfo(portIndex, portName, this);                            modemHash.put(indexInt, pStatus);                        }                        // Now I have to find out its sigState                        String oid = rs232InSigState + "." + String.valueOf(portIndex)                                     + "." + String.valueOf(DCD);                        try                        {                            GetPdu pduGet = new GetPdu(context);                            pduGet.addOid(oid);                            pduGet.addObserver(this);                            pduGet.send();                        }                        catch (PduException exc)                        {                            System.out.println("PduException " + exc.getMessage());                        }                        catch (IOException exc)                        {                            System.out.println("IOException " + exc.getMessage());                        }                    }                    else                    {                        // This port is not up, remove it from our info                        modemIndexStatusHash.remove(indexInt);                        modemHash.remove(indexInt);                    }                    // ask for the next modem                    pduGetNext = new GetNextPdu_vec(context, NR_PORT_OID);                    pduGetNext.addObserver(this);                    pduGetNext.addOid(var[0].getOid().toString());                    pduGetNext.addOid(var[1].getOid().toString());                    pduGetNext.addOid(var[2].getOid().toString());                    try                    {                        pduGetNext.send();                    }                    catch (PduException exc)                    {                        System.out.println("PduException " + exc.getMessage());                    }                    catch (IOException exc)                    {                        System.out.println("IOException " + exc.getMessage());                    }                }                else                {                    loopHasEnded = true;                }            }            else            {                // Actually the loop is ended when                // we have all the responses from pduGet's. Since I                // cannot control that, I do it this way.                loopHasEnded = true;            }        }        else        {            modemIndexStatusHash.clear();            modemHash.clear();            loopHasEnded = true;        }    }    else if (obs instanceof GetPdu)    {        GetPdu pduGet = (GetPdu) obs;        if (pduGet.getErrorStatus() == AsnObject.SNMP_ERR_NOERROR)        {            varbind var = (varbind) ov;            AsnObjectId oid = var.getOid();            int sigStatus = ((AsnInteger) var.getValue()).getValue();            // the index is the one-but-last element in the OID            int len = oid.getSize();            long portIndex = oid.getElementAt(len-2);            Long indexInt = new Long(portIndex);            modemIndexStatusHash.put(indexInt,                   new Integer(sigStatus));            PortInfo pStatus =                     (PortInfo) modemHash.get(indexInt);            if (pStatus != null)            {                pStatus.setStatus(sigStatus);            }        }    }    if (loopHasEnded)    {        lastUpdateDate = new Date();        javax.swing.SwingUtilities.invokeLater(new TreeUpdate());        isGetNextInFlight = false;    }}/** * Sets the parent for this TreeNode. If the parent is not set, this * class should be the root of the TreeModel. */public void setParent (TreeNode p){    parent = p;}/** * Sets the DefaultTreeModel for this TreeNode. The tree model is used * for notifying when any of the nodes were added, removed or changed. */public void setDefaultTreeModel (DefaultTreeModel model){    treeModel = model;}/** * Fire the property event. * * @see * javax.swing.tree.DefaultTreeModel#nodeStructureChanged */protected void fireTreeModelChanged(){    if (treeModel != null)    {        treeModel.nodeStructureChanged(this);    }}class PortInfo extends Object implements TreeNode{    private TreeNode    parent;    private int         portIndex, sigStatus;    private String      portName;public PortInfo(int ind, String nm, TreeNode par){    this(ind, 0, nm, par);}public PortInfo(int ind, int st, String nm, TreeNode par){    portIndex = ind;    sigStatus = st;    portName = nm;    parent = par;}public int getIndex(){    return portIndex;}public int getStatus(){    return sigStatus;}public void setStatus(int st){    sigStatus = st;}public String getName(){    return portName;}public String toString(){    return ""+portIndex + " " + portName + " " + sig_state[sigStatus];}/** * Returns the children of the reciever as an Enumeration. */public Enumeration children(){    return null;}/** * Returns the number of children <code>TreeNode</code>s the receiver * contains. */public int getChildCount(){    return 0;}/** * Returns the child <code>TreeNode</code> at index  * <code>childIndex</code>. */public TreeNode getChildAt(int childIndex){    return null;}/** * Returns the index of <code>node</code> in the receivers children. * If the receiver does not contain <code>node</code>, -1 will be * returned. */public int getIndex(TreeNode node){    return -1;}/** * Returns the parent <code>TreeNode</code> of the receiver. */public TreeNode getParent(){    return parent;}/** * Returns true if the receiver allows children. */public boolean getAllowsChildren(){    return true;}/** * Returns true if the receiver is a leaf. */public boolean isLeaf(){    return true;}} // end class PortInfoclass TreeUpdate implements Runnable{    public void run()    {        fireTreeModelChanged();        firePropertyChange("modems", null, null);    }}}

⌨️ 快捷键说明

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