List of usage examples for javax.management JMException JMException
public JMException(String msg)
From source file:org.wso2.andes.server.AMQBrokerManagerMBean.java
/** * Deletes the queue from queue registry and persistant storage. * * @param queueName// w w w.j a va 2s .c om * @throws JMException * @throws MBeanException */ public void deleteQueue(final String queueName) throws JMException, MBeanException { AMQQueue queue = _queueRegistry.getQueue(new AMQShortString(queueName)); if (queue == null) { throw new JMException("The Queue " + queueName + " is not a registered queue."); } try { boolean isQueueDeletable = ClusterResourceHolder.getInstance().getVirtualHostConfigSynchronizer() .checkIfQueueDeletable(queue); if (isQueueDeletable) { CurrentActor.set(new ManagementActor(_logActor.getRootMessageLogger())); queue.delete(); if (queue.isDurable()) { _durableConfig.removeQueue(queue); } //tell Andes kernel to remove queue QpidAMQPBridge.getInstance().deleteQueue(queue); } else { _logActor.message(new LogMessage() { String message = "Cannot Delete Queue" + queueName + " It Has Registered Subscriptions."; public String toString() { return message; } public String getLogHierarchy() { return "amqp.queue"; } }); throw new AMQException("Cannot Delete Queue" + queueName + " It Has Registered Subscriptions."); } } catch (AMQException ex) { JMException jme = new JMException(ex.toString()); if (ex.toString().contains("not a registered queue")) { throw new MBeanException(jme, "The Queue " + queueName + " is not a registered queue."); } else if (ex.toString().contains("Has Registered Subscriptions")) { throw new MBeanException(jme, "Queue " + queueName + " has active subscribers. Please stop them first."); } else { throw new MBeanException(jme, "Error in deleting queue " + queueName + ":"); } } catch (Exception e) { throw new MBeanException(e, "Error in deleting queue " + queueName + ". There was an issue with cluster coordination"); } finally { CurrentActor.remove(); } }
From source file:org.springframework.jmx.export.MBeanExporter.java
/** * Registers the defined beans with the <code>MBeanServer</code>. Each bean is exposed * to the <code>MBeanServer</code> via a <code>ModelMBean</code>. The actual implemetation * of the <code>ModelMBean</code> interface used depends on the implementation of the * <code>ModelMBeanProvider</code> interface that is configured. By default the * <code>RequiredModelMBean</code> class that is supplied with all JMX implementations * is used./*from www . j a va 2s . co m*/ * <p>The management interface produced for each bean is dependent on the * <code>MBeanInfoAssembler</code> implementation being used. * The <code>ObjectName</code> given to each bean is dependent on the implementation * of the <code>ObjectNamingStrategy</code> interface being used. */ protected void registerBeans() throws JMException { // If no server was provided then try to find one. // This is useful in an environment such as JDK 1.5, Tomcat // or JBoss where there is already an MBeanServer loaded. if (this.server == null) { this.server = JmxUtils.locateMBeanServer(); } // The beans property may be <code>null</code>, for example // if we are relying solely on autodetection. if (this.beans == null) { this.beans = new HashMap(); } // Perform autodetection, if desired. if (this.autodetect) { if (this.beanFactory == null) { throw new JMException("Cannot autodetect MBeans if not running in a BeanFactory"); } // Autodetect any beans that are already MBeans. logger.info("Autodetecting user-defined JMX MBeans"); autodetectMBeans(); // Allow the metadata assembler a chance to vote for bean inclusion. if (this.assembler instanceof AutodetectCapableMBeanInfoAssembler) { autodetectBeans((AutodetectCapableMBeanInfoAssembler) this.assembler); } } // Check we now have at least one bean. if (this.beans.isEmpty()) { throw new IllegalArgumentException("Must specify at least one bean for registration"); } this.registeredBeans = new HashSet(this.beans.size()); try { for (Iterator it = this.beans.entrySet().iterator(); it.hasNext();) { Map.Entry entry = (Map.Entry) it.next(); String beanKey = (String) entry.getKey(); Object value = entry.getValue(); ObjectName objectName = registerBeanNameOrInstance(value, beanKey); if (objectName != null) { this.registeredBeans.add(objectName); notifyListenersOfRegistration(objectName); } } } catch (InvalidTargetObjectTypeException ex) { // Unregister beans already registered by this exporter. unregisterBeans(); // We should never get this! throw new JMException("An invalid object type was used when specifying a managed resource. " + "This is a serious error and points to an error in the Spring JMX code. Root cause: " + ex.getMessage()); } catch (JMException ex) { // Unregister beans already registered by this exporter. unregisterBeans(); throw ex; } }
From source file:org.wso2.andes.server.information.management.QueueManagementInformationMBean.java
/** * {@inheritDoc}/*from w w w.j a va 2s.co m*/ */ @Override public void deleteAllMessagesInQueue( @MBeanOperationParameter(name = "queueName", description = "Name of the queue to delete messages from") String queueName, @MBeanOperationParameter(name = "ownerName", description = "Username of user that calls for " + "purge") String ownerName) throws MBeanException { AMQQueue queue = queueRegistry.getQueue(new AMQShortString(queueName)); try { if (queue == null) { throw new JMException("The Queue " + queueName + " is not a registered queue."); } queue.purge(0l); //This is to trigger the AMQChannel purge event so that the queue // state of qpid is updated. This method also validates the request owner and throws // an exception if permission is denied. InboundQueueEvent storageQueue = AMQPUtils.createInboundQueueEvent(queue); int purgedMessageCount = Andes.getInstance().purgeQueue(storageQueue); log.info("Total message count purged for queue (from store) : " + queueName + " : " + purgedMessageCount + ". All in memory messages received before the purge call" + " are abandoned from delivery phase. "); } catch (JMException jme) { if (jme.toString().contains("not a registered queue")) { throw new MBeanException(jme, "The Queue " + queueName + " is not a registered " + "queue."); } else { throw new MBeanException(jme, PURGE_QUEUE_ERROR + queueName); } } catch (AMQException | AndesException amqex) { throw new MBeanException(amqex, PURGE_QUEUE_ERROR + queueName); } }
From source file:org.springframework.jmx.export.MBeanExporter.java
/** * Registers an individual bean with the <code>MBeanServer</code>. This method * is responsible for deciding <strong>how</strong> a bean should be exposed * to the <code>MBeanServer</code>. Specifically, if the <code>mapValue</code> * is the name of a bean that is configured for lazy initialization, then * a proxy to the resource is registered with the <code>MBeanServer</code> * so that the the lazy load behavior is honored. If the bean is already an * MBean then it will be registered directly with the <code>MBeanServer</code> * without any intervention. For all other beans or bean names, the resource * itself is registered with the <code>MBeanServer</code> directly. * @param beanKey the key associated with this bean in the beans map * @param mapValue the value configured for this bean in the beans map. * May be either the <code>String</code> name of a bean, or the bean itself. * @return the <code>ObjectName</code> under which the resource was registered * @throws JMException in case of an error in the underlying JMX infrastructure * @throws InvalidTargetObjectTypeException an error in the definition of the MBean resource * @see #setBeans/*from w ww . j a v a 2 s . c o m*/ * @see #registerLazyInit * @see #registerMBean * @see #registerSimpleBean */ private ObjectName registerBeanNameOrInstance(Object mapValue, String beanKey) throws JMException, InvalidTargetObjectTypeException { if (mapValue instanceof String) { // Bean name pointing to a potentially lazy-init bean in the factory. if (this.beanFactory == null) { throw new JMException("Cannot resolve bean names if not running in a BeanFactory"); } String beanName = (String) mapValue; if (isBeanDefinitionLazyInit(this.beanFactory, beanName)) { if (logger.isDebugEnabled()) { logger.debug("Found bean name for lazy init bean with key [" + beanKey + "]. Registering bean with lazy init support."); } return registerLazyInit(beanName, beanKey); } else { if (logger.isDebugEnabled()) { logger.debug("String value under key [" + beanKey + "] points to a bean that was not " + "registered for lazy initialization. Registering bean normally with JMX server."); } Object bean = this.beanFactory.getBean(beanName); return registerBeanInstance(bean, beanKey); } } else { // Plain bean instance -> register it directly. return registerBeanInstance(mapValue, beanKey); } }