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

📄 dialogchannelstatusbean.java

📁 snmp zip 包开发snmp协议
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
public TreeNode getChildAt(int childIndex){    TreeNode node = null;    if (childIndex < channelHash.size())    {        Enumeration e = channelHash.elements();        for (int i=0; i<=childIndex; i++)        {            node = (TreeNode) e.nextElement();        }    }    return node;}/** * 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){    int ret = -1;    if (channelHash.contains(node))    {        boolean found = false;        Enumeration e = channelHash.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;            pdu = new GetNextPdu_vec(context, NR_OID);            pdu.addObserver(this);            pdu.addOid(dlgR4DeviceIndex);            pdu.addOid(dlgR4DeviceName);            pdu.addOid(dlgR4DeviceType);            pdu.addOid(dlgR4DeviceOpenCount);            pdu.addOid(dlgR4VoiceChannelStatus);            try            {                pdu.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 hasEnded = false;    int index;    varbind [] var;    pdu = (GetNextPdu_vec) obs;    if (pdu.isTimedOut() == false)    {        if (pdu.getErrorStatus() == AsnObject.SNMP_ERR_NOERROR)        {            var = (varbind []) ov;            if (var[0].getOid().toString().startsWith(dlgR4DeviceIndex))            {                index        = ((AsnInteger) var[0].getValue()).getValue();                deviceName   = ((AsnOctets)  var[1].getValue()).getValue();                deviceType   = ((AsnInteger) var[2].getValue()).getValue();                openCount    = ((AsnInteger) var[3].getValue()).getValue();                channelStatus = ((AsnInteger) var[4].getValue()).getValue();                if (deviceType == voice)                {                    Integer indexInt = new Integer(index);                    if (openCount == 0)                    {                        channelIndexStatusHash.remove(indexInt);                        channelHash.remove(indexInt);                    }                    else                    {                        channelIndexStatusHash.put(indexInt,                               new Integer(channelStatus));                        ChannelStatus cStatus =                                 (ChannelStatus) channelHash.get(indexInt);                        if (cStatus == null)                        {                            cStatus = new ChannelStatus(index, channelStatus,                                         deviceName, this);                            channelHash.put(indexInt, cStatus);                        }                        else                        {                            cStatus.setStatus(channelStatus);                        }                    }                }                // ask for the next channel                pdu = new GetNextPdu_vec(context, NR_OID);                pdu.addObserver(this);                pdu.addOid(var[0].getOid().toString());                pdu.addOid(var[1].getOid().toString());                pdu.addOid(var[2].getOid().toString());                pdu.addOid(var[3].getOid().toString());                pdu.addOid(var[4].getOid().toString());                try                {                    pdu.send();                }                catch (PduException exc)                {                    System.out.println("PduException " + exc.getMessage());                }                catch (IOException exc)                {                    System.out.println("IOException " + exc.getMessage());                }            }            else            {                hasEnded = true;            }        }        else        {            hasEnded = true;        }    }    else    {        channelIndexStatusHash.clear();        channelHash.clear();        hasEnded = true;    }    if (hasEnded)    {        // the GetNext loop has ended        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 ChannelStatus extends Object implements TreeNode{    private TreeNode    parent;    private int         index, status;    private String      name;public ChannelStatus(int ind, int st, String nm, TreeNode par){    index = ind;    status = st;    name = nm;    parent = par;}public int getIndex(){    return index;}public int getStatus(){    return status;}public void setStatus(int st){    status = st;}public String getName(){    return name;}public String toString(){    return ""+index + " " + name + " " + vch_status[status];}/** * 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 ChannelStatusclass TreeUpdate implements Runnable{    public void run()    {        fireTreeModelChanged();        firePropertyChange("modems", null, null);    }}}

⌨️ 快捷键说明

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