Search in sources :

Example 41 with MBeanException

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

the class RequiredModelMBean method sendNotification.

public void sendNotification(Notification ntfyObj) throws MBeanException, RuntimeOperationsException {
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), "sendNotification(Notification)", "Entry");
    }
    if (ntfyObj == null)
        throw new RuntimeOperationsException(new IllegalArgumentException("notification object must not be " + "null"), "Exception occurred trying to send a notification from a " + "RequiredModelMBean");
    // log notification if specified in descriptor
    Descriptor ntfyDesc = modelMBeanInfo.getDescriptor(ntfyObj.getType(), "notification");
    Descriptor mmbDesc = modelMBeanInfo.getMBeanDescriptor();
    if (ntfyDesc != null) {
        String logging = (String) ntfyDesc.getFieldValue("log");
        if (logging == null) {
            if (mmbDesc != null)
                logging = (String) mmbDesc.getFieldValue("log");
        }
        if ((logging != null) && (logging.equalsIgnoreCase("t") || logging.equalsIgnoreCase("true"))) {
            String logfile = (String) ntfyDesc.getFieldValue("logfile");
            if (logfile == null) {
                if (mmbDesc != null)
                    logfile = (String) mmbDesc.getFieldValue("logfile");
            }
            if (logfile != null) {
                try {
                    writeToLog(logfile, "LogMsg: " + ((new Date(ntfyObj.getTimeStamp())).toString()) + " " + ntfyObj.getType() + " " + ntfyObj.getMessage() + " Severity = " + (String) ntfyDesc.getFieldValue("severity"));
                } catch (Exception e) {
                    if (MODELMBEAN_LOGGER.isLoggable(Level.FINE)) {
                        MODELMBEAN_LOGGER.logp(Level.FINE, RequiredModelMBean.class.getName(), "sendNotification(Notification)", "Failed to log " + ntfyObj.getType() + " notification: ", e);
                    }
                }
            }
        }
    }
    if (generalBroadcaster != null) {
        generalBroadcaster.sendNotification(ntfyObj);
    }
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), "sendNotification(Notification)", "sendNotification sent provided notification object");
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), "sendNotification(Notification)", " Exit");
    }
}
Also used : Descriptor(javax.management.Descriptor) Date(java.util.Date) AttributeNotFoundException(javax.management.AttributeNotFoundException) ServiceNotFoundException(javax.management.ServiceNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) RuntimeErrorException(javax.management.RuntimeErrorException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ListenerNotFoundException(javax.management.ListenerNotFoundException) RuntimeOperationsException(javax.management.RuntimeOperationsException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 42 with MBeanException

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

the class RequiredModelMBean method sendAttributeChangeNotification.

public void sendAttributeChangeNotification(AttributeChangeNotification ntfyObj) throws MBeanException, RuntimeOperationsException {
    final String mth = "sendAttributeChangeNotification(" + "AttributeChangeNotification)";
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Entry");
    }
    if (ntfyObj == null)
        throw new RuntimeOperationsException(new IllegalArgumentException("attribute change notification object must not be null"), "Exception occurred trying to send " + "attribute change notification of a ModelMBean");
    Object oldv = ntfyObj.getOldValue();
    Object newv = ntfyObj.getNewValue();
    if (oldv == null)
        oldv = "null";
    if (newv == null)
        newv = "null";
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Sending AttributeChangeNotification with " + ntfyObj.getAttributeName() + ntfyObj.getAttributeType() + ntfyObj.getNewValue() + ntfyObj.getOldValue());
    }
    // log notification if specified in descriptor
    Descriptor ntfyDesc = modelMBeanInfo.getDescriptor(ntfyObj.getType(), "notification");
    Descriptor mmbDesc = modelMBeanInfo.getMBeanDescriptor();
    String logging, logfile;
    if (ntfyDesc != null) {
        logging = (String) ntfyDesc.getFieldValue("log");
        if (logging == null) {
            if (mmbDesc != null)
                logging = (String) mmbDesc.getFieldValue("log");
        }
        if ((logging != null) && (logging.equalsIgnoreCase("t") || logging.equalsIgnoreCase("true"))) {
            logfile = (String) ntfyDesc.getFieldValue("logfile");
            if (logfile == null) {
                if (mmbDesc != null)
                    logfile = (String) mmbDesc.getFieldValue("logfile");
            }
            if (logfile != null) {
                try {
                    writeToLog(logfile, "LogMsg: " + ((new Date(ntfyObj.getTimeStamp())).toString()) + " " + ntfyObj.getType() + " " + ntfyObj.getMessage() + " Name = " + ntfyObj.getAttributeName() + " Old value = " + oldv + " New value = " + newv);
                } catch (Exception e) {
                    if (MODELMBEAN_LOGGER.isLoggable(Level.FINE)) {
                        MODELMBEAN_LOGGER.logp(Level.FINE, RequiredModelMBean.class.getName(), mth, "Failed to log " + ntfyObj.getType() + " notification: ", e);
                    }
                }
            }
        }
    } else if (mmbDesc != null) {
        logging = (String) mmbDesc.getFieldValue("log");
        if ((logging != null) && (logging.equalsIgnoreCase("t") || logging.equalsIgnoreCase("true"))) {
            logfile = (String) mmbDesc.getFieldValue("logfile");
            if (logfile != null) {
                try {
                    writeToLog(logfile, "LogMsg: " + ((new Date(ntfyObj.getTimeStamp())).toString()) + " " + ntfyObj.getType() + " " + ntfyObj.getMessage() + " Name = " + ntfyObj.getAttributeName() + " Old value = " + oldv + " New value = " + newv);
                } catch (Exception e) {
                    if (MODELMBEAN_LOGGER.isLoggable(Level.FINE)) {
                        MODELMBEAN_LOGGER.logp(Level.FINE, RequiredModelMBean.class.getName(), mth, "Failed to log " + ntfyObj.getType() + " notification: ", e);
                    }
                }
            }
        }
    }
    if (attributeBroadcaster != null) {
        attributeBroadcaster.sendNotification(ntfyObj);
    }
    //
    if (generalBroadcaster != null) {
        generalBroadcaster.sendNotification(ntfyObj);
    }
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "sent notification");
        MODELMBEAN_LOGGER.logp(Level.FINER, RequiredModelMBean.class.getName(), mth, "Exit");
    }
}
Also used : Descriptor(javax.management.Descriptor) Date(java.util.Date) AttributeNotFoundException(javax.management.AttributeNotFoundException) ServiceNotFoundException(javax.management.ServiceNotFoundException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) RuntimeErrorException(javax.management.RuntimeErrorException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) MBeanException(javax.management.MBeanException) ListenerNotFoundException(javax.management.ListenerNotFoundException) RuntimeOperationsException(javax.management.RuntimeOperationsException) RuntimeOperationsException(javax.management.RuntimeOperationsException)

