Search in sources :

Example 76 with InstanceNotFoundException

use of javax.management.InstanceNotFoundException in project jdk8u_jdk by JetBrains.

the class SnmpGenericObjectServer method set.

/**
     * Execute an SNMP SET request.
     *
     * <p>
     * This method first builds the list of attributes that need to be
     * set on the MBean and then calls setAttributes() on the
     * MBean server. Then it updates the SnmpMibSubRequest with the new
     * values retrieved from the MBean.
     * </p>
     *
     * <p>
     * The SNMP metadata information is obtained through the given
     * <code>meta</code> object, which usually is an instance of a
     * <code>mibgen</code> generated class.
     * </p>
     *
     * <p><b><i>
     * This method is called internally by <code>mibgen</code> generated
     * objects and you should never need to call it directly.
     * </i></b></p>
     *
     * @param meta  The metadata object impacted by the subrequest
     * @param name  The ObjectName of the MBean impacted by this subrequest
     * @param req   The SNMP subrequest to execute on the MBean
     * @param depth The depth of the SNMP object in the OID tree.
     *
     * @exception SnmpStatusException whenever an SNMP exception must be
     *      raised. Raising an exception will abort the request. <br>
     *      Exceptions should never be raised directly, but only by means of
     * <code>
     * req.registerGetException(<i>VariableId</i>,<i>SnmpStatusException</i>)
     * </code>
     **/
public void set(SnmpGenericMetaServer meta, ObjectName name, SnmpMibSubRequest req, int depth) throws SnmpStatusException {
    final int size = req.getSize();
    final AttributeList attList = new AttributeList(size);
    final String[] nameList = new String[size];
    final SnmpVarBind[] varList = new SnmpVarBind[size];
    final long[] idList = new long[size];
    int i = 0;
    for (Enumeration<SnmpVarBind> e = req.getElements(); e.hasMoreElements(); ) {
        final SnmpVarBind var = e.nextElement();
        try {
            final long id = var.oid.getOidArc(depth);
            final String attname = meta.getAttributeName(id);
            final Object attvalue = meta.buildAttributeValue(id, var.value);
            final Attribute att = new Attribute(attname, attvalue);
            attList.add(att);
            nameList[i] = attname;
            varList[i] = var;
            idList[i] = id;
            i++;
        } catch (SnmpStatusException x) {
            req.registerSetException(var, x);
        }
    }
    AttributeList result;
    int errorCode = SnmpStatusException.noAccess;
    try {
        result = server.setAttributes(name, attList);
    } catch (InstanceNotFoundException f) {
        result = new AttributeList();
        errorCode = SnmpStatusException.snmpRspInconsistentName;
    } catch (ReflectionException r) {
        errorCode = SnmpStatusException.snmpRspInconsistentName;
        result = new AttributeList();
    } catch (Exception x) {
        result = new AttributeList();
    }
    final Iterator<?> it = result.iterator();
    for (int j = 0; j < i; j++) {
        if (!it.hasNext()) {
            final SnmpStatusException x = new SnmpStatusException(errorCode);
            req.registerSetException(varList[j], x);
            continue;
        }
        final Attribute att = (Attribute) it.next();
        while ((j < i) && (!nameList[j].equals(att.getName()))) {
            final SnmpStatusException x = new SnmpStatusException(SnmpStatusException.noAccess);
            req.registerSetException(varList[j], x);
            j++;
        }
        if (j == i)
            break;
        try {
            varList[j].value = meta.buildSnmpValue(idList[j], att.getValue());
        } catch (SnmpStatusException x) {
            req.registerSetException(varList[j], x);
        }
    }
}
Also used : SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) ReflectionException(javax.management.ReflectionException) Attribute(javax.management.Attribute) AttributeList(javax.management.AttributeList) InstanceNotFoundException(javax.management.InstanceNotFoundException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) SnmpStatusException(com.sun.jmx.snmp.SnmpStatusException) MBeanRegistrationException(javax.management.MBeanRegistrationException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) RuntimeOperationsException(javax.management.RuntimeOperationsException) SnmpVarBind(com.sun.jmx.snmp.SnmpVarBind)

Example 77 with InstanceNotFoundException

use of javax.management.InstanceNotFoundException in project jdk8u_jdk by JetBrains.

the class SnmpMibAgent method setSnmpAdaptorName.

/**
     * 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
     * associated to the specified <CODE>name</CODE>.
     *
     * @param name The name of the SNMP protocol adaptor.
     * @param contextName The MIB context name. If null is passed, will be registered in the default context.
     * @exception InstanceNotFoundException The SNMP protocol adaptor does
     *     not exist in the MBean server.
     *
     * @exception ServiceNotFoundException This SNMP MIB is not registered
     *     in the MBean server or the requested service is not supported.
     *
     * @since 1.5
     */
