Search in sources :

Example 51 with SnmpStatusException

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

the class SnmpAdaptorServer method sendTrapPdu.

/**
     * Send the specified trap PDU to every destinations from the ACL file.
     */
private void sendTrapPdu(SnmpPduPacket pdu) throws SnmpStatusException, IOException {
    // Make an SNMP message from the pdu
    //
    SnmpMessage msg = null;
    try {
        msg = (SnmpMessage) pduFactory.encodeSnmpPdu(pdu, bufferSize);
        if (msg == null) {
            throw new SnmpStatusException(SnmpDefinitions.snmpRspAuthorizationError);
        }
    } catch (SnmpTooBigException x) {
        if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
            SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag, "sendTrapPdu", "Trap pdu is too big. " + "Trap hasn't been sent to anyone");
        }
        throw new SnmpStatusException(SnmpDefinitions.snmpRspTooBig);
    // FIXME: is the right exception to throw ?
    // We could simply forward SnmpTooBigException ?
    }
    // Now send the SNMP message to each destination
    //
    int sendingCount = 0;
    openTrapSocketIfNeeded();
    if (ipacl != null) {
        Enumeration<InetAddress> ed = ipacl.getTrapDestinations();
        while (ed.hasMoreElements()) {
            msg.address = ed.nextElement();
            Enumeration<String> ec = ipacl.getTrapCommunities(msg.address);
            while (ec.hasMoreElements()) {
                msg.community = ec.nextElement().getBytes();
                try {
                    sendTrapMessage(msg);
                    sendingCount++;
                } catch (SnmpTooBigException x) {
                    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                        SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag, "sendTrapPdu", "Trap pdu is too big. " + "Trap hasn't been sent to " + msg.address);
                    }
                }
            }
        }
    }
    //
    if (sendingCount == 0) {
        try {
            msg.address = InetAddress.getLocalHost();
            sendTrapMessage(msg);
        } catch (SnmpTooBigException x) {
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag, "sendTrapPdu", "Trap pdu is too big. " + "Trap hasn't been sent.");
            }
        } catch (UnknownHostException e) {
            if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINEST)) {
                SNMP_ADAPTOR_LOGGER.logp(Level.FINEST, dbgTag, "sendTrapPdu", "Trap pdu is too big. " + "Trap hasn't been sent.");
            }
        }
    }
    closeTrapSocketIfNeeded();
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) UnknownHostException(java.net.UnknownHostException) SnmpMessage(com.sun.jmx.snmp.SnmpMessage) SnmpTooBigException(com.sun.jmx.snmp.SnmpTooBigException) InetAddress(java.net.InetAddress)

Example 52 with SnmpStatusException

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

the class JvmMemMgrPoolRelTableMetaImpl method getNextOid.

// See com.sun.jmx.snmp.agent.SnmpMibTable
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) {
        //
        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 == null)
        throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
    return next;
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) SnmpOid(com.sun.jmx.snmp.SnmpOid) SnmpTableHandler(sun.management.snmp.util.SnmpTableHandler)

Example 53 with SnmpStatusException

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

the class JvmRTClassPathTableMetaImpl method getNextOid.

// See com.sun.jmx.snmp.agent.SnmpMibTable
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) {
        //
        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 == null)
        throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
    return next;
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) SnmpOid(com.sun.jmx.snmp.SnmpOid) SnmpTableHandler(sun.management.snmp.util.SnmpTableHandler)

Example 54 with SnmpStatusException

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

the class JvmRTClassPathTableMetaImpl method getEntry.