Example 43 with MBeanException

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

the class RelationSupport method setRoleInt.

// Sets the role with given value
//
// This method is called in setRole() above.
// It is also called by the Relation Service setRole() method.
// It is also called in setRolesInt() method below (used in setRoles()
// above and in RelationService setRoles() method).
//
// Will check the role according to its corresponding role definition
// provided in relation's relation type
// Will send a notification (RelationNotification with type
// RELATION_BASIC_UPDATE or RELATION_MBEAN_UPDATE, depending if the
// relation is a MBean or not) if not initialization of role.
//
// -param aRole  role to be set (name and new value)
// -param relationServCallFlg  true if call from the Relation Service; this
//  will happen if the current RelationSupport object has been created by
//  the Relation Service (via createRelation()) method, so direct access is
//  possible.
// -param relationServ  reference to Relation Service object, if internal
//  relation
// -param multiRoleFlg  true if getting the role in the scope of a
//  multiple retrieval.
//
// -return (except other "critical" exceptions):
//  - for single role retrieval (multiRoleFlg false):
//    - null if the role has been set
//    - raise an InvalidRoleValueException
// else
//  - for multi-role retrieval (multiRoleFlg true):
//    - the Role object for given role name if role has been set
//    - a RoleUnresolved object with problem else.
//
// -exception IllegalArgumentException if null parameter
// -exception RoleNotFoundException  if multiRoleFlg is false and:
//  - internal relation and the role does not exist
//  or
//  - existing role (i.e. not initializing it) and the role is not
//    writable.
// -exception InvalidRoleValueException  ifmultiRoleFlg is false and
//  value provided for:
//   - the number of referenced MBeans in given value is less than
//     expected minimum degree
//   or
//   - the number of referenced MBeans in provided value exceeds expected
//     maximum degree
//   or
//   - one referenced MBean in the value is not an Object of the MBean
//     class expected for that role
//   or
//   - a MBean provided for that role does not exist
// -exception RelationServiceNotRegisteredException  if the Relation
//  Service is not registered in the MBean Server
// -exception RelationTypeNotFoundException  if relation type unknown
// -exception RelationNotFoundException  if a relation MBean has not been
//  added in the Relation Service
Object setRoleInt(Role aRole, boolean relationServCallFlg, RelationService relationServ, boolean multiRoleFlg) throws IllegalArgumentException, RoleNotFoundException, InvalidRoleValueException, RelationServiceNotRegisteredException, RelationTypeNotFoundException, RelationNotFoundException {
    if (aRole == null || (relationServCallFlg && relationServ == null)) {
        String excMsg = "Invalid parameter.";
        throw new IllegalArgumentException(excMsg);
    }
    RELATION_LOGGER.entering(RelationSupport.class.getName(), "setRoleInt", new Object[] { aRole, relationServCallFlg, relationServ, multiRoleFlg });
    String roleName = aRole.getRoleName();
    int pbType = 0;
    // Checks if role exists in the relation
    // No error if the role does not exist in the relation, to be able to
    // handle initialization of role when creating the relation
    // (roles provided in the RoleList parameter are directly set but
    // roles automatically initialized are set using setRole())
    Role role;
    synchronized (myRoleName2ValueMap) {
        role = (myRoleName2ValueMap.get(roleName));
    }
    List<ObjectName> oldRoleValue;
    Boolean initFlg;
    if (role == null) {
        initFlg = true;
        oldRoleValue = new ArrayList<ObjectName>();
    } else {
        initFlg = false;
        oldRoleValue = role.getRoleValue();
    }
    // initialization) and correct value
    try {
        Integer status;
        if (relationServCallFlg) {
            // Call from the Relation Service, so direct access to it,
            // avoiding MBean Server
            //
            // Shall not raise a RelationTypeNotFoundException
            status = relationServ.checkRoleWriting(aRole, myRelTypeName, initFlg);
        } else {
            // Call from setRole() method above
            // So we have a MBean. We must access the Relation Service
            // via the MBean Server.
            Object[] params = new Object[3];
            params[0] = aRole;
            params[1] = myRelTypeName;
            params[2] = initFlg;
            String[] signature = new String[3];
            signature[0] = "javax.management.relation.Role";
            signature[1] = "java.lang.String";
            signature[2] = "java.lang.Boolean";
            // Can throw InstanceNotFoundException if the Relation Service
            // is not registered (to be transformed into
            // RelationServiceNotRegisteredException in any case).
            //
            // Can throw a MBeanException wrapping a
            // RelationTypeNotFoundException:
            // throw wrapped exception.
            //
            // Shall not throw a ReflectionException
            status = (Integer) (myRelServiceMBeanServer.invoke(myRelServiceName, "checkRoleWriting", params, signature));
        }
        pbType = status.intValue();
    } catch (MBeanException exc2) {
        // Retrieves underlying exception
        Exception wrappedExc = exc2.getTargetException();
        if (wrappedExc instanceof RelationTypeNotFoundException) {
            throw ((RelationTypeNotFoundException) wrappedExc);
        } else {
            throw new RuntimeException(wrappedExc.getMessage());
        }
    } catch (ReflectionException exc3) {
        throw new RuntimeException(exc3.getMessage());
    } catch (RelationTypeNotFoundException exc4) {
        throw new RuntimeException(exc4.getMessage());
    } catch (InstanceNotFoundException exc5) {
        throw new RelationServiceNotRegisteredException(exc5.getMessage());
    }
    Object result = null;
    if (pbType == 0) {
        // Role can be set
        if (!(initFlg.booleanValue())) {
            // Not initializing the role
            // If role being initialized:
            // - do not send an update notification
            // - do not try to update internal map of Relation Service
            //   listing referenced MBeans, as role is initialized to an
            //   empty list
            // Sends a notification (RelationNotification)
            // Can throw a RelationNotFoundException
            sendRoleUpdateNotification(aRole, oldRoleValue, relationServCallFlg, relationServ);
            // Updates the role map of the Relation Service
            // Can throw RelationNotFoundException
            updateRelationServiceMap(aRole, oldRoleValue, relationServCallFlg, relationServ);
        }
        // Sets the role
        synchronized (myRoleName2ValueMap) {
            myRoleName2ValueMap.put(roleName, (Role) (aRole.clone()));
        }
        if (multiRoleFlg) {
            // Multi-roles retrieval: returns the role
            result = aRole;
        }
    } else {
        if (!(multiRoleFlg)) {
            // Problem when setting a simple role: either role not
            // found, not writable, or incorrect value:
            // raises appropriate exception, RoleNotFoundException or
            // InvalidRoleValueException
            RelationService.throwRoleProblemException(pbType, roleName);
            // To keep compiler happy :)
            return null;
        } else {
            // Problem when retrieving a role in a multi-role retrieval:
            // returns a RoleUnresolved object
            result = new RoleUnresolved(roleName, aRole.getRoleValue(), pbType);
        }
    }
    RELATION_LOGGER.exiting(RelationSupport.class.getName(), "setRoleInt");
    return result;
}
Also used : ReflectionException(javax.management.ReflectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) MBeanException(javax.management.MBeanException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) ObjectName(javax.management.ObjectName) MBeanException(javax.management.MBeanException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 44 with MBeanException

use of javax.management.MBeanException in project bamboobsc by billchen198318.

the class HostUtils method getHttpPort.

public static int getHttpPort() {
    int port = 8080;
    MBeanServer mBeanServer = MBeanServerFactory.findMBeanServer(null).get(0);
    ObjectName name;
    try {
        name = new ObjectName("Catalina", "type", "Server");
        try {
            Server server = (Server) mBeanServer.getAttribute(name, "managedResource");
            Service[] services = server.findServices();
            for (Service service : services) {
                for (Connector connector : service.findConnectors()) {
                    ProtocolHandler protocolHandler = connector.getProtocolHandler();
                    if (protocolHandler instanceof Http11Protocol || protocolHandler instanceof Http11AprProtocol || protocolHandler instanceof Http11NioProtocol) {
                        port = connector.getPort();
                    }
                }
            }
        } catch (AttributeNotFoundException e) {
            e.printStackTrace();
        } catch (InstanceNotFoundException e) {
            e.printStackTrace();
        } catch (MBeanException e) {
            e.printStackTrace();
        } catch (ReflectionException e) {
            e.printStackTrace();
        }
    } catch (MalformedObjectNameException e) {
        e.printStackTrace();
    }
    return port;
}
Also used : Connector(org.apache.catalina.connector.Connector) ReflectionException(javax.management.ReflectionException) AttributeNotFoundException(javax.management.AttributeNotFoundException) MalformedObjectNameException(javax.management.MalformedObjectNameException) Http11NioProtocol(org.apache.coyote.http11.Http11NioProtocol) MBeanServer(javax.management.MBeanServer) Server(org.apache.catalina.Server) InstanceNotFoundException(javax.management.InstanceNotFoundException) Service(org.apache.catalina.Service) Http11AprProtocol(org.apache.coyote.http11.Http11AprProtocol) ObjectName(javax.management.ObjectName) ProtocolHandler(org.apache.coyote.ProtocolHandler) Http11Protocol(org.apache.coyote.http11.Http11Protocol) MBeanException(javax.management.MBeanException) MBeanServer(javax.management.MBeanServer)

Example 45 with MBeanException

use of javax.management.MBeanException in project ddf by codice.

the class ResourceDownload method copyToLocalSite.

@Override
public void copyToLocalSite(String sourceId, String metacardId) throws MBeanException {
    LOGGER.debug("Downloading resource associated with metacard id [{}] from source [{}] to the local site.", metacardId, sourceId);
    ResourceRequest resourceRequest = new ResourceRequestById(metacardId);
    if (!resourceCacheMBean.isCacheEnabled()) {
        String message = "Caching of resources is not enabled.";
        LOGGER.info(message);
        throw new MBeanException(new DownloadToLocalSiteException(Status.BAD_REQUEST, message), message);
    }
    try {
        LOGGER.debug("Attempting to download the resource associated with metacard [{}] from source [{}] to the local site.", metacardId, sourceId);
        ResourceResponse resourceResponse = catalogFramework.getResource(resourceRequest, sourceId);
        if (resourceResponse == null) {
            String message = String.format(ERROR_MESSAGE_TEMPLATE, metacardId, sourceId);
            LOGGER.debug(message);
            throw new MBeanException(new DownloadToLocalSiteException(Status.INTERNAL_SERVER_ERROR, message), message);
        }
    } catch (IOException | ResourceNotSupportedException e) {
        String message = String.format(ERROR_MESSAGE_TEMPLATE, metacardId, sourceId);
        LOGGER.debug(message, e);
        throw new MBeanException(new DownloadToLocalSiteException(Status.INTERNAL_SERVER_ERROR, message), message);
    } catch (ResourceNotFoundException e) {
        String message = String.format(ERROR_MESSAGE_TEMPLATE + " The resource could not be found.", metacardId, sourceId);
        LOGGER.debug(message, e);
        throw new MBeanException(new DownloadToLocalSiteException(Status.NOT_FOUND, message), message);
    }
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) ResourceRequest(ddf.catalog.operation.ResourceRequest) DownloadToLocalSiteException(org.codice.ddf.catalog.resource.download.DownloadToLocalSiteException) IOException(java.io.IOException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException)

Aggregations

MBeanException (javax.management.MBeanException)105 ReflectionException (javax.management.ReflectionException)50 InstanceNotFoundException (javax.management.InstanceNotFoundException)41 AttributeNotFoundException (javax.management.AttributeNotFoundException)35 ObjectName (javax.management.ObjectName)32 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)31 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)26 MalformedObjectNameException (javax.management.MalformedObjectNameException)19 InvocationTargetException (java.lang.reflect.InvocationTargetException)18 RuntimeOperationsException (javax.management.RuntimeOperationsException)18 ServiceNotFoundException (javax.management.ServiceNotFoundException)17 Attribute (javax.management.Attribute)14 RuntimeErrorException (javax.management.RuntimeErrorException)14 Method (java.lang.reflect.Method)10 DynamicMBean (javax.management.DynamicMBean)10 ListenerNotFoundException (javax.management.ListenerNotFoundException)10 Descriptor (javax.management.Descriptor)9 InvalidTargetObjectTypeException (javax.management.modelmbean.InvalidTargetObjectTypeException)8 MalformedURLException (java.net.MalformedURLException)7 MBeanRegistrationException (javax.management.MBeanRegistrationException)7