Example usage for javax.jms JMSException JMSException

List of usage examples for javax.jms JMSException JMSException

Introduction

In this page you can find the example usage for javax.jms JMSException JMSException.

Prototype

public JMSException(String reason) 

Source Link

Document

Constructs a JMSException with the specified reason and with the error code defaulting to null.

Usage

From source file:edu.psu.citeseerx.messaging.MsgService.java

/**
 * Creates a consumer for a given type of channel, either queue or topic.
 * @param provider/*from w w  w . j a v a 2 s . co  m*/
 * @param name channel name
 * @param type consumer or producer
 * @param mode message acknowledgement mode
 * @throws JMSException
 */
protected void createConsumer(JMSProvider provider, String name, int type, int mode) throws JMSException {

    JMSReceiver receiver = new JMSReceiver(name);
    switch (type) {
    case QUEUE:
        System.out.println("Configuring consumer for queue: " + name);
        receiver.initializeQueue(provider, mode);
        break;
    case TOPIC:
        System.out.println("Configuring consumer for topic: " + name);
        receiver.initializeTopic(provider, mode);
        break;
    default:
        throw new JMSException("Invalid channel type specified");
    }
    jmsReceivers.put(name, receiver);

}

From source file:edu.psu.citeseerx.messaging.MsgService.java

/**
 * Creates a producer for a given type of channel, either queue or topic.
 * @param provider//from  ww  w.  ja  va 2 s  .c o  m
 * @param name channel name
 * @param type consumer or producer
 * @param mode message acknowledgement mode
 * @throws JMSException
 */
protected void createProducer(JMSProvider provider, String name, int type, int mode) throws JMSException {

    JMSSender sender = new JMSSender(name);
    switch (type) {
    case QUEUE:
        System.out.println("Configuring producer for queue: " + name);
        sender.initializeQueue(provider, mode);
        break;
    case TOPIC:
        System.out.println("Configuring producer for topic: " + name);
        sender.initializeTopic(provider, mode);
        break;
    default:
        throw new JMSException("Invalid channel type specified");
    }
    jmsSenders.put(name, sender);

}

From source file:com.mirth.connect.connectors.jms.JmsConnector.java

public Session getSession(boolean transacted, boolean topic) throws JMSException {
    if (!isConnected()) {
        throw new JMSException("Not connected");
    }//from  w ww  .ja  v  a  2s .c o m
    UMOTransaction tx = TransactionCoordination.getInstance().getTransaction();
    Session session = getCurrentSession();
    if (session != null) {
        logger.debug("Retrieving jms session from current transaction");
        return session;
    }
    logger.debug("Retrieving new jms session from connection");
    session = jmsSupport.createSession(connection, topic, transacted || tx != null, acknowledgementMode,
            noLocal);
    if (tx != null) {
        logger.debug("Binding session to current transaction");
        try {
            tx.bindResource(connection, session);
        } catch (TransactionException e) {
            throw new RuntimeException("Could not bind session to current transaction", e);
        }
    }
    return session;
}

From source file:com.amazon.sqs.javamessaging.SQSMessageConsumerPrefetch.java

/**
 * Convert the return SQS message into JMS message
 * @param message SQS message to convert
 * @return Converted JMS message//from   www . j  a  va2  s. c  om
 * @throws JMSException
 */
protected javax.jms.Message convertToJMSMessage(Message message) throws JMSException {
    MessageAttributeValue messageTypeAttribute = message.getMessageAttributes()
            .get(SQSMessage.JMS_SQS_MESSAGE_TYPE);
    javax.jms.Message jmsMessage = null;
    if (messageTypeAttribute == null) {
        jmsMessage = new SQSTextMessage(acknowledger, queueUrl, message);
    } else {
        String messageType = messageTypeAttribute.getStringValue();
        if (SQSMessage.BYTE_MESSAGE_TYPE.equals(messageType)) {
            try {
                jmsMessage = new SQSBytesMessage(acknowledger, queueUrl, message);
            } catch (JMSException e) {
                LOG.warn("MessageReceiptHandle - " + message.getReceiptHandle()
                        + "cannot be serialized to BytesMessage", e);
                throw e;
            }
        } else if (SQSMessage.OBJECT_MESSAGE_TYPE.equals(messageType)) {
            jmsMessage = new SQSObjectMessage(acknowledger, queueUrl, message);
        } else if (SQSMessage.TEXT_MESSAGE_TYPE.equals(messageType)) {
            jmsMessage = new SQSTextMessage(acknowledger, queueUrl, message);
        } else {
            throw new JMSException("Not a supported JMS message type");
        }
    }
    jmsMessage.setJMSDestination(sqsDestination);
    return jmsMessage;
}

From source file:com.amazon.sqs.javamessaging.SQSSession.java

/**
 * Creates a <code>MessageProducer</code> for the specified destination.
 * Only queue destinations are supported at this time.
 * //  w  w  w . jav a  2 s. c om
 * @param destination
 *            a queue destination
 * @return new message producer
 * @throws JMSException
 *             If session is closed or queue destination is not used
 */
@Override
public MessageProducer createProducer(Destination destination) throws JMSException {
    checkClosed();
    if (destination != null && !(destination instanceof SQSQueueDestination)) {
        throw new JMSException("Actual type of Destination/Queue has to be SQSQueueDestination");
    }
    SQSMessageProducer messageProducer;
    synchronized (stateLock) {
        checkClosing();
        messageProducer = new SQSMessageProducer(amazonSQSClient, this, (SQSQueueDestination) destination);
        messageProducers.add(messageProducer);
    }
    return messageProducer;
}

From source file:com.amazon.sqs.javamessaging.SQSMessageConsumerPrefetch.java

private boolean cannotDeliver() throws JMSException {
    if (isClosed() || !running) {
        return true;
    }/*  w  w  w. j  ava  2  s  .co  m*/
    if (messageListener != null) {
        throw new JMSException("Cannot receive messages synchronously after a message listener is set");
    }
    return false;
}

From source file:com.amazon.sqs.javamessaging.SQSSession.java

/**
 * Creates a <code>MessageConsumer</code> for the specified destination.
 * Only queue destinations are supported at this time.
 * //from   w w  w  .ja  v a2 s.co  m
 * @param destination
 *            a queue destination
 * @return new message consumer
 * @throws JMSException
 *             If session is closed or queue destination is not used
 */
@Override
public MessageConsumer createConsumer(Destination destination) throws JMSException {
    checkClosed();
    if (!(destination instanceof SQSQueueDestination)) {
        throw new JMSException("Actual type of Destination/Queue has to be SQSQueueDestination");
    }
    SQSMessageConsumer messageConsumer;
    synchronized (stateLock) {
        checkClosing();
        messageConsumer = createSQSMessageConsumer((SQSQueueDestination) destination);
        messageConsumers.add(messageConsumer);
        if (running) {
            messageConsumer.startPrefetch();
        }
    }
    return messageConsumer;
}

From source file:com.amazon.sqs.javamessaging.SQSConnection.java

/** This method is not supported. */
@Override//from   w  w w.  j  av a2  s.  c o  m
public ConnectionConsumer createConnectionConsumer(Destination destination, String messageSelector,
        ServerSessionPool sessionPool, int maxMessages) throws JMSException {
    throw new JMSException(SQSMessagingClientConstants.UNSUPPORTED_METHOD);
}

From source file:com.amazon.sqs.javamessaging.SQSConnection.java

/** This method is not supported. */
@Override//from   ww  w  . j a  v  a 2s .co  m
public ConnectionConsumer createDurableConnectionConsumer(Topic topic, String subscriptionName,
        String messageSelector, ServerSessionPool sessionPool, int maxMessages) throws JMSException {
    throw new JMSException(SQSMessagingClientConstants.UNSUPPORTED_METHOD);
}

From source file:com.amazon.sqs.javamessaging.SQSConnection.java

/** This method is not supported. */
@Override//from  ww  w  .j  a v  a  2 s.c o  m
public ConnectionConsumer createConnectionConsumer(Queue queue, String messageSelector,
        ServerSessionPool sessionPool, int maxMessages) throws JMSException {
    throw new JMSException(SQSMessagingClientConstants.UNSUPPORTED_METHOD);
}