com.sun.jmx.snmp.SnmpOid Java Examples

The following examples show how to use com.sun.jmx.snmp.SnmpOid. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AcmChecker.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
void checkCurrentOid() throws SnmpStatusException {
    if(model != null) {
        SnmpOid oid = new SnmpOid(l.toArray());
        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
            SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, SnmpMib.class.getName(),
                    "checkCurrentOid", "Checking access for : " + oid);
        }
        model.checkAccess(version,
                          principal,
                          securityLevel,
                          pduType,
                          securityModel,
                          contextName,
                          oid);
    }
}
 
Example #2
Source File: SnmpNamedListTableCache.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Update cahed datas.
 * Obtains a {@link List} of raw datas by calling
 * {@link #getRawDatas(Map,String) getRawDatas((Map)context,getRawDatasKey())}.<br>
 * Then allocate a new {@link TreeMap} to serve as temporary map between
 * names and indexes, and call {@link #updateCachedDatas(Object,List)}
 * with that temporary map as context.<br>
 * Finally replaces the {@link #names} TreeMap by the temporary
 * TreeMap.
 * @param context The request contextual cache allocated by the
 *        {@link JvmContextFactory}.
 **/
protected SnmpCachedData updateCachedDatas(Object context) {

    final Map<Object, Object> userData =
        (context instanceof Map)?Util.<Map<Object, Object>>cast(context):null;

    // Look for memory manager list in request contextual cache.
    final List<?> rawDatas = getRawDatas(userData,getRawDatasKey());

    log.debug("updateCachedDatas","rawDatas.size()=" +
          ((rawDatas==null)?"<no data>":""+rawDatas.size()));

    TreeMap<String,SnmpOid> ctxt = new TreeMap<>();
    final SnmpCachedData result =
        super.updateCachedDatas(ctxt,rawDatas);
    names = ctxt;
    return result;
}
 
Example #3
Source File: JvmRTClassPathTableMetaImpl.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return a table handler containing the Thread indexes.
 * Indexes are computed from the ThreadId.
 **/
protected SnmpCachedData updateCachedDatas(Object userData) {


    // We are getting all the input args
    final String[] path =
        JvmRuntimeImpl.getClassPath(userData);

    // Time stamp for the cache
    final long time = System.currentTimeMillis();
    final int len = path.length;

    SnmpOid indexes[] = new SnmpOid[len];

    for(int i = 0; i < len; i++) {
        indexes[i] = new SnmpOid(i + 1);
    }

    return new SnmpCachedData(time, indexes, path);
}
 
Example #4
Source File: JvmRTBootClassPathTableMetaImpl.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return a table handler containing the Thread indexes.
 * Indexes are computed from the ThreadId.
 **/
protected SnmpCachedData updateCachedDatas(Object userData) {


    // We are getting all the input args
    final String[] path =
        JvmRuntimeImpl.getBootClassPath(userData);

    // Time stamp for the cache
    final long time = System.currentTimeMillis();
    final int len = path.length;

    SnmpOid indexes[] = new SnmpOid[len];

    for(int i = 0; i < len; i++) {
        indexes[i] = new SnmpOid(i + 1);
    }

    return new SnmpCachedData(time, indexes, path);
}
 
Example #5
Source File: SnmpAdaptorServer.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sends a trap using SNMP V1 trap format.
 * <BR>The trap is sent to the specified <CODE>SnmpPeer</CODE> destination.
 * The community string used is the one located in the
 * <CODE>SnmpPeer</CODE> parameters
 * (<CODE>SnmpParameters.getRdCommunity() </CODE>).
 *
 * @param peer The <CODE>SnmpPeer</CODE> destination of the trap.
 * @param agentAddr The agent address to be used for the trap.
 * @param enterpOid The enterprise OID to be used for the trap.
 * @param generic The generic number of the trap.
 * @param specific The specific number of the trap.
 * @param varBindList A list of <CODE>SnmpVarBind</CODE> instances or null.
 * @param time The time stamp (overwrite the current time).
 *
 * @exception IOException An I/O error occurred while sending the trap.
 * @exception SnmpStatusException If the trap exceeds the limit
 * defined by <CODE>bufferSize</CODE>.
 *
 * @since 1.5
 */
@Override
public void snmpV1Trap(SnmpPeer peer,
                       SnmpIpAddress agentAddr,
                       SnmpOid enterpOid,
                       int generic,
                       int specific,
                       SnmpVarBindList varBindList,
                       SnmpTimeticks time)
    throws IOException, SnmpStatusException {

    SnmpParameters p = (SnmpParameters) peer.getParams();
    snmpV1Trap(peer.getDestAddr(),
               peer.getDestPort(),
               agentAddr,
               p.getRdCommunity(),
               enterpOid,
               generic,
               specific,
               varBindList,
               time);
}
 
Example #6
Source File: JvmThreadInstanceTableMetaImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
protected boolean contains(SnmpOid oid, Object userData) {

        // Get the handler.
        //
        SnmpTableHandler handler = getHandler(userData);

        // handler should never be null.
        //
        if (handler == null)
            return false;
        if(!handler.contains(oid))
            return false;

        JvmThreadInstanceEntryImpl inst = getJvmThreadInstance(userData, oid);
        return (inst != null);
    }
 
Example #7
Source File: JvmRTClassPathTableMetaImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Return a table handler containing the Thread indexes.
 * Indexes are computed from the ThreadId.
 **/
protected SnmpCachedData updateCachedDatas(Object userData) {


    // We are getting all the input args
    final String[] path =
        JvmRuntimeImpl.getClassPath(userData);

    // Time stamp for the cache
    final long time = System.currentTimeMillis();
    final int len = path.length;

    SnmpOid indexes[] = new SnmpOid[len];

    for(int i = 0; i < len; i++) {
        indexes[i] = new SnmpOid(i + 1);
    }

    return new SnmpCachedData(time, indexes, path);
}
 
Example #8
Source File: SnmpMibAgent.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Sets the reference to the SNMP protocol adaptor through which the MIB
 * will be SNMP accessible and add this new MIB in the SNMP MIB handler.
 * This method is to be called to set a specific agent to a specific OID. This can be useful when dealing with MIB overlapping.
 * Some OID can be implemented in more than one MIB. In this case, the OID nearest the agent will be used on SNMP operations.
 * @param stack The SNMP MIB handler.
 * @param oids The set of OIDs this agent implements.
 *
 * @since 1.5
 */
@Override
public void setSnmpAdaptor(SnmpMibHandler stack, SnmpOid[] oids) {
    if (adaptor != null) {
        adaptor.removeMib(this);
    }
    adaptor = stack;
    if (adaptor != null) {
        adaptor.addMib(this, oids);
    }
}
 
Example #9
Source File: JvmMemMgrPoolRelTableMetaImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected void updateTreeMap(TreeMap<SnmpOid, Object> table, Object userData,
                             SnmpCachedData mmHandler,
                             SnmpTableHandler mpHandler,
                             Map<String, SnmpOid> poolIndexMap) {

    final SnmpOid[] indexes = mmHandler.indexes;
    final Object[]  datas   = mmHandler.datas;
    final int size = indexes.length;
    for (int i=size-1; i>-1; i--) {
        final MemoryManagerMXBean mmm =
            (MemoryManagerMXBean)datas[i];
        if (mmm == null) continue;
        updateTreeMap(table,userData,mmm,indexes[i],poolIndexMap);
    }
}
 
Example #10
Source File: SnmpLoadedClassData.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public final Object getData(SnmpOid index) {
    int pos = 0;

    try {
        pos = (int) index.getOidArc(0);
    }catch(SnmpStatusException e) {
        return null;
    }

    if (pos >= datas.length) return null;
    return datas[pos];
}
 
Example #11
Source File: JvmRTBootClassPathTableMeta.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void check(SnmpMibSubRequest req, SnmpOid rowOid, int depth)
    throws SnmpStatusException {
    if (req.getSize() == 0) return;

    JvmRTBootClassPathEntryMBean entry = (JvmRTBootClassPathEntryMBean) getEntry(rowOid);
    synchronized (this) {
        node.setInstance(entry);
        node.check(req,depth);
    }
}
 
Example #12
Source File: JvmMemManagerTableMetaImpl.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
protected SnmpOid getNextOid(SnmpOid oid, Object userData)
    throws SnmpStatusException {
    final boolean dbg = log.isDebugOn();
    if (dbg) log.debug("getNextOid", "previous=" + oid);


    // Get the data handler.
    //
    SnmpTableHandler handler = getHandler(userData);
    if (handler == null) {
        // This should never happen.
        // If we get here it's a bug.
        //
        if (dbg) log.debug("getNextOid", "handler is null!");
        throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
    }

    // Get the next oid
    //
    final SnmpOid next = handler.getNext(oid);
    if (dbg) log.debug("getNextOid", "next=" + next);

    // if next is null: we reached the end of the table.
    //
    if (next == null)
        throw new SnmpStatusException(SnmpStatusException.noSuchInstance);

    return next;
}
 
Example #13
Source File: JvmThreadInstanceTableMetaImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
protected SnmpOid getNextOid(SnmpOid oid, Object userData)
    throws SnmpStatusException {
    log.debug("getNextOid", "previous=" + oid);


    // Get the data handler.
    //
    SnmpTableHandler handler = getHandler(userData);
    if (handler == null) {
        // This should never happen.
        // If we get here it's a bug.
        //
        log.debug("getNextOid", "handler is null!");
        throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
    }

    // Get the next oid
    //
    SnmpOid next = oid;
    while(true) {
        next = handler.getNext(next);
        if (next == null) break;
        if (getJvmThreadInstance(userData,next) != null) break;
    }

    log.debug("*** **** **** **** getNextOid", "next=" + next);

    // if next is null: we reached the end of the table.
    //
    if (next == null)
        throw new SnmpStatusException(SnmpStatusException.noSuchInstance);

    return next;
}
 
Example #14
Source File: JvmRTClassPathTableMeta.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public synchronized void addEntry(SnmpOid rowOid, ObjectName objname,
             Object entry)
    throws SnmpStatusException {
    if (! (entry instanceof JvmRTClassPathEntryMBean) )
        throw new ClassCastException("Entries for Table \"" +
                       "JvmRTClassPathTable" + "\" must implement the \"" +
                       "JvmRTClassPathEntryMBean" + "\" interface.");
    super.addEntry(rowOid, objname, entry);
}
 
Example #15
Source File: SnmpRequestTree.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static int findOid(SnmpOid[] oids, int count, SnmpOid oid) {
    final int size = count;
    int low= 0;
    int max= size - 1;
    int curr= low + (max-low)/2;
    //System.out.println("Try to retrieve: " + oid.toString());
    while (low <= max) {

        final SnmpOid pos = oids[curr];

        //System.out.println("Compare with" + pos.toString());
        // never know ...we might find something ...
        //
        final int comp = oid.compareTo(pos);
        if (comp == 0)
            return curr;

        if (oid.equals(pos)) {
            return curr;
        }
        if (comp > 0) {
            low = curr + 1;
        } else {
            max = curr - 1;
        }
        curr = low + (max-low)/2;
    }
    return -1;
}
 
Example #16
Source File: JvmThreadInstanceTableMetaImpl.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public Object getEntry(SnmpOid oid)
    throws SnmpStatusException {
    log.debug("*** **** **** **** getEntry", "oid [" + oid + "]");
    if (oid == null || oid.getLength() != 8) {
        log.debug("getEntry", "Invalid oid [" + oid + "]");
        throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
    }

    // Get the request contextual cache (userData).
    //
    final Map<Object,Object> m = JvmContextFactory.getUserData();

    // Get the handler.
    //
    SnmpTableHandler handler = getHandler(m);

    // handler should never be null.
    //
    if (handler == null || !handler.contains(oid))
        throw new SnmpStatusException(SnmpStatusException.noSuchInstance);

    final JvmThreadInstanceEntryImpl entry = getJvmThreadInstance(m,oid);

    if (entry == null)
        throw new SnmpStatusException(SnmpStatusException.noSuchInstance);

    return entry;
}
 
Example #17
Source File: JvmRTClassPathTableMeta.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void get(SnmpMibSubRequest req, SnmpOid rowOid, int depth)
    throws SnmpStatusException {
    JvmRTClassPathEntryMBean entry = (JvmRTClassPathEntryMBean) getEntry(rowOid);
    synchronized (this) {
        node.setInstance(entry);
        node.get(req,depth);
    }
}
 
Example #18
Source File: JvmMemManagerTableMeta.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void get(SnmpMibSubRequest req, SnmpOid rowOid, int depth)
    throws SnmpStatusException {
    JvmMemManagerEntryMBean entry = (JvmMemManagerEntryMBean) getEntry(rowOid);
    synchronized (this) {
        node.setInstance(entry);
        node.get(req,depth);
    }
}
 
Example #19
Source File: JvmRTLibraryPathTableMetaImpl.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected boolean contains(SnmpOid oid, Object userData) {

        // Get the handler.
        //
        SnmpTableHandler handler = getHandler(userData);

        // handler should never be null.
        //
        if (handler == null)
            return false;

        return handler.contains(oid);
    }
 
Example #20
Source File: SnmpRequestTree.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
SnmpMibSubRequest getSubRequest(Handler handler, SnmpOid oid) {
    if (handler == null) return null;
    final int pos = handler.getEntryPos(oid);
    if (pos == -1) return null;
    return new SnmpMibSubRequestImpl(request,
                                     handler.getEntrySubList(pos),
                                     handler.getEntryOid(pos),
                                     handler.isNewEntry(pos),
                                     getnextflag,
                                     handler.getRowStatusVarBind(pos));
}
 
Example #21
Source File: SnmpRequestTree.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public SnmpOid getEntryOid(int pos) {
    if (entryoids == null) return null;
    // if (pos == -1 || pos >= entryoids.size() ) return null;
    if (pos == -1 || pos >= entrycount ) return null;
    // return (SnmpOid) entryoids.get(pos);
    return entryoids[pos];
}
 
Example #22
Source File: JvmMemManagerTableMeta.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public synchronized void addEntry(SnmpOid rowOid, ObjectName objname,
             Object entry)
    throws SnmpStatusException {
    if (! (entry instanceof JvmMemManagerEntryMBean) )
        throw new ClassCastException("Entries for Table \"" +
                       "JvmMemManagerTable" + "\" must implement the \"" +
                       "JvmMemManagerEntryMBean" + "\" interface.");
    super.addEntry(rowOid, objname, entry);
}
 
Example #23
Source File: JvmMemManagerTableMeta.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void createNewEntry(SnmpMibSubRequest req, SnmpOid rowOid, int depth)
    throws SnmpStatusException {
    if (factory != null)
        factory.createNewEntry(req, rowOid, depth, this);
    else
        throw new SnmpStatusException(
            SnmpStatusException.snmpRspNoAccess);
}
 
Example #24
Source File: SnmpCachedData.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public  SnmpOid getNext(SnmpOid index) {
    if (index == null) {
        if (indexes.length>0) return indexes[0];
        else return null;
    }
    final int pos = find(index);
    if (pos > -1) {
        if (pos < (indexes.length -1) ) return indexes[pos+1];
        else return null;
    }
    final int insertion = -pos -1;
    if ((insertion > -1) && (insertion < indexes.length))
        return indexes[insertion];
    else return null;
}
 
Example #25
Source File: JvmRTLibraryPathTableMeta.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void check(SnmpMibSubRequest req, SnmpOid rowOid, int depth)
    throws SnmpStatusException {
    if (req.getSize() == 0) return;

    JvmRTLibraryPathEntryMBean entry = (JvmRTLibraryPathEntryMBean) getEntry(rowOid);
    synchronized (this) {
        node.setInstance(entry);
        node.check(req,depth);
    }
}
 
Example #26
Source File: JvmMemManagerTableMetaImpl.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected boolean contains(SnmpOid oid, Object userData) {

        // Get the handler.
        //
        SnmpTableHandler handler = getHandler(userData);

        // handler should never be null.
        //
        if (handler == null)
            return false;

        return handler.contains(oid);
    }
 
Example #27
Source File: JVM_MANAGEMENT_MIB_IMPL.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private synchronized void sendTrap(SnmpOid trap, SnmpVarBindList list) {
    final Iterator<NotificationTarget> iterator = notificationTargets.iterator();
    final SnmpAdaptorServer adaptor =
        (SnmpAdaptorServer) getSnmpAdaptor();

    if (adaptor == null) {
        log.error("sendTrap", "Cannot send trap: adaptor is null.");
        return;
    }

    if (!adaptor.isActive()) {
        log.config("sendTrap", "Adaptor is not active: trap not sent.");
        return;
    }

    while(iterator.hasNext()) {
        NotificationTarget target = null;
        try {
            target = iterator.next();
            SnmpPeer peer =
                new SnmpPeer(target.getAddress(), target.getPort());
            SnmpParameters p = new SnmpParameters();
            p.setRdCommunity(target.getCommunity());
            peer.setParams(p);
            log.debug("handleNotification", "Sending trap to " +
                      target.getAddress() + ":" + target.getPort());
            adaptor.snmpV2Trap(peer, trap, list, null);
        }catch(Exception e) {
            log.error("sendTrap",
                      "Exception occurred while sending trap to [" +
                      target + "]. Exception : " + e);
            log.debug("sendTrap",e);
        }
    }
}
 
Example #28
Source File: JvmRTBootClassPathTableMeta.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the arc of the next columnar object following "var".
 */
public long getNextVarEntryId( SnmpOid rowOid, long var, Object data )
    throws SnmpStatusException {
    long nextvar = node.getNextVarId(var, data);
    while (!isReadableEntryId(rowOid, nextvar, data))
        nextvar = node.getNextVarId(nextvar, data);
    return nextvar;
}
 
Example #29
Source File: JvmRTBootClassPathTableMeta.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the arc of the next columnar object following "var".
 */
public long getNextVarEntryId( SnmpOid rowOid, long var, Object data )
    throws SnmpStatusException {
    long nextvar = node.getNextVarId(var, data);
    while (!isReadableEntryId(rowOid, nextvar, data))
        nextvar = node.getNextVarId(nextvar, data);
    return nextvar;
}
 
Example #30
Source File: JvmMemGCTableMeta.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public boolean skipEntryVariable( SnmpOid rowOid, long var, Object data, int pduVersion) {
    try {
        JvmMemGCEntryMBean entry = (JvmMemGCEntryMBean) getEntry(rowOid);
        synchronized (this) {
            node.setInstance(entry);
            return node.skipVariable(var, data, pduVersion);
        }
    } catch (SnmpStatusException x) {
        return false;
    }
}