jdk/src/share/classes/com/sun/jmx/snmp/agent/SnmpMibNode.java
author darcy
Wed, 02 Apr 2014 21:38:45 -0700
changeset 23711 95fb268275e3
parent 22331 f65a493da643
permissions -rw-r--r--
8039022: Fix serial lint warnings in sun.tools.java 8039027: Fix serial lint warnings in jconsole and jstat 8039038: Fix serial lint warnings in com.sun.jmx.snmp Reviewed-by: alanb, lancea, dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23711
95fb268275e3 8039022: Fix serial lint warnings in sun.tools.java
darcy
parents: 22331
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package com.sun.jmx.snmp.agent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
// java imports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
// jmx imports
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
//
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import com.sun.jmx.snmp.SnmpOid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import com.sun.jmx.snmp.SnmpValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import com.sun.jmx.snmp.SnmpVarBind;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import com.sun.jmx.snmp.SnmpDefinitions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import com.sun.jmx.snmp.SnmpStatusException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * The <CODE>SnmpMibNode</CODE> class represents a node in an SNMP MIB.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * This class is used internally and by the class generated by
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * <CODE>mibgen</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * You should not need to use this class directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <p><b>This API is a Sun Microsystems internal API  and is subject
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * to change without notice.</b></p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 */
23711
95fb268275e3 8039022: Fix serial lint warnings in sun.tools.java
darcy
parents: 22331
diff changeset
    56
