Example usage for javax.management MBeanException MBeanException

List of usage examples for javax.management MBeanException MBeanException

Introduction

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

Prototype

public MBeanException(java.lang.Exception e, String message) 

Source Link

Document

Creates an MBeanException that wraps the actual java.lang.Exception with a detail message.

Usage

From source file:org.wso2.andes.server.information.management.SubscriptionManagementInformationMBean.java

/**
 * {@inheritDoc}//from   w  w  w  .java 2  s .c  o m
 */
@Override
public String[] getSubscriptions(String isDurable, String isActive, String protocolType, String destinationType)
        throws MBeanException {
    try {

        //TODO: fix this method. isActive comes as *
        boolean durableSubscriptionsReq = Boolean.parseBoolean(isDurable);
        Set<AndesSubscription> subscriptionsToDisplay = getSubscriptionsOfBroker(durableSubscriptionsReq, true,
                protocolType, destinationType);

        Set<AndesSubscription> inactiveSubscriptions = getSubscriptionsOfBroker(durableSubscriptionsReq, false,
                protocolType, destinationType);
        subscriptionsToDisplay.addAll(inactiveSubscriptions);

        String[] subscriptionArray = new String[subscriptionsToDisplay.size()];

        int index = 0;
        for (AndesSubscription subscription : subscriptionsToDisplay) {
            Long pendingMessageCount = MessagingEngine.getInstance()
                    .getApproximateQueueMessageCount(subscription.getStorageQueue().getName());

            subscriptionArray[index] = renderSubscriptionForUI(subscription.isActive(), destinationType,
                    subscription, pendingMessageCount.intValue());

            index++;
        }
        return subscriptionArray;

    } catch (Exception e) {
        log.error("Error while invoking MBeans to retrieve subscription information", e);
        throw new MBeanException(e, "Error while invoking MBeans to retrieve subscription information");
    }
}

From source file:org.wso2.andes.server.information.management.SubscriptionManagementInformationMBean.java

/**
 * {@inheritDoc}//from www . j  av  a  2 s  .c  o  m
 */
public long getPendingMessageCount(String queueName) throws MBeanException {
    try {
        return MessagingEngine.getInstance().getApproximateQueueMessageCount(queueName);
    } catch (Exception e) {
        log.error("Error while invoking MBeans to calculate the pending message count for storage queue", e);
        throw new MBeanException(e,
                "Error while invoking MBeans to calculate the pending message count for " + "storage queue");
    }
}

From source file:catalina.mbeans.StandardServerMBean.java

/**
 * Write the configuration information for this entire <code>Server</code>
 * out to the server.xml configuration file.
 *
 * @exception InstanceNotFoundException if the managed resource object
 *  cannot be found/*from ww  w .ja  v a 2s  .  co m*/
 * @exception MBeanException if the initializer of the object throws
 *  an exception, or persistence is not supported
 * @exception RuntimeOperationsException if an exception is reported
 *  by the persistence mechanism
 */
public synchronized void store() throws InstanceNotFoundException, MBeanException, RuntimeOperationsException {

    Server server = ServerFactory.getServer();
    if (server instanceof StandardServer) {
        try {
            ((StandardServer) server).store();
        } catch (Exception e) {
            throw new MBeanException(e, "Error updating conf/server.xml");
        }
    }

}

From source file:org.skfiy.typhon.spi.GMConsoleProvider.java

/**
 *
 * @param uid//from   ww w . j  a  v a  2s.  co m
 * @param propertyName
 * @param val
 * @throws javax.management.MBeanException
 */
public void changeProperty(final String uid, final String propertyName, final String val)
        throws MBeanException {
    try {
        invoke(transcoding(uid), new Handler() {

            @Override
            void execute() {
                Player player = SessionUtils.getPlayer();
                try {
                    Class<?> propertyType = PropertyUtils.getPropertyType(player, propertyName);
                    if (propertyType == null) { // Not found property
                        throw new IllegalArgumentException("Not found property[" + propertyName + "]");
                    }

                    if (propertyType == Byte.class || propertyType == Byte.TYPE) {
                        BeanUtils.setProperty(player, propertyName, Byte.valueOf(val));
                    } else if (propertyType == Character.class || propertyType == Character.TYPE) {
                        BeanUtils.setProperty(player, propertyName, val.charAt(0));
                    } else if (propertyType == Boolean.class || propertyType == Boolean.TYPE) {
                        BeanUtils.setProperty(player, propertyName, Boolean.valueOf(val));
                    } else if (propertyType == Integer.class || propertyType == Integer.TYPE) {
                        BeanUtils.setProperty(player, propertyName, Integer.valueOf(val));
                    } else if (propertyType == Long.class || propertyType == Long.TYPE) {
                        BeanUtils.setProperty(player, propertyName, Long.valueOf(val));
                    } else if (propertyType == Float.class || propertyType == Float.TYPE) {
                        BeanUtils.setProperty(player, propertyName, Float.valueOf(val));
                    } else if (propertyType == Double.class || propertyType == Double.TYPE) {
                        BeanUtils.setProperty(player, propertyName, Double.valueOf(val));
                    } else {
                        BeanUtils.setProperty(player, propertyName, val);
                    }

                } catch (Exception ex) {
                    throw new IllegalArgumentException(ex.getMessage());
                }
            }

        });
    } catch (Exception e) {
        throw new MBeanException(e, e.getMessage());
    }
}

