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.QueueManagementInformationMBean.java

/**
 * {@inheritDoc}/*from  ww  w. ja v a  2 s .  com*/
 */
@Override
public CompositeData[] getMessagesInDLCForQueue(
        @MBeanOperationParameter(name = "queueName", description = "Name of queue to browse "
                + "messages") String queueName,
        @MBeanOperationParameter(name = "lastMsgId", description = "Browse message this "
                + "onwards") long nextMsgId,
        @MBeanOperationParameter(name = "maxMsgCount", description = "Maximum message count "
                + "per request") int maxMessageCount)
        throws MBeanException {

    try {

        List<AndesMessageMetadata> nextNMessageMetadataFromQueue;
        if (!DLCQueueUtils.isDeadLetterQueue(queueName)) {
            nextNMessageMetadataFromQueue = Andes.getInstance().getNextNMessageMetadataInDLCForQueue(queueName,
                    DLCQueueUtils.identifyTenantInformationAndGenerateDLCString(queueName), nextMsgId,
                    maxMessageCount);
        } else {
            nextNMessageMetadataFromQueue = Andes.getInstance().getNextNMessageMetadataFromDLC(
                    DLCQueueUtils.identifyTenantInformationAndGenerateDLCString(queueName), nextMsgId,
                    maxMessageCount);
        }
        return getDisplayableMetaData(nextNMessageMetadataFromQueue, true);
    } catch (AndesException e) {
        throw new MBeanException(e, "Error occurred in browse queue.");
    }

}

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

/**
 * We are returning message count to the UI from this method.
 * When it has received Acks from the clients more than the message actual
 * message in the  queue,( This can happen when a copy of a message get
 * delivered to the consumer while the ACK for the previouse message was
 * on the way back to server), Message count is becoming minus.
 * <p>//from w w w.  j a v  a 2  s .  co m
 * So from now on , we ll not provide minus values to the front end since
 * it is not acceptable
 */
public long getMessageCount(String queueName, String msgPattern) throws MBeanException {

    if (log.isDebugEnabled()) {
        log.debug("Counting at queue : " + queueName);
    }

    long messageCount = 0;
    try {
        if (!DLCQueueUtils.isDeadLetterQueue(queueName)) {
            if ("queue".equals(msgPattern)) {
                messageCount = Andes.getInstance().getMessageCountOfQueue(queueName);
            }
        } else {
            messageCount = Andes.getInstance().getMessageCountInDLC(queueName);
        }

    } catch (AndesException e) {
        log.error(MESSAGE_COUNT_RETRIEVE_ERROR + queueName, e);
        throw new MBeanException(e, MESSAGE_COUNT_RETRIEVE_ERROR + queueName);
    }

    return messageCount;
}

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

/**
 * Get DLC queue by name specified if already created
 *
 * @param queueName name of the DLc queue (including tenant information)
 * @return a Map with <DLCQueueName,MessageCount> entry
 *//*  w  w w. j  a va  2 s  . co  m*/
public Map<String, Long> getDLCQueueInformation(String queueName) throws MBeanException {

    Map<String, Long> DLCQueueInformation;

    try {
        DLCQueueInformation = new HashMap<>(1);

        AndesMessageRouter DLCMessageRouter = AndesContext.getInstance().getMessageRouterRegistry()
                .getMessageRouter(AMQPUtils.DLC_EXCHANGE_NAME);

        List<StorageQueue> DLCQueues = DLCMessageRouter.getAllBoundQueues();

        for (StorageQueue dlcQueue : DLCQueues) {
            if (queueName.equals(dlcQueue.getName())) {
                DLCQueueInformation.put(dlcQueue.getName(), dlcQueue.getMessageCount());
                break;
            }
        }
    } catch (AndesException e) {
        throw new MBeanException(e, "Error while receiving DLC queue Information from MBeans");
    }

    return DLCQueueInformation;
}

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

/**
 * Method to display a list of messages when browsed.
 *
 * @param metadataList the list of message metadata
 * @return Composite data array of properties of all messages
 * @throws MBeanException if an OpenDataException occurs while mapping JMS headers for the Message.
 *//*from w w  w  .  java2 s.c o  m*/
private CompositeData[] getDisplayableMetaData(List<AndesMessageMetadata> metadataList, boolean includeContent)
        throws MBeanException {
    List<CompositeData> compositeDataList = new ArrayList<>();
    try {
        for (AndesMessageMetadata andesMessageMetadata : metadataList) {
            Object[] itemValues = getItemValues(andesMessageMetadata, includeContent);
            if (null != itemValues) {
                CompositeDataSupport support = new CompositeDataSupport(_msgContentType,
                        VIEW_MSG_CONTENT_COMPOSITE_ITEM_NAMES_DESC.toArray(
                                new String[VIEW_MSG_CONTENT_COMPOSITE_ITEM_NAMES_DESC.size()]),
                        itemValues);
                compositeDataList.add(support);
            }
        }
    } catch (OpenDataException exception) {
        throw new MBeanException(exception, "Error occurred when formatting message in queue.");
    }
    return compositeDataList.toArray(new CompositeData[compositeDataList.size()]);
}

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

/**
 * Method to get an array of properties of a single message.
 *
 * @param andesMessageMetadata andes message metadata to be parsed
 * @return an array of properties of the message
 * @throws MBeanException if an AMQException occurs while reading Message Content headers.
 *//* w ww.  j  a v a 2  s. co  m*/
private Object[] getItemValues(AndesMessageMetadata andesMessageMetadata, boolean includeContent)
        throws MBeanException {
    try {

        Object[] itemValues = null;
        //get AMQMessage from AndesMessageMetadata
        AMQMessage amqMessage = AMQPUtils.getAMQMessageFromAndesMetaData(andesMessageMetadata);
        //header properties from AMQMessage
        BasicContentHeaderProperties properties = (BasicContentHeaderProperties) amqMessage
                .getContentHeaderBody().getProperties();
        //get custom header properties of AMQMessage
        StringBuilder stringBuilder = new StringBuilder();
        for (String headerKey : properties.getHeaders().keys()) {
            stringBuilder.append(headerKey).append(" = ").append(properties.getHeaders().get(headerKey));
            stringBuilder.append(", ");
        }
        if (null != properties.getCorrelationId()) {
            stringBuilder.append("JMSCorrelationID").append(" = ").append(properties.getCorrelationId())
                    .append(", ");
        }
        if (null != properties.getReplyTo()) {
            stringBuilder.append("JMSReplyTo").append(" = ").append(properties.getReplyTo()).append(", ");
        }
        if (null != properties.getType()) {
            stringBuilder.append("JMSType").append(" = ").append(properties.getType()).append(", ");
        }
        String msgProperties = stringBuilder.toString();
        //get content type
        String contentType = properties.getContentTypeAsString();
        //get message id
        String messageId = properties.getMessageIdAsString();
        //get redelivered
        boolean redelivered = false;
        //get timestamp
        long timeStamp = properties.getTimestamp();
        //get destination
        String destination = andesMessageMetadata.getDestination();
        //get AndesMessageMetadata id
        long andesMessageMetadataId = andesMessageMetadata.getMessageID();

        //content is constructing
        final int bodySize = (int) amqMessage.getSize();

        if (includeContent) {
            AndesMessagePart constructedContent = constructContent(bodySize, amqMessage);
            byte[] messageContent = constructedContent.getData();
            int position = constructedContent.getOffset();
            //if position did not proceed, there is an error receiving content. If not, decode content
            if (!((bodySize != 0) && (position == 0))) {
                String[] content = decodeContent(amqMessage, messageContent);
                //set content type of message to readable name
                contentType = getReadableNameForMessageContentType(contentType);
                //set CompositeData of message
                itemValues = new Object[] { msgProperties, contentType, content, messageId, redelivered,
                        timeStamp, destination, andesMessageMetadataId };
            } else if (bodySize == 0) { //empty message
                itemValues = new Object[] { msgProperties, contentType, "", messageId, redelivered, timeStamp,
                        destination, andesMessageMetadataId };
            }
        } else {
            itemValues = new Object[] { msgProperties, contentType, new String[] {}, messageId, redelivered,
                    timeStamp, destination, andesMessageMetadataId };
        }
        return itemValues;
    } catch (AMQException exception) {
        throw new MBeanException(exception,
                "Error occurred when formatting message with Id : " + andesMessageMetadata.getMessageID()
                        + " assigned to queue : " + andesMessageMetadata.getDestination());
    }
}

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

/**
 * Method to construct message body of a single message.
 *
 * @param bodySize   Original content size of the message
 * @param amqMessage AMQMessage//from   w  w w .j ava2s . co  m
 * @return Message content and last position of written data as an AndesMessagePart
 * @throws MBeanException
 */
private AndesMessagePart constructContent(int bodySize, AMQMessage amqMessage) throws MBeanException {

    AndesMessagePart andesMessagePart;

    if (amqMessage.getMessageMetaData().isCompressed()) {
        /* If the current message was compressed by the server, decompress the message content and, get it as an
         * AndesMessagePart
         */
        long messageID = amqMessage.getMessageId();
        LongArrayList messList = new LongArrayList();
        messList.add(messageID);

        try {
            LongObjectHashMap<List<AndesMessagePart>> contentListMap = MessagingEngine.getInstance()
                    .getContent(messList);
            List<AndesMessagePart> contentList = contentListMap.get(messageID);

            andesMessagePart = lz4CompressionHelper.getDecompressedMessage(contentList, bodySize);

        } catch (AndesException e) {
            throw new MBeanException(e, "Error occurred while construct the message content. Message ID:"
                    + amqMessage.getMessageId());
        }
    } else {
        byte[] messageContent = new byte[bodySize];

        //Getting a buffer, to write data into the byte array and to the buffer at the same time
        java.nio.ByteBuffer buffer = java.nio.ByteBuffer.wrap(messageContent);

        int position = 0;

        while (position < bodySize) {
            position = position + amqMessage.getContent(buffer, position);

            //If position did not proceed, there is an error receiving content
            if ((0 != bodySize) && (0 == position)) {
                break;
            }

            //The limit is setting to the current position and then the position of the buffer is setting to zero
            buffer.flip();

            //The position of the buffer is setting to zero, the limit is setting to the capacity
            buffer.clear();
        }

        andesMessagePart = new AndesMessagePart();
        andesMessagePart.setData(messageContent);
        andesMessagePart.setOffSet(position);
    }

    return andesMessagePart;
}

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

/**
 * Method to decode content of a single message into text
 *
 * @param amqMessage     the message of which content need to be decoded
 * @param messageContent the byte array of message content to be decoded
 * @return A string array representing the decoded message content
 * @throws MBeanException/*from w w w.j a  v a 2  s. c o  m*/
 */
private String[] decodeContent(AMQMessage amqMessage, byte[] messageContent) throws MBeanException {

    try {
        //get encoding
        String encoding = amqMessage.getMessageHeader().getEncoding();
        if (encoding == null) {
            encoding = "UTF-8";
        }
        //get mime type of message
        String mimeType = amqMessage.getMessageHeader().getMimeType();
        // setting default mime type
        if (StringUtils.isBlank(mimeType)) {
            mimeType = MIME_TYPE_TEXT_PLAIN;
        }
        //create message content to readable text from ByteBuffer
        ByteBuffer wrapMsgContent = ByteBuffer.wrap(messageContent);
        String content[] = new String[2];
        String summaryMsg = "";
        String wholeMsg = "";

        //get TextMessage content to display
        if (mimeType.equals(MIME_TYPE_TEXT_PLAIN) || mimeType.equals(MIMI_TYPE_TEXT_XML)) {
            wholeMsg = extractTextMessageContent(wrapMsgContent, encoding);
            //get ByteMessage content to display
        } else if (mimeType.equals(MIME_TYPE_APPLICATION_JAVA_OBJECT_STREAM)
                || mimeType.equals(MIME_TYPE_APPLICATION_OCTET_STREAM)) {
            wholeMsg = "This Operation is Not Supported!";
            //get StreamMessage content to display
        } else if (mimeType.equals(MIME_TYPE_JMS_STREAM_MESSAGE)) {
            wholeMsg = extractStreamMessageContent(wrapMsgContent, encoding);
            //get MapMessage content to display
        } else if (mimeType.equals(MIME_TYPE_AMQP_MAP) || mimeType.equals(MIME_TYPE_JMS_MAP_MESSAGE)) {
            wholeMsg = extractMapMessageContent(wrapMsgContent);
        }
        //trim content to summary and whole message
        if (wholeMsg.length() >= CHARACTERS_TO_SHOW) {
            summaryMsg = wholeMsg.substring(0, CHARACTERS_TO_SHOW);
        } else {
            summaryMsg = wholeMsg;
        }
        if (wholeMsg.length() > MESSAGE_DISPLAY_LENGTH_MAX) {
            wholeMsg = wholeMsg.substring(0, MESSAGE_DISPLAY_LENGTH_MAX - 3) + DISPLAY_CONTINUATION
                    + DISPLAY_LENGTH_EXCEEDED;
        }
        content[0] = summaryMsg;
        content[1] = wholeMsg;
        return content;
    } catch (CharacterCodingException exception) {
        throw new MBeanException(exception, "Error occurred in browse queue.");
    }
}

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

/***
 * {@inheritDoc}/*www.java 2s.  c  o m*/
 */
@Override
public CompositeData[] getMessageMetadataInDeadLetterChannel(
        @MBeanOperationParameter(name = "targetQueue", description = "Name of destination queue ") String targetQueue,
        @MBeanOperationParameter(name = "startMessageId", description = "Message Id to start the resultset with.") long startMessageId,
        @MBeanOperationParameter(name = "pageLimit", description = "Maximum message count required in a single response") int pageLimit)
        throws MBeanException {

    try {
        List<AndesMessageMetadata> nextNMessageMetadataFromQueue;

        if (!DLCQueueUtils.isDeadLetterQueue(targetQueue)) {
            nextNMessageMetadataFromQueue = Andes.getInstance().getNextNMessageMetadataInDLCForQueue(
                    targetQueue, DLCQueueUtils.identifyTenantInformationAndGenerateDLCString(targetQueue),
                    startMessageId, pageLimit);
        } else {
            nextNMessageMetadataFromQueue = Andes.getInstance().getNextNMessageMetadataFromDLC(
                    DLCQueueUtils.identifyTenantInformationAndGenerateDLCString(targetQueue), startMessageId,
                    pageLimit);
        }
        return getDisplayableMetaData(nextNMessageMetadataFromQueue, false);

    } catch (AndesException e) {
        throw new MBeanException(e, "Error occurred when listing metadata in DLC for queue : " + targetQueue
                + " from message Id : " + startMessageId + " onwards.");
    }
}

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

/***
 * {@inheritDoc}//from   w  w  w.  j ava  2s .c om
 */
@Override
public int rerouteAllMessagesInDeadLetterChannelForQueue(
        @MBeanOperationParameter(name = "sourceQueue", description = "Name of the source queue") String sourceQueue,
        @MBeanOperationParameter(name = "targetQueue", description = "Name of the target queue") String targetQueue,
        @MBeanOperationParameter(name = "internalBatchSize", description = "Number of messages processed in a "
                + "single database call.") int internalBatchSize)
        throws MBeanException {

    List<Long> currentMessageIdList;
    Long lastMessageId = 0L;
    int movedMessageCount = 0;

    // Get full name of Dead Letter Channel
    String dlcQueueName = DLCQueueUtils.identifyTenantInformationAndGenerateDLCString(sourceQueue);

    try {
        if (DLCQueueUtils.isDeadLetterQueue(sourceQueue)) {
            currentMessageIdList = Andes.getInstance().getNextNMessageIdsInDLC(dlcQueueName, lastMessageId,
                    internalBatchSize);

            while (currentMessageIdList.size() > 0) {
                int movedMessageCountInThisBatch = moveMessagesFromDLCToNewDestination(currentMessageIdList,
                        sourceQueue, targetQueue, false);

                if (log.isDebugEnabled()) {
                    log.debug("Successfully restored messages from DLC to targetQueue: " + targetQueue
                            + " movedMessageCountInThisBatch : " + movedMessageCountInThisBatch);
                }

                movedMessageCount = movedMessageCount + movedMessageCountInThisBatch;
                lastMessageId = currentMessageIdList.get(currentMessageIdList.size() - 1);

                currentMessageIdList = Andes.getInstance().getNextNMessageIdsInDLC(dlcQueueName, lastMessageId,
                        internalBatchSize);
            }
        } else {
            currentMessageIdList = Andes.getInstance().getNextNMessageIdsInDLCForQueue(sourceQueue,
                    dlcQueueName, lastMessageId, internalBatchSize);

            while (currentMessageIdList.size() > 0) {
                int movedMessageCountInThisBatch = moveMessagesFromDLCToNewDestination(currentMessageIdList,
                        sourceQueue, targetQueue, false);

                if (log.isDebugEnabled()) {
                    log.debug("Successfully restored messages from sourceQueue : " + sourceQueue
                            + " to targetQueue : " + targetQueue + " movedMessageCountInThisBatch : "
                            + movedMessageCountInThisBatch);
                }

                movedMessageCount = movedMessageCount + movedMessageCountInThisBatch;
                lastMessageId = currentMessageIdList.get(currentMessageIdList.size() - 1);

                currentMessageIdList = Andes.getInstance().getNextNMessageIdsInDLCForQueue(sourceQueue,
                        dlcQueueName, lastMessageId, internalBatchSize);
            }
        }
    } catch (AndesException ex) {
        throw new MBeanException(ex,
                "Error occurred when moving metadata destined to sourceQueue : " + sourceQueue
                        + " from DLC to targetQueue : " + targetQueue + ". movedMessageCount : "
                        + movedMessageCount);
    }

    return movedMessageCount;
}