@SuppressWarnings("serial") // JDK implementation class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
public abstract class SnmpMibNode implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    // ---------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    // PUBLIC METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    //----------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * Get the next OID arc corresponding to a readable scalar variable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * a branch leading to a subgroub, or a table.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * @param id Id we start from looking for the next.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * @param userData A contextual object containing user-data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     *        This object is allocated through the <code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     *        {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory}</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     *        for each incoming SNMP request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @return The next id in this group.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @exception SnmpStatusException If no id is found after the given id.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public long getNextVarId(long id, Object userData)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        return getNextIdentifier(varList,id);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * Get the next OID arc corresponding to a readable scalar variable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * a branch leading to a subgroub, or a table, possibly skipping over
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * those arcs that must not or cannot be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * Calls {@link #getNextVarId(long,java.lang.Object)} until
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * {@link #skipVariable(long,java.lang.Object,int)} returns false.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @param id Id we start from looking for the next.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @param userData A contextual object containing user-data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *        This object is allocated through the <code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *        {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory}</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *        for each incoming SNMP request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @param pduVersion Protocol version of the original request PDU.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @return The next id in this group which can be returned using
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *         the given PDU's protocol version.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @exception SnmpStatusException If no id is found after the given id.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    public long getNextVarId(long id, Object userData, int pduVersion)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        long varid=id;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        do {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            varid = getNextVarId(varid,userData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        } while (skipVariable(varid,userData,pduVersion));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        return varid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Hook for subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * The default implementation of this method is to always return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * false. Subclasses should redefine this method so that it returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * true when:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * <ul><li>the variable is a leaf that is not instantiated,</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * <li>or the variable is a leaf whose type cannot be returned by that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     *     version of the protocol (e.g. an Counter64 with SNMPv1).</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @param id Id we start from looking for the next.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @param userData A contextual object containing user-data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     *        This object is allocated through the <code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *        {@link com.sun.jmx.snmp.agent.SnmpUserDataFactory}</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     *        for each incoming SNMP request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * @param pduVersion Protocol version of the original request PDU.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @return true if the variable must be skipped by the get-next
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     *         algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    protected boolean skipVariable(long id, Object userData, int pduVersion) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Find the node which handles a varbind, and register it in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * SnmpRequestTree. This method is a pure internal method. You should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * never try to call it directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @param varbind  The varbind to be handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @param oid      The OID array extracted from the varbind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * @param depth    The depth reached in the OID at this step of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     *                 processing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @param handlers The Hashtable in which the varbind will be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *                 with its handling node. This hashtable contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *                 <CODE>SnmpRequestTree.Handler</CODE> items.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @exception SnmpStatusException No handling node was found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    void findHandlingNode(SnmpVarBind varbind,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                          long[] oid, int depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                          SnmpRequestTree handlers)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        throws SnmpStatusException {
22331
f65a493da643 7068126: Enhance SNMP statuses
sjiang
parents: 5506
diff changeset
   158
        throw new SnmpStatusException(SnmpStatusException.noSuchObject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * Find the node which handles the leaf that immediately follows the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * given varbind OID, and register the it in the SnmpRequestTree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * This method is a pure internal method. You should never try to call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * it directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * @param varbind  The varbind to be handled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @param oid      The OID array extracted from the varbind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * @param depth    The depth reached in the OID at this step of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *                 processing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @param handlers The Hashtable in which the varbind will be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *                 with its handling node. This hashtable contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *                 SnmpRequestTree.Handler items.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @return The SnmpOid of the next leaf.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * @exception SnmpStatusException No handling node was found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    long[] findNextHandlingNode(SnmpVarBind varbind,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                                 long[] oid, int pos, int depth,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                 SnmpRequestTree handlers, AcmChecker checker)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        throws SnmpStatusException {
22331
f65a493da643 7068126: Enhance SNMP statuses
sjiang
parents: 5506
diff changeset
   186
        throw new SnmpStatusException(SnmpStatusException.noSuchObject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Generic handling of the <CODE>get</CODE> operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * <p> You can override this method if you need to implement some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * specific policies for minimizing the accesses made to some remote
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * underlying resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @param req   The sub-request that must be handled by this node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * @param depth The depth reached in the OID tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @exception SnmpStatusException An error occurred while accessing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *  the MIB node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    public abstract void get(SnmpMibSubRequest req, int depth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        throws SnmpStatusException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Generic handling of the <CODE>set</CODE> operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * <p> You can override this method if you need to implement some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * specific policies for minimizing the accesses made to some remote
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * underlying resources.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @param req   The sub-request that must be handled by this node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @param depth The depth reached in the OID tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @exception SnmpStatusException An error occurred while accessing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *  the MIB node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    public abstract void set(SnmpMibSubRequest req, int depth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        throws SnmpStatusException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Generic handling of the <CODE>check</CODE> operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * <p> You can override this method if you need to implement some
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * specific policies for minimizing the accesses made to some remote
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * underlying resources, or if you need to implement some consistency
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * checks between the different values provided in the varbind list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @param req   The sub-request that must be handled by this node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @param depth The depth reached in the OID tree.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @exception SnmpStatusException An error occurred while accessing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *  the MIB node.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    public abstract void check(SnmpMibSubRequest req, int depth)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        throws SnmpStatusException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * Sorts the specified integer array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @param array An integer array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    static public void sort(int array[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        QuickSort(array, 0, array.length - 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * Computes the root OID of the MIB.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public void getRootOid(Vector<Integer> result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    //----------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    // PACKAGE METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
    //----------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * This is a generic version of C.A.R Hoare's Quick Sort
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * algorithm.  This will handle arrays that are already
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * sorted, and arrays with duplicate keys.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * If you think of a one dimensional array as going from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * the lowest index on the left to the highest index on the right
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * then the parameters to this function are lowest index or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * left and highest index or right.  The first time you call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * this function it will be with the parameters 0, a.length - 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @param a An integer array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @param lo0 Left boundary of array partition.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @param hi0 Right boundary of array partition.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    static void QuickSort(int a[], int lo0, int hi0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        int lo = lo0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        int hi = hi0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        int mid;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        if ( hi0 > lo0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            /* Arbitrarily establishing partition element as the midpoint of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
             * the array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            mid = a[ ( lo0 + hi0 ) / 2 ];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            // loop through the array until indices cross
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            while( lo <= hi ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                /* find the first element that is greater than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                 * the partition element starting from the left Index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                while( ( lo < hi0 )  && ( a[lo] < mid ))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                    ++lo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                /* find an element that is smaller than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                 * the partition element starting from the right Index.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                while( ( hi > lo0 ) && ( a[hi] > mid ))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                    --hi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                // if the indexes have not crossed, swap
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                if( lo <= hi ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                    swap(a, lo, hi);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                    ++lo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                    --hi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
            /* If the right index has not reached the left side of array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
             * must now sort the left partition.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            if( lo0 < hi )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                QuickSort( a, lo0, hi );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            /* If the left index has not reached the right side of array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
             * must now sort the right partition.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            if( lo < hi0 )
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                QuickSort( a, lo, hi0 );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    //----------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    // PROTECTED METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    //----------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * This will give the first element greater than <CODE>value</CODE>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * in a sorted array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * If there is no element of the array greater than <CODE>value</CODE>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * the method will throw a <CODE>SnmpStatusException</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @param table A sorted integer array.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @param value The greatest value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * @exception SnmpStatusException If there is no element greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     *     <CODE>value</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    final static protected int getNextIdentifier(int table[], long value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        throws SnmpStatusException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        final int[] a = table;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        final int val= (int) value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
22331
f65a493da643 7068126: Enhance SNMP statuses
sjiang
parents: 5506
diff changeset
   349
        if (a == null) {
f65a493da643 7068126: Enhance SNMP statuses
sjiang
parents: 5506
diff changeset
   350
            throw new SnmpStatusException(SnmpStatusException.noSuchObject);
f65a493da643 7068126: Enhance SNMP statuses
sjiang
parents: 5506
diff changeset
   351
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        int low= 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        int max= a.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        int curr= low + (max-low)/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        int elmt= 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        // Basic check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        //
22331
f65a493da643 7068126: Enhance SNMP statuses
sjiang
parents: 5506
diff changeset
   360
        if (max < 1) {
f65a493da643 7068126: Enhance SNMP statuses
sjiang
parents: 5506
diff changeset
   361
            throw new SnmpStatusException(SnmpStatusException.noSuchObject);
f65a493da643 7068126: Enhance SNMP statuses
sjiang
parents: 5506
diff changeset
   362
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
22331
f65a493da643 7068126: Enhance SNMP statuses
sjiang
parents: 5506
diff changeset
   364
        if (a[max-1] <= val) {
f65a493da643 7068126: Enhance SNMP statuses
sjiang
parents: 5506
diff changeset
   365
            throw new SnmpStatusException(SnmpStatusException.noSuchObject);
f65a493da643 7068126: Enhance SNMP statuses
sjiang
parents: 5506
diff changeset
   366
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        while (low <= max) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            elmt= a[curr];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            if (val == elmt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                // We ned to get the next index ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                curr++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                return a[curr];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            if (elmt < val) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                low= curr +1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                max= curr -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            curr= low + (max-low)/2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        return a[curr];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    //----------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
    // PRIVATE METHODS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    //----------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    final static private void swap(int a[], int i, int j) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        int T;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        T = a[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        a[i] = a[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        a[j] = T;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    //----------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    // PROTECTED VARIABLES
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    //----------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * Contains the list of variable identifiers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    protected int[] varList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
}