Search in sources :

Example 6 with SnmpOid

use of com.sun.jmx.snmp.SnmpOid in project jdk8u_jdk by JetBrains.

the class SnmpNamedListTableCache method getIndex.

/**
     * Call {@link #getKey(Object,List,int,Object)} in order to get
     * the item name. Then check whether an index was already allocated
     * for the entry by that name. If yes return it. Otherwise, call
     * {@link #makeIndex(Object,List,int,Object)} to compute a new
     * index for that entry.
     * Finally store the association between
     * the name and index in the context TreeMap.
     * @param context The context passed to
     *        {@link #updateCachedDatas(Object,List)}.
     *        It is expected to
     *        be an instance of  {@link TreeMap}.
     * @param rawDatas Raw table datas passed to
     *        {@link #updateCachedDatas(Object,List)}.
     * @param rank Rank of the given <var>item</var> in the
     *        <var>rawDatas</var> list iterator.
     * @param item The raw data object for which an index must be determined.
     **/
protected SnmpOid getIndex(Object context, List<?> rawDatas, int rank, Object item) {
    final String key = getKey(context, rawDatas, rank, item);
    final Object index = (names == null || key == null) ? null : names.get(key);
    final SnmpOid result = ((index != null) ? ((SnmpOid) index) : makeIndex(context, rawDatas, rank, item));
    if ((context != null) && (key != null) && (result != null)) {
        Map<Object, Object> map = Util.cast(context);
        map.put(key, result);
    }
    log.debug("getIndex", "key=" + key + ", index=" + result);
    return result;
}
Also used : SnmpOid(com.sun.jmx.snmp.SnmpOid)

Example 7 with SnmpOid

use of com.sun.jmx.snmp.SnmpOid in project jdk8u_jdk by JetBrains.

the class SnmpNamedListTableCache method makeIndex.

/**
     * Find a new index for the entry corresponding to the
     * given <var>item</var>.
     * <br>This method is called by {@link #getIndex(Object,List,int,Object)}
     * when a new index needs to be allocated for an <var>item</var>. The
     * index returned must not be already in used.
     * @param context The context passed to
     *        {@link #updateCachedDatas(Object,List)}.
     * @param rawDatas Raw table datas passed to
     *        {@link #updateCachedDatas(Object,List)}.
     * @param rank Rank of the given <var>item</var> in the
     *        <var>rawDatas</var> list iterator.
     * @param item The raw data object for which an index must be determined.
     **/
protected SnmpOid makeIndex(Object context, List<?> rawDatas, int rank, Object item) {
    // check we are in the limits of an unsigned32.
    if (++last > 0x00000000FFFFFFFFL) {
        // we just wrapped.
        log.debug("makeIndex", "Index wrapping...");
        last = 0;
        wrapped = true;
    }
    // If we never wrapped, we can safely return last as new index.
    if (!wrapped)
        return new SnmpOid(last);
    // We wrapped. We must look for an unused index.
    for (int i = 1; i < 0x00000000FFFFFFFFL; i++) {
        if (++last > 0x00000000FFFFFFFFL)
            last = 1;
        final SnmpOid testOid = new SnmpOid(last);
        // Was this index already in use?
        if (names == null)
            return testOid;
        if (names.containsValue(testOid))
            continue;
        // Have we just used it in a previous iteration?
        if (context == null)
            return testOid;
        if (((Map) context).containsValue(testOid))
            continue;
        // Ok, not in use.
        return testOid;
    }
    // better to return null and log an error.
    return null;
}
Also used : SnmpOid(com.sun.jmx.snmp.SnmpOid) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 8 with SnmpOid

use of com.sun.jmx.snmp.SnmpOid in project jdk8u_jdk by JetBrains.

the class SnmpSubBulkRequestHandler method findVarBind.

/**
     * The method updates find out which element to use at update time. Handle oid overlapping as well
     */