From source file:org.skfiy.typhon.spi.GMConsoleProvider.java

/**
 *
 * @param key/*from  w ww.  j a v  a  2s .com*/
 * @param value
 * @throws javax.management.MBeanException
 */
public void changeSystemProperties(final String key, final String value) throws MBeanException {
    try {
        Typhons.setProperty(key, value);
        Typhons.refresh();
    } catch (Exception e) {
        throw new MBeanException(e, e.getMessage());
    }
}

From source file:org.skfiy.typhon.spi.GMConsoleProvider.java

/**
 *
 * @param uid/*  w  ww.j  a va2  s .  c  o  m*/
 * @param iid
 * @param level
 * @throws MBeanException
 */
public void changeHeroLevel(final String uid, final String iid, final String level) throws MBeanException {
    try {
        invoke(transcoding(uid), new Handler() {

            @Override
            void execute() {
                Player player = SessionUtils.getPlayer();
                Node node = player.getHeroBag().findNode(iid);
                if (node == null) {
                    HeroItemDobj itemDobj = itemProvider.getItem(iid);
                    int pos = player.getHeroBag().intoItem(itemDobj);
                    node = player.getHeroBag().findNode(pos);
                }

                HeroItem heroItem = node.getItem();
                int lv = Integer.valueOf(level);
                if (lv > 150) {
                    lv = 150;
                }
                heroItem.setLevel(lv);
            }

        });
    } catch (Exception e) {
        throw new MBeanException(e, e.getMessage());
    }
}

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

/**
 * Creates new exchange and registers it with the registry.
 *
 * @param exchangeName/* www .  jav a  2  s .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.wso2.andes.server.information.management.SubscriptionManagementInformationMBean.java

/**
 * {@inheritDoc}/*from   ww  w  .  jav  a2s.c  o  m*/
 */
public String[] getFilteredSubscriptions(boolean isDurable, boolean isActive, String protocolType,
        String destinationType, String filteredNamePattern, boolean isFilteredNameByExactMatch,
        String identifierPattern, boolean isIdentifierPatternByExactMatch, String ownNodeId, int pageNumber,
        int maxSubscriptionCount) throws MBeanException {

    try {
        int startingIndex = pageNumber * maxSubscriptionCount;
        String[] subscriptionArray;
        int resultSetSize = maxSubscriptionCount;
        int index = 0;
        int subscriptionDetailsIndex = 0;

        AndesSubscriptionManager subscriptionManager = AndesContext.getInstance().getAndesSubscriptionManager();

        Set<AndesSubscription> searchSubscriptionList = subscriptionManager.getFilteredSubscriptions(isDurable,
                isActive, ProtocolType.valueOf(protocolType), DestinationType.valueOf(destinationType),
                filteredNamePattern, isFilteredNameByExactMatch, identifierPattern,
                isIdentifierPatternByExactMatch, ownNodeId);

        int fullListSize = searchSubscriptionList.size() - startingIndex;

        //Get only paginated subscription from search subscription result
        if (fullListSize >= 0 && fullListSize < maxSubscriptionCount) {
            resultSetSize = (searchSubscriptionList.size() - startingIndex);
        }
        subscriptionArray = new String[resultSetSize];

        for (AndesSubscription subscription : searchSubscriptionList) {
            if (startingIndex <= index) {
                Long pendingMessageCount = MessagingEngine.getInstance()
                        .getApproximateQueueMessageCount(subscription.getStorageQueue().getName());
                subscriptionArray[subscriptionDetailsIndex] = renderSubscriptionForUI(isActive, destinationType,
                        subscription, pendingMessageCount.intValue());
                subscriptionDetailsIndex++;
                if (subscriptionDetailsIndex == maxSubscriptionCount) {
                    break;
                }
            }
            index++;
        }

        return subscriptionArray;
    } catch (Exception e) {
        log.error(
                "Error while invoking MBeans to retrieve subscription information. The given method parameters "
                        + "are: isDurable- " + isDurable + " isActive- " + isActive + " protocolType- "
                        + protocolType + " destinationType- " + destinationType + " filteredNamePattern- "
                        + filteredNamePattern + " isFilteredNameByExactMatch- " + isFilteredNameByExactMatch
                        + " identifierPattern- " + identifierPattern + " isIdentifierPatternByExactMatch- "
                        + isIdentifierPatternByExactMatch + " ownNodeId- " + ownNodeId + " pageNumber- "
                        + pageNumber + " maxSubscriptionCount- " + maxSubscriptionCount,
                e);
        throw new MBeanException(e, "Error while invoking MBeans to retrieve subscription information");
    }
}

From source file:org.skfiy.typhon.spi.GMConsoleProvider.java

/**
 * ./*from   ww  w  .j a v a2s  .c  o m*/
 *
 * @param uid ??
 * @param iid Item ID
 * @throws javax.management.MBeanException
 */
public void pushHero(final String uid, final String iid) throws MBeanException {
    try {
        invoke(transcoding(uid), new Handler() {

            @Override
            void execute() {
                //                    Player player = SessionUtils.getPlayer();
                HeroItemDobj itemDobj = itemProvider.getItem(iid);
                BagUtils.intoItem(itemDobj);
            }
        });
    } catch (Exception e) {
        throw new MBeanException(e, e.getMessage());
    }
}

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

/**
 * Unregisters the exchange from registry.
 *
 * @param exchangeName//from w  ww .jav a2 s  . c  o m
 * @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();
    }
}