// See com.sun.jmx.snmp.agent.SnmpMibTable
public Object getEntry(SnmpOid oid) throws SnmpStatusException {
    final boolean dbg = log.isDebugOn();
    if (dbg)
        log.debug("getEntry", "oid [" + oid + "]");
    if (oid == null || oid.getLength() != 1) {
        if (dbg)
            log.debug("getEntry", "Invalid oid [" + oid + "]");
        throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
    }
    // Get the request contextual cache (userData).
    //
    final Map<Object, Object> m = JvmContextFactory.getUserData();
    // We're going to use this name to store/retrieve the entry in
    // the request contextual cache.
    //
    // Revisit: Probably better programming to put all these strings
    //          in some interface.
    //
    final String entryTag = ((m == null) ? null : ("JvmRTClassPathTable.entry." + oid.toString()));
    //
    if (m != null) {
        final Object entry = m.get(entryTag);
        if (entry != null) {
            if (dbg)
                log.debug("getEntry", "Entry is already in the cache");
            return entry;
        } else if (dbg)
            log.debug("getEntry", "Entry is not in the cache");
    }
    // The entry was not in the cache, make a new one.
    //
    // Get the data hanler.
    //
    SnmpTableHandler handler = getHandler(m);
    //
    if (handler == null)
        throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
    // Get the data associated with our entry.
    //
    final Object data = handler.getData(oid);
    //
    if (data == null)
        throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
    //
    if (dbg)
        log.debug("getEntry", "data is a: " + data.getClass().getName());
    final Object entry = new JvmRTClassPathEntryImpl((String) data, (int) oid.getOidArc(0));
    //
    if (m != null && entry != null) {
        m.put(entryTag, entry);
    }
    return entry;
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) SnmpTableHandler(sun.management.snmp.util.SnmpTableHandler) SnmpString(com.sun.jmx.snmp.SnmpString)

Example 55 with SnmpStatusException

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

the class JvmMemManagerTableMetaImpl method getEntry.

// See com.sun.jmx.snmp.agent.SnmpMibTable
public Object getEntry(SnmpOid oid) throws SnmpStatusException {
    if (oid == null)
        throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
    // Get the request contextual cache (userData).
    //
    final Map<Object, Object> m = JvmContextFactory.getUserData();
    // We know in the case of this table that the index is an integer,
    // it is thus the first OID arc of the index OID.
    //
    final long index = oid.getOidArc(0);
    // We're going to use this name to store/retrieve the entry in
    // the request contextual cache.
    //
    // Revisit: Probably better programming to put all these strings
    //          in some interface.
    //
    final String entryTag = ((m == null) ? null : ("JvmMemManagerTable.entry." + index));
    //
    if (m != null) {
        final Object entry = m.get(entryTag);
        if (entry != null)
            return entry;
    }
    // The entry was not in the cache, make a new one.
    //
    // Get the data hanler.
    //
    SnmpTableHandler handler = getHandler(m);
    //
    if (handler == null)
        throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
    // Get the data associated with our entry.
    //
    final Object data = handler.getData(oid);
    //
    if (data == null)
        throw new SnmpStatusException(SnmpStatusException.noSuchInstance);
    // make the new entry (transient object that will be kept only
    // for the duration of the request.
    //
    final Object entry = new JvmMemManagerEntryImpl((MemoryManagerMXBean) data, (int) index);
    //
    if (m != null && entry != null) {
        m.put(entryTag, entry);
    }
    return entry;
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) SnmpTableHandler(sun.management.snmp.util.SnmpTableHandler)

Aggregations

SnmpStatusException (com.sun.jmx.snmp.SnmpStatusException)64 SnmpVarBind (com.sun.jmx.snmp.SnmpVarBind)18 SnmpTableHandler (sun.management.snmp.util.SnmpTableHandler)18 SnmpOid (com.sun.jmx.snmp.SnmpOid)15 SnmpMessage (com.sun.jmx.snmp.SnmpMessage)5 SnmpTooBigException (com.sun.jmx.snmp.SnmpTooBigException)5 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)5 InstanceNotFoundException (javax.management.InstanceNotFoundException)5 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)5 MBeanException (javax.management.MBeanException)5 MBeanRegistrationException (javax.management.MBeanRegistrationException)5 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)5 ReflectionException (javax.management.ReflectionException)5 RuntimeOperationsException (javax.management.RuntimeOperationsException)5 SnmpString (com.sun.jmx.snmp.SnmpString)4 BerDecoder (com.sun.jmx.snmp.BerDecoder)3 BerException (com.sun.jmx.snmp.BerException)3 Attribute (javax.management.Attribute)3 SnmpPduPacket (com.sun.jmx.snmp.SnmpPduPacket)2 SnmpScopedPduPacket (com.sun.jmx.snmp.SnmpScopedPduPacket)2