private SnmpVarBind findVarBind(SnmpVarBind element, SnmpVarBind result) {
    if (element == null)
        return null;
    if (result.oid == null) {
        return element;
    }
    if (element.value == SnmpVarBind.endOfMibView)
        return result;
    if (result.value == SnmpVarBind.endOfMibView)
        return element;
    final SnmpValue val = result.value;
    int comp = element.oid.compareTo(result.oid);
    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "findVarBind", "Comparing OID element : " + element.oid + " with result : " + result.oid);
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "findVarBind", "Values element : " + element.value + " result : " + result.value);
    }
    if (comp < 0) {
        //
        return element;
    } else {
        if (comp == 0) {
            // Take the deeper within the reply
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "findVarBind", " oid overlapping. Oid : " + element.oid + "value :" + element.value);
                SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "findVarBind", "Already present varBind : " + result);
            }
            SnmpOid oid = result.oid;
            SnmpMibAgent deeperAgent = server.getAgentMib(oid);
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "findVarBind", "Deeper agent : " + deeperAgent);
            }
            if (deeperAgent == agent) {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "findVarBind", "The current agent is the deeper one. Update the value with the current one");
                }
                return element;
            } else {
                if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                    SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "findVarBind", "The current agent is not the deeper one. return the previous one.");
                }
                return result;
            }
        /*
                   Vector v = new Vector();
                   SnmpMibRequest getReq = createMibRequest(v,
                   version,
                   null);
                   SnmpVarBind realValue = new SnmpVarBind(oid);
                   getReq.addVarBind(realValue);
                   try {
                   deeperAgent.get(getReq);
                   } catch(SnmpStatusException e) {
                   e.printStackTrace();
                   }

                   if(isDebugOn())
                   trace("findVarBind", "Biggest priority value is : " +
                   realValue.value);

                   return realValue;
                */
        } else {
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
                SNMP_ADAPTOR_LOGGER.logp(Level.FINER, SnmpSubRequestHandler.class.getName(), "findVarBind", "The right varBind is the already present one");
            }
            return result;
        }
    }
}
Also used : SnmpOid(com.sun.jmx.snmp.SnmpOid) SnmpValue(com.sun.jmx.snmp.SnmpValue) SnmpMibAgent(com.sun.jmx.snmp.agent.SnmpMibAgent)

Example 9 with SnmpOid

use of com.sun.jmx.snmp.SnmpOid in project jdk8u_jdk by JetBrains.

the class SnmpTableSupport method removeEntry.

/**
     * Remove an entry from this table.
     *
     * This method unregisters an entry from the table and performs
     * synchronization with the associated table metadata object.
     *
     * @param index The SnmpIndex identifying the entry.
     * @param entry The entry that should be removed in the table. This
     *              parameter is optional and can be omitted if it doesn't
     *              need to be passed along to the
     *              <code>removeEntryCb()</code> callback defined in the
     *              {@link com.sun.jmx.snmp.agent.SnmpTableCallbackHandler}
     *              interface.
     *
     * @exception SnmpStatusException if the entry cannot be unregistered.
     **/
protected void removeEntry(SnmpIndex index, Object entry) throws SnmpStatusException {
    SnmpOid oid = buildOidFromIndex(index);
    meta.removeEntry(oid, entry);
}
Also used : SnmpOid(com.sun.jmx.snmp.SnmpOid)

Example 10 with SnmpOid

use of com.sun.jmx.snmp.SnmpOid in project jdk8u_jdk by JetBrains.

the class SnmpTableSupport method addEntry.

/**
     * Add an entry in this table.
     *
     * This method registers an entry in the table and performs
     * synchronization with the associated table metadata object.
     *
     * @param index The SnmpIndex built from the given entry.
     * @param name  The ObjectName with which this entry will be registered.
     * @param entry The entry that should be added in the table.
     *
     * @exception SnmpStatusException if the entry cannot be registered with
     *            the given index.
     **/
protected void addEntry(SnmpIndex index, ObjectName name, Object entry) throws SnmpStatusException {
    SnmpOid oid = buildOidFromIndex(index);
    meta.addEntry(oid, name, entry);
}
Also used : SnmpOid(com.sun.jmx.snmp.SnmpOid)

Aggregations

SnmpOid (com.sun.jmx.snmp.SnmpOid)37 SnmpStatusException (com.sun.jmx.snmp.SnmpStatusException)15 SnmpTableHandler (sun.management.snmp.util.SnmpTableHandler)9 SnmpVarBind (com.sun.jmx.snmp.SnmpVarBind)4 SnmpValue (com.sun.jmx.snmp.SnmpValue)3 SnmpMibAgent (com.sun.jmx.snmp.agent.SnmpMibAgent)2 TreeMap (java.util.TreeMap)2 ObjectName (javax.management.ObjectName)2 Date (java.util.Date)1 Map (java.util.Map)1