@Override
public void setSnmpAdaptorName(ObjectName name, String contextName) throws InstanceNotFoundException, ServiceNotFoundException {
    if (server == null) {
        throw new ServiceNotFoundException(mibName + " is not registered in the MBean server");
    }
    //
    if (adaptor != null) {
        adaptor.removeMib(this, contextName);
    }
    // Then update the reference to the new adaptor server.
    //
    Object[] params = { this, contextName };
    String[] signature = { "com.sun.jmx.snmp.agent.SnmpMibAgent", "java.lang.String" };
    try {
        adaptor = (SnmpMibHandler) (server.invoke(name, "addMib", params, signature));
    } catch (InstanceNotFoundException e) {
        throw new InstanceNotFoundException(name.toString());
    } catch (ReflectionException e) {
        throw new ServiceNotFoundException(name.toString());
    } catch (MBeanException e) {
    // Should never occur...
    }
    adaptorName = name;
}
Also used : ReflectionException(javax.management.ReflectionException) ServiceNotFoundException(javax.management.ServiceNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException)

Example 78 with InstanceNotFoundException

use of javax.management.InstanceNotFoundException in project jdk8u_jdk by JetBrains.

the class SnmpMibAgent method setSnmpAdaptorName.

/**
     * 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
     * associated to the specified <CODE>name</CODE>.
     * 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 nearer agent will be used on SNMP operations.
     * @param name The name of the SNMP protocol adaptor.
     * @param oids The set of OIDs this agent implements.
     * @exception InstanceNotFoundException The SNMP protocol adaptor does
     *     not exist in the MBean server.
     *
     * @exception ServiceNotFoundException This SNMP MIB is not registered
     *     in the MBean server or the requested service is not supported.
     *
     * @since 1.5
     */
@Override
public void setSnmpAdaptorName(ObjectName name, SnmpOid[] oids) throws InstanceNotFoundException, ServiceNotFoundException {
    if (server == null) {
        throw new ServiceNotFoundException(mibName + " is not registered in the MBean server");
    }
    //
    if (adaptor != null) {
        adaptor.removeMib(this);
    }
    // Then update the reference to the new adaptor server.
    //
    Object[] params = { this, oids };
    String[] signature = { "com.sun.jmx.snmp.agent.SnmpMibAgent", oids.getClass().getName() };
    try {
        adaptor = (SnmpMibHandler) (server.invoke(name, "addMib", params, signature));
    } catch (InstanceNotFoundException e) {
        throw new InstanceNotFoundException(name.toString());
    } catch (ReflectionException e) {
        throw new ServiceNotFoundException(name.toString());
    } catch (MBeanException e) {
    // Should never occur...
    }
    adaptorName = name;
}
Also used : ReflectionException(javax.management.ReflectionException) ServiceNotFoundException(javax.management.ServiceNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException)

Example 79 with InstanceNotFoundException

use of javax.management.InstanceNotFoundException in project jdk8u_jdk by JetBrains.

the class SnmpMibAgent method setSnmpAdaptorName.

/**
     * 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
     * associated to the specified <CODE>name</CODE>.
     *
     * @param name The name of the SNMP protocol adaptor.
     * @param contextName The MIB context name. If null is passed, will be registered in the default context.
     * @param oids The set of OIDs this agent implements.
     * @exception InstanceNotFoundException The SNMP protocol adaptor does
     *     not exist in the MBean server.
     *
     * @exception ServiceNotFoundException This SNMP MIB is not registered
     *     in the MBean server or the requested service is not supported.
     *
     * @since 1.5
     */
@Override
public void setSnmpAdaptorName(ObjectName name, String contextName, SnmpOid[] oids) throws InstanceNotFoundException, ServiceNotFoundException {
    if (server == null) {
        throw new ServiceNotFoundException(mibName + " is not registered in the MBean server");
    }
    //
    if (adaptor != null) {
        adaptor.removeMib(this, contextName);
    }
    // Then update the reference to the new adaptor server.
    //
    Object[] params = { this, contextName, oids };
    String[] signature = { "com.sun.jmx.snmp.agent.SnmpMibAgent", "java.lang.String", oids.getClass().getName() };
    try {
        adaptor = (SnmpMibHandler) (server.invoke(name, "addMib", params, signature));
    } catch (InstanceNotFoundException e) {
        throw new InstanceNotFoundException(name.toString());
    } catch (ReflectionException e) {
        throw new ServiceNotFoundException(name.toString());
    } catch (MBeanException e) {
    // Should never occur...
    }
    adaptorName = name;
}
Also used : ReflectionException(javax.management.ReflectionException) ServiceNotFoundException(javax.management.ServiceNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException)

Example 80 with InstanceNotFoundException

use of javax.management.InstanceNotFoundException in project jdk8u_jdk by JetBrains.

the class RelationService method updateUnregistrationListener.

// Updates the listener registered to the MBean Server to be informed of
// referenced MBean deregistrations
//
// -param newRefList  ArrayList of ObjectNames for new references done
//  to MBeans (can be null)
// -param obsoleteRefList  ArrayList of ObjectNames for obsolete references
//  to MBeans (can be null)
//
// -exception RelationServiceNotRegisteredException  if the Relation
//  Service is not registered in the MBean Server.
private void updateUnregistrationListener(List<ObjectName> newRefList, List<ObjectName> obsoleteRefList) throws RelationServiceNotRegisteredException {
    if (newRefList != null && obsoleteRefList != null) {
        if (newRefList.isEmpty() && obsoleteRefList.isEmpty()) {
            // Nothing to do :)
            return;
        }
    }
    RELATION_LOGGER.entering(RelationService.class.getName(), "updateUnregistrationListener", new Object[] { newRefList, obsoleteRefList });
    // Can throw RelationServiceNotRegisteredException
    isActive();
    if (newRefList != null || obsoleteRefList != null) {
        boolean newListenerFlag = false;
        if (myUnregNtfFilter == null) {
            // Initialize it to be able to synchronise it :)
            myUnregNtfFilter = new MBeanServerNotificationFilter();
            newListenerFlag = true;
        }
        synchronized (myUnregNtfFilter) {
            // Enables ObjectNames in newRefList
            if (newRefList != null) {
                for (ObjectName newObjName : newRefList) myUnregNtfFilter.enableObjectName(newObjName);
            }
            if (obsoleteRefList != null) {
                // Disables ObjectNames in obsoleteRefList
                for (ObjectName obsObjName : obsoleteRefList) myUnregNtfFilter.disableObjectName(obsObjName);
            }
            // Under test
            if (newListenerFlag) {
                try {
                    myMBeanServer.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME, this, myUnregNtfFilter, null);
                } catch (InstanceNotFoundException exc) {
                    throw new RelationServiceNotRegisteredException(exc.getMessage());
                }
            }
        // End test
        //              if (!newListenerFlag) {
        // The Relation Service was already registered as a
        // listener:
        // removes it
        // Shall not throw InstanceNotFoundException (as the
        // MBean Server Delegate is expected to exist) or
        // ListenerNotFoundException (as it has been checked above
        // that the Relation Service is registered)
        //                  try {
        //                      myMBeanServer.removeNotificationListener(
        //                              MBeanServerDelegate.DELEGATE_NAME,
        //                              this);
        //                  } catch (InstanceNotFoundException exc1) {
        //                      throw new RuntimeException(exc1.getMessage());
        //                  } catch (ListenerNotFoundException exc2) {
        //                      throw new
        //                          RelationServiceNotRegisteredException(exc2.getMessage());
        //                  }
        //              }
        // Adds Relation Service with current filter
        // Can throw InstanceNotFoundException if the Relation
        // Service is not registered, to be transformed into
        // RelationServiceNotRegisteredException
        //
        // Assume that there will not be any InstanceNotFoundException
        // for the MBean Server Delegate :)
        //              try {
        //                  myMBeanServer.addNotificationListener(
        //                              MBeanServerDelegate.DELEGATE_NAME,
        //                              this,
        //                              myUnregNtfFilter,
        //                              null);
        //              } catch (InstanceNotFoundException exc) {
        //                  throw new
        //                     RelationServiceNotRegisteredException(exc.getMessage());
        //              }
        }
    }
    RELATION_LOGGER.exiting(RelationService.class.getName(), "updateUnregistrationListener");
    return;
}
Also used : InstanceNotFoundException(javax.management.InstanceNotFoundException) ObjectName(javax.management.ObjectName)

Aggregations

InstanceNotFoundException (javax.management.InstanceNotFoundException)102 ObjectName (javax.management.ObjectName)59 ReflectionException (javax.management.ReflectionException)44 MBeanException (javax.management.MBeanException)32 MalformedObjectNameException (javax.management.MalformedObjectNameException)28 MBeanRegistrationException (javax.management.MBeanRegistrationException)25 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)19 MBeanServer (javax.management.MBeanServer)17 IOException (java.io.IOException)16 AttributeNotFoundException (javax.management.AttributeNotFoundException)16 Attribute (javax.management.Attribute)15 IntrospectionException (javax.management.IntrospectionException)14 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)14 AttributeList (javax.management.AttributeList)12 ObjectInstance (javax.management.ObjectInstance)12 MBeanInfo (javax.management.MBeanInfo)11 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)10 RuntimeOperationsException (javax.management.RuntimeOperationsException)9 ArrayList (java.util.ArrayList)7 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)7