Example usage for javax.management JMException JMException

List of usage examples for javax.management JMException JMException

Introduction

In this page you can find the example usage for javax.management JMException JMException.

Prototype

public JMException(String msg) 

Source Link

Document

Constructor that allows a specific error message to be specified.

Usage

From source file:org.wso2.andes.server.cluster.ClusterManagementInformationMBean.java

/**
 * {@inheritDoc}//from   w  w  w.  j  a  v a2  s  .  c  o m
 */
@Override
public List<String> getAllClusterNodeAddresses() throws JMException {
    try {
        return this.clusterManager.getAllClusterNodeAddresses();
    } catch (AndesException e) {
        logger.error("Error occurred while retrieving cluster details", e);
        throw new JMException("Error occurred while retrieving cluster details");
    }
}

From source file:org.apache.servicemix.jbi.deployer.impl.ComponentInstaller.java

public void register() throws JMException {
    try {/*from   ww  w  . ja v  a2  s .  co  m*/
        deployer.getManagementStrategy().manageObject(this);
    } catch (Exception ex) {
        throw new JMException(ex.getMessage());
    }
}

From source file:org.apache.camel.management.JmxMBeanAssembler.java

public RequiredModelMBean assemble(Object obj, ObjectName name) throws JMException {
    ModelMBeanInfo mbi = null;//from   ww  w. j av  a2 s.c o m

    // prefer to use the managed instance if it has been annotated with Spring JMX annotations
    if (obj instanceof ManagedInstance) {
        Object custom = ((ManagedInstance) obj).getInstance();
        if (custom != null
                && ObjectHelper.hasAnnotation(custom.getClass().getAnnotations(), ManagedResource.class)) {
            if (LOG.isTraceEnabled()) {
                LOG.trace("Assembling MBeanInfo for: " + name.toString()
                        + " from custom @ManagedResource object: " + custom);
            }
            // get the mbean info from the custom managed object
            mbi = assembler.getMBeanInfo(custom, name.toString());
            // and let the custom object be registered in JMX
            obj = custom;
        }
    }

    if (mbi == null) {
        // use the default provided mbean which has been annotated with Spring JMX annotations
        if (LOG.isTraceEnabled()) {
            LOG.trace("Assembling MBeanInfo for: " + name.toString() + " from @ManagedResource object: " + obj);
        }
        mbi = assembler.getMBeanInfo(obj, name.toString());
    }

    RequiredModelMBean mbean = (RequiredModelMBean) server.instantiate(RequiredModelMBean.class.getName());
    mbean.setModelMBeanInfo(mbi);

    try {
        mbean.setManagedResource(obj, "ObjectReference");
    } catch (InvalidTargetObjectTypeException e) {
        throw new JMException(e.getMessage());
    }

    return mbean;
}

From source file:org.apache.servicemix.jbi.deployer.impl.ComponentInstaller.java

public void unregister() throws JMException {
    try {//from  w  ww .j ava 2s . com
        deployer.getManagementStrategy().unmanageObject(this);
    } catch (Exception ex) {
        throw new JMException(ex.getMessage());
    }
}

From source file:org.apache.servicemix.nmr.management.ManagementAgent.java

/**
 * @see org.fusesource.commons.management.ManagementStrategy#manageNamedObject(java.lang.Object,java.lang.Object)
 *//*  w  ww  . j av a2s .c  o m*/
public void manageNamedObject(Object managedObject, Object preferredName) throws Exception {
    managedObject = getTypeSpecificManagedObject(managedObject);
    if (preferredName instanceof ObjectName && managedObject != null) {
        try {
            register(managedObject, (ObjectName) preferredName);
        } catch (Exception ex) {
            throw (JMException) new JMException(ex.getMessage()).initCause(ex);
        }
    }
}

From source file:org.wso2.andes.server.AMQBrokerManagerMBean.java

/**
 * Creates new exchange and registers it with the registry.
 *
 * @param exchangeName/*from  w  w  w.j  a v  a 2s.  c  o m*/
 * @param type
 * @param durable
 * @throws JMException
 * @throws MBeanException
 */
public void createNewExchange(String exchangeName, String type, boolean durable)
        throws JMException, MBeanException {
    CurrentActor.set(new ManagementActor(_logActor.getRootMessageLogger()));
    try {
        synchronized (_exchangeRegistry) {
            Exchange exchange = _exchangeRegistry.getExchange(new AMQShortString(exchangeName));
            if (exchange == null) {
                exchange = _exchangeFactory.createExchange(new AMQShortString(exchangeName),
                        new AMQShortString(type), durable, false, 0);
                _exchangeRegistry.registerExchange(exchange);
                if (durable) {
                    _durableConfig.createExchange(exchange);

                    //tell Andes kernel to create Exchange
                    QpidAMQPBridge.getInstance().createExchange(exchange);
                }
            } else {
                throw new JMException("The exchange \"" + exchangeName + "\" already exists.");
            }
        }
    } catch (AMQException ex) {
        JMException jme = new JMException(ex.toString());
        throw new MBeanException(jme, "Error in creating exchange " + exchangeName);
    } finally {
        CurrentActor.remove();
    }
}

From source file:org.apache.servicemix.nmr.management.ManagementAgent.java

public void register(Object obj, ObjectName name, boolean forceRegistration) throws JMException {
    try {/*from ww  w  . j ava  2 s. c o m*/
        registerMBeanWithServer(obj, name, forceRegistration);
    } catch (NotCompliantMBeanException e) {
        // If this is not a "normal" MBean, then try to deploy it using JMX
        // annotations
        ModelMBeanInfo mbi = assembler.getMBeanInfo(obj, name.toString());
        RequiredModelMBean mbean = (RequiredModelMBean) mbeanServer
                .instantiate(RequiredModelMBean.class.getName());
        mbean.setModelMBeanInfo(mbi);
        try {
            mbean.setManagedResource(obj, "ObjectReference");
        } catch (InvalidTargetObjectTypeException itotex) {
            throw new JMException(itotex.getMessage());
        }
        registerMBeanWithServer(mbean, name, forceRegistration);
    }
}

From source file:org.wso2.andes.server.AMQBrokerManagerMBean.java

/**
 * Unregisters the exchange from registry.
 *
 * @param exchangeName/* w ww.jav  a 2 s  .  c  om*/
 * @throws JMException
 * @throws MBeanException
 */
public void unregisterExchange(String exchangeName) throws JMException, MBeanException {
    // TODO
    // Check if the exchange is in use.
    // boolean inUse = false;
    // Check if there are queue-bindings with the exchange and unregister
    // when there are no bindings.
    CurrentActor.set(new ManagementActor(_logActor.getRootMessageLogger()));
    try {
        _exchangeRegistry.unregisterExchange(new AMQShortString(exchangeName), false);
    } catch (AMQException ex) {
        JMException jme = new JMException(ex.toString());
        throw new MBeanException(jme, "Error in unregistering exchange " + exchangeName);
    } finally {
        CurrentActor.remove();
    }
}

From source file:org.wso2.andes.server.AMQBrokerManagerMBean.java

/**
 * Creates a new queue and registers it with the registry and puts it
 * in persistance storage if durable queue.
 *
 * @param queueName//from  w w w.  jav a 2 s .  c o  m
 * @param durable
 * @param owner
 * @throws JMException
 * @throws MBeanException
 */
public void createNewQueue(String queueName, String owner, boolean durable, boolean exclusiveConsumer)
        throws JMException, MBeanException {
    AMQQueue queue = _queueRegistry.getQueue(new AMQShortString(queueName));
    try {
        if (queue != null) {
            //ClusterResourceHolder.getInstance().getCassandraMessageStore().addQueue(queueName);
            throw new JMException("The queue \"" + queueName + "\" already exists.");
        }

        CurrentActor.set(new ManagementActor(_logActor.getRootMessageLogger()));
        AMQShortString ownerShortString = null;
        if (owner != null) {
            ownerShortString = new AMQShortString(owner);
        }

        queue = AMQQueueFactory.createAMQQueueImpl(new AMQShortString(queueName), durable, ownerShortString,
                false, false, getVirtualHost(), null);
        if (queue.isDurable() && !queue.isAutoDelete()) {
            _durableConfig.createQueue(queue);

            //tell Andes kernel to create queue
            QpidAMQPBridge.getInstance().createQueue(queue, exclusiveConsumer);
        }

    } catch (Exception ex) {
        JMException jme = new JMException(ex.toString());
        throw new MBeanException(jme, "The queue \"" + queueName + "\" already exists.");
    } finally {
        CurrentActor.remove();
    }
}

From source file:org.jolokia.backend.MBeanServerHandler.java

/**
 * Unregister all previously registered MBean. This is tried for all previously
 * registered MBeans//  w  w  w.  j a va2  s.  c o m
 *
 * @throws JMException if an exception occurs during unregistration
 */
public final void destroy() throws JMException {
    synchronized (mBeanHandles) {
        List<JMException> exceptions = new ArrayList<JMException>();
        List<MBeanHandle> unregistered = new ArrayList<MBeanHandle>();
        for (MBeanHandle handle : mBeanHandles) {
            try {
                unregistered.add(handle);
                handle.server.unregisterMBean(handle.objectName);
            } catch (InstanceNotFoundException e) {
                exceptions.add(e);
            } catch (MBeanRegistrationException e) {
                exceptions.add(e);
            }
        }
        // Remove all successfully unregistered handles
        mBeanHandles.removeAll(unregistered);

        // Throw error if any exception occured during unregistration
        if (exceptions.size() == 1) {
            throw exceptions.get(0);
        } else if (exceptions.size() > 1) {
            StringBuilder ret = new StringBuilder();
            for (JMException e : exceptions) {
                ret.append(e.getMessage()).append(", ");
            }
            throw new JMException(ret.substring(0, ret.length() - 2));
        }
    }

    // Unregister any notification listener
    mBeanServerManager.destroy();
}