Example usage for javax.jms Session SESSION_TRANSACTED

List of usage examples for javax.jms Session SESSION_TRANSACTED

Introduction

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

Prototype

int SESSION_TRANSACTED

To view the source code for javax.jms Session SESSION_TRANSACTED.

Click Source Link

Document

This value may be passed as the argument to the method createSession(int sessionMode) on the Connection object to specify that the session should use a local transaction.

Usage

From source file:org.mule.transport.jms.Jms11Support.java

public Session createSession(Connection connection, boolean topic, boolean transacted, int ackMode,
        boolean noLocal) throws JMSException {
    return connection.createSession(transacted, (transacted ? Session.SESSION_TRANSACTED : ackMode));
}

From source file:org.springframework.integration.jms.JmsOutboundGateway.java

private void setContainerProperties(GatewayReplyListenerContainer container) {
    container.setConnectionFactory(this.connectionFactory);
    if (this.replyDestination != null) {
        container.setDestination(this.replyDestination);
    }//w  w  w .j ava 2 s.co  m
    if (StringUtils.hasText(this.replyDestinationName)) {
        container.setDestinationName(this.replyDestinationName);
    }
    if (this.destinationResolver != null) {
        container.setDestinationResolver(this.destinationResolver);
    }
    container.setPubSubDomain(this.replyPubSubDomain);
    if (this.correlationKey != null) {
        String messageSelector = this.correlationKey + " LIKE '" + this.gatewayCorrelation + "%'";
        container.setMessageSelector(messageSelector);
    }
    container.setMessageListener(this);
    if (this.replyContainerProperties != null) {
        if (this.replyContainerProperties.isSessionTransacted() != null) {
            container.setSessionTransacted(this.replyContainerProperties.isSessionTransacted());
        }
        if (this.replyContainerProperties.getCacheLevel() != null) {
            container.setCacheLevel(this.replyContainerProperties.getCacheLevel());
        }
        if (this.replyContainerProperties.getConcurrentConsumers() != null) {
            container.setConcurrentConsumers(this.replyContainerProperties.getConcurrentConsumers());
        }
        if (this.replyContainerProperties.getIdleConsumerLimit() != null) {
            container.setIdleConsumerLimit(this.replyContainerProperties.getIdleConsumerLimit());
        }
        if (this.replyContainerProperties.getIdleTaskExecutionLimit() != null) {
            container.setIdleTaskExecutionLimit(this.replyContainerProperties.getIdleTaskExecutionLimit());
        }
        if (this.replyContainerProperties.getMaxConcurrentConsumers() != null) {
            container.setMaxConcurrentConsumers(this.replyContainerProperties.getMaxConcurrentConsumers());
        }
        if (this.replyContainerProperties.getMaxMessagesPerTask() != null) {
            container.setMaxMessagesPerTask(this.replyContainerProperties.getMaxMessagesPerTask());
        }
        if (this.replyContainerProperties.getReceiveTimeout() != null) {
            container.setReceiveTimeout(this.replyContainerProperties.getReceiveTimeout());
        }
        if (this.replyContainerProperties.getRecoveryInterval() != null) {
            container.setRecoveryInterval(this.replyContainerProperties.getRecoveryInterval());
        }
        if (StringUtils.hasText(this.replyContainerProperties.getSessionAcknowledgeModeName())) {
            Integer acknowledgeMode = JmsAdapterUtils
                    .parseAcknowledgeMode(this.replyContainerProperties.getSessionAcknowledgeModeName());
            if (acknowledgeMode != null) {
                if (JmsAdapterUtils.SESSION_TRANSACTED == acknowledgeMode) {
                    container.setSessionTransacted(true);
                } else {
                    container.setSessionAcknowledgeMode(acknowledgeMode);
                }
            }
        } else if (this.replyContainerProperties.getSessionAcknowledgeMode() != null) {
            Integer sessionAcknowledgeMode = this.replyContainerProperties.getSessionAcknowledgeMode();
            if (Session.SESSION_TRANSACTED == sessionAcknowledgeMode) {
                container.setSessionTransacted(true);
            } else {
                container.setSessionAcknowledgeMode(sessionAcknowledgeMode);
            }

        }

        if (this.replyContainerProperties.getTaskExecutor() != null) {
            container.setTaskExecutor(this.replyContainerProperties.getTaskExecutor());
        } else {
            // set the beanName so the default TE threads get a meaningful name
            String containerBeanName = this.getComponentName();
            containerBeanName = ((!StringUtils.hasText(containerBeanName)
                    ? "JMS_OutboundGateway@" + ObjectUtils.getIdentityHexString(this)
                    : containerBeanName) + ".replyListener");
            container.setBeanName(containerBeanName);
        }
    }
}

From source file:org.springframework.jms.connection.SingleConnectionFactory.java

/**
 * Create a default Session for this ConnectionFactory,
 * adapting to JMS 1.0.2 style queue/topic mode if necessary.
 * @param con the JMS Connection to operate on
 * @param mode the Session acknowledgement mode
 * ({@code Session.TRANSACTED} or one of the common modes)
 * @return the newly created Session//  ww  w. ja v a 2s.c  o  m
 * @throws JMSException if thrown by the JMS API
 */
protected Session createSession(Connection con, Integer mode) throws JMSException {
    // Determine JMS API arguments...
    boolean transacted = (mode == Session.SESSION_TRANSACTED);
    int ackMode = (transacted ? Session.AUTO_ACKNOWLEDGE : mode);
    // Now actually call the appropriate JMS factory method...
    if (Boolean.FALSE.equals(this.pubSubMode) && con instanceof QueueConnection) {
        return ((QueueConnection) con).createQueueSession(transacted, ackMode);
    } else if (Boolean.TRUE.equals(this.pubSubMode) && con instanceof TopicConnection) {
        return ((TopicConnection) con).createTopicSession(transacted, ackMode);
    } else {
        return con.createSession(transacted, ackMode);
    }
}

From source file:org.springframework.jms.listener.endpoint.DefaultJmsActivationSpecFactory.java

/**
 * This implementation maps {@code SESSION_TRANSACTED} onto an
 * ActivationSpec property named "useRAManagedTransaction", if available
 * (following ActiveMQ's naming conventions).
 *///www .  j  av a  2  s. c  o m
@Override
protected void applyAcknowledgeMode(BeanWrapper bw, int ackMode) {
    if (ackMode == Session.SESSION_TRANSACTED && bw.isWritableProperty("useRAManagedTransaction")) {
        // ActiveMQ
        bw.setPropertyValue("useRAManagedTransaction", "true");
    } else {
        super.applyAcknowledgeMode(bw, ackMode);
    }
}

From source file:org.wso2.andes.systest.TestingBaseCase.java

/**
 * Create and start an asynchrounous publisher that will send MAX_QUEUE_MESSAGE_COUNT
 * messages to the provided destination. Messages are sent in a new connection
 * on a transaction. Any error is captured and the test is signalled to exit.
 *
 * @param destination//from  w  w  w .jav a  2s.  c  o m
 */
private void startPublisher(final Destination destination) {
    _publisher = new Thread(new Runnable() {

        public void run() {
            try {
                Connection connection = getConnection();
                Session session = connection.createSession(true, Session.SESSION_TRANSACTED);

                MessageProducer publisher = session.createProducer(destination);

                for (int count = 0; count < MAX_QUEUE_MESSAGE_COUNT; count++) {
                    publisher.send(createNextMessage(session, count));
                    session.commit();
                }
            } catch (Exception e) {
                _publisherError = e;
                _disconnectionLatch.countDown();
            }
        }
    });

    _publisher.start();
}

From source file:org.wso2.andes.systest.TestingBaseCase.java

/**
 * Perform the Main test of a topic Consumer with the given AckMode.
 *
 * Test creates a new connection and sets up the connection to prevent
 * failover//from  ww w. j a  v  a 2 s.c o m
 *
 * A new consumer is connected and started so that it will prefetch msgs.
 *
 * An asynchrounous publisher is started to fill the broker with messages.
 *
 * We then wait to be notified of the disconnection via the ExceptionListener
 *
 * 0-10 does not have the same notification paths but sync() apparently should
 * give us the exception, currently it doesn't, so the test is excluded from 0-10
 *
 * We should ensure that this test has the same path for all protocol versions.
 *
 * Clients should not have to modify their code based on the protocol in use.
 *
 * @param ackMode @see javax.jms.Session
 *
 * @throws Exception
 */
protected void topicConsumer(int ackMode, boolean durable) throws Exception {
    Connection connection = getConnection();

    connection.setExceptionListener(this);

    Session session = connection.createSession(ackMode == Session.SESSION_TRANSACTED, ackMode);

    _destination = session.createTopic(getName());

    MessageConsumer consumer;

    if (durable) {
        consumer = session.createDurableSubscriber(_destination, getTestQueueName());
    } else {
        consumer = session.createConsumer(_destination);
    }

    connection.start();

    // Start the consumer pre-fetching
    // Don't care about response as we will fill the broker up with messages
    // after this point and ensure that the client is disconnected at the
    // right point.
    consumer.receiveNoWait();
    startPublisher(_destination);

    boolean disconnected = _disconnectionLatch.await(DISCONNECTION_WAIT, TimeUnit.SECONDS);

    assertTrue("Client was not disconnected", disconnected);
    assertTrue("Client was not disconnected.", _connectionException != null);

    Exception linked = _connectionException.getLinkedException();

    _publisher.join(JOIN_WAIT);

    assertFalse("Publisher still running", _publisher.isAlive());

    //Validate publishing occurred ok
    if (_publisherError != null) {
        throw _publisherError;
    }

    // NOTE these exceptions will need to be modeled so that they are not
    // 0-8 specific. e.g. JMSSessionClosedException

    assertNotNull("No error received onException listener.", _connectionException);

    assertNotNull("No linked exception set on:" + _connectionException.getMessage(), linked);

    assertTrue("Incorrect linked exception received.", linked instanceof AMQException);

    AMQException amqException = (AMQException) linked;

    assertEquals("Channel was not closed with correct code.", AMQConstant.RESOURCE_ERROR,
            amqException.getErrorCode());
}

From source file:org.wso2.carbon.inbound.endpoint.protocol.jms.factory.JMSConnectionFactory.java

public JMSConnectionFactory(Properties properties) {
    try {// w w  w.  j av a2 s .  co m
        ctx = new InitialContext(properties);
    } catch (NamingException e) {
        logger.error("NamingException while obtaining initial context. " + e.getMessage(), e);
    }

    String connectionFactoryType = properties.getProperty(JMSConstants.CONNECTION_FACTORY_TYPE);
    if ("topic".equals(connectionFactoryType)) {
        this.destinationType = JMSConstants.JMSDestinationType.TOPIC;
    } else {
        this.destinationType = JMSConstants.JMSDestinationType.QUEUE;
    }

    if (properties.getProperty(JMSConstants.PARAM_JMS_SPEC_VER) == null || JMSConstants.JMS_SPEC_VERSION_1_1
            .equals(properties.getProperty(JMSConstants.PARAM_JMS_SPEC_VER))) {
        jmsSpec = JMSConstants.JMS_SPEC_VERSION_1_1;
    } else if (JMSConstants.JMS_SPEC_VERSION_2_0
            .equals(properties.getProperty(JMSConstants.PARAM_JMS_SPEC_VER))) {
        jmsSpec = JMSConstants.JMS_SPEC_VERSION_2_0;
    } else {
        jmsSpec = JMSConstants.JMS_SPEC_VERSION_1_0;
    }

    if ("true".equalsIgnoreCase(properties.getProperty(JMSConstants.PARAM_IS_SHARED_SUBSCRIPTION))) {
        isSharedSubscription = true;
    } else {
        isSharedSubscription = false;
    }

    noPubSubLocal = Boolean.valueOf(properties.getProperty(JMSConstants.PARAM_PUBSUB_NO_LOCAL));

    clientId = properties.getProperty(JMSConstants.PARAM_DURABLE_SUB_CLIENT_ID);
    subscriptionName = properties.getProperty(JMSConstants.PARAM_DURABLE_SUB_NAME);

    if (isSharedSubscription) {
        if (subscriptionName == null) {
            logger.info("Subscription name is not given. Therefor declaring a non-shared subscription");
            isSharedSubscription = false;
        }
    }

    String subDurable = properties.getProperty(JMSConstants.PARAM_SUB_DURABLE);
    if (subDurable != null) {
        isDurable = Boolean.parseBoolean(subDurable);
    }
    String msgSelector = properties.getProperty(JMSConstants.PARAM_MSG_SELECTOR);
    if (msgSelector != null) {
        messageSelector = msgSelector;
    }
    this.connectionFactoryString = properties.getProperty(JMSConstants.CONNECTION_FACTORY_JNDI_NAME);
    if (connectionFactoryString == null || "".equals(connectionFactoryString)) {
        connectionFactoryString = "QueueConnectionFactory";
    }

    this.destinationName = properties.getProperty(JMSConstants.DESTINATION_NAME);
    if (destinationName == null || "".equals(destinationName)) {
        destinationName = "QUEUE_" + System.currentTimeMillis();
    }

    String strTransactedSession = properties.getProperty(JMSConstants.SESSION_TRANSACTED);
    if (strTransactedSession == null || "".equals(strTransactedSession)
            || !strTransactedSession.equals("true")) {
        transactedSession = false;
    } else if ("true".equals(strTransactedSession)) {
        transactedSession = true;
    }

    String strSessionAck = properties.getProperty(JMSConstants.SESSION_ACK);
    if (null == strSessionAck) {
        sessionAckMode = 1;
    } else if (strSessionAck.equals("AUTO_ACKNOWLEDGE")) {
        sessionAckMode = Session.AUTO_ACKNOWLEDGE;
    } else if (strSessionAck.equals("CLIENT_ACKNOWLEDGE")) {
        sessionAckMode = Session.CLIENT_ACKNOWLEDGE;
    } else if (strSessionAck.equals("DUPS_OK_ACKNOWLEDGE")) {
        sessionAckMode = Session.DUPS_OK_ACKNOWLEDGE;
    } else if (strSessionAck.equals("SESSION_TRANSACTED")) {
        sessionAckMode = Session.SESSION_TRANSACTED;
    } else {
        sessionAckMode = 1;
    }

    createConnectionFactory();
}

From source file:tools.ConsumerTool.java

public void parseCommandLine(String[] args) {
    CommandLineParser parser = new PosixParser();

    Options options = new Options();

    Option ackModeOpt = OptionBuilder.withLongOpt("acknowledgement-mode").withArgName("ackMode").hasArg()
            .withDescription(//from w w  w .  j  a va  2s.co  m
                    "session acknowledgement mode: AUTO_ACKNOWLEDGE, CLIENT_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE")
            .create("a");
    options.addOption(ackModeOpt);

    Option browserOpt = OptionBuilder.withLongOpt("queue-browser").withDescription("create a queue browser")
            .create("b");
    options.addOption(browserOpt);

    Option clientIdOpt = OptionBuilder.withLongOpt("client-id").withArgName("id").hasArg()
            .withDescription("client id string that can optionally be set on a connection").create("c");
    options.addOption(clientIdOpt);

    Option durableOpt = OptionBuilder.withLongOpt("durable").withDescription("create a durable subscriber")
            .create("d");
    options.addOption(durableOpt);

    Option perMessageSleepOpt = OptionBuilder.withLongOpt("per-message-sleep").withArgName("millis").hasArg()
            .withDescription("amount of time (in ms) to sleep after receiving each message").create("e");
    options.addOption(perMessageSleepOpt);

    Option connFactOpt = OptionBuilder.withLongOpt("connection-factory-name").withArgName("name").hasArg()
            .withDescription("name of the connection factory to lookup").create("f");
    options.addOption(connFactOpt);

    Option numThreadsOpt = OptionBuilder.withLongOpt("num-threads").withArgName("num").hasArg()
            .withDescription("number of threads to run in parallel each with a connection").create("g");
    options.addOption(numThreadsOpt);

    Option helpOpt = OptionBuilder.withLongOpt("help").withDescription("show help").create("h");
    options.addOption(helpOpt);

    Option jndiDestOpt = OptionBuilder.withLongOpt("jndi-lookup-destination")
            .withDescription("lookup destinations with jndi").create("j");
    options.addOption(jndiDestOpt);

    Option selectorOpt = OptionBuilder.withLongOpt("message-selector").withArgName("selector").hasArg()
            .withDescription("message selector to use when creating consumer").create("k");
    options.addOption(selectorOpt);

    Option numMessagesOpt = OptionBuilder.withLongOpt("num-messages").withArgName("num").hasArg()
            .withDescription("number of messages to receive before stopping").create("m");
    options.addOption(numMessagesOpt);

    Option destNameOpt = OptionBuilder.withLongOpt("destination-name").withArgName("name").hasArg()
            .withDescription("name of the destination to receive from").create("n");
    options.addOption(destNameOpt);

    Option tempOpt = OptionBuilder.withLongOpt("temporary-destination")
            .withDescription("use a temporary destination").create("p");
    options.addOption(tempOpt);

    Option useQueueOpt = OptionBuilder.withLongOpt("queue-destination")
            .withDescription("use a queue destination").create("q");
    options.addOption(useQueueOpt);

    Option receiveTimeoutOpt = OptionBuilder.withLongOpt("receive-timeout").withArgName("millis").hasArg()
            .withDescription("blocking receive timeout (-1 indicates blocking receive call with no timeout)")
            .create("r");
    options.addOption(receiveTimeoutOpt);

    Option subscriptionOpt = OptionBuilder.withLongOpt("subscription-name").withArgName("subName").hasArg()
            .withDescription("subscription name to use when creating a durable subscriber").create("s");
    options.addOption(subscriptionOpt);

    Option transOpt = OptionBuilder.withLongOpt("transacted").withDescription("use a transacted session")
            .create("t");
    options.addOption(transOpt);

    Option asyncOpt = OptionBuilder.withLongOpt("async-listener")
            .withDescription("use an async message listener instead of consumer receive calls").create("y");
    options.addOption(asyncOpt);

    Option batchSizeOpt = OptionBuilder.withLongOpt("batch-size").withArgName("size").hasArg()
            .withDescription(
                    "size of the batch to ack or commit when using client ack mode or transacted sessions")
            .create("z");
    options.addOption(batchSizeOpt);

    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        if (line.hasOption("h")) {
            // automatically generate the help statement
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("ConsumerTool", options, true);
            System.exit(0);
        }

        if (line.hasOption("a")) {
            String ackModeStr = line.getOptionValue("a");
            if (ackModeStr.equalsIgnoreCase("AUTO_ACKNOWLEDGE")) {
                acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
            } else if (ackModeStr.equalsIgnoreCase("CLIENT_ACKNOWLEDGE")) {
                acknowledgeMode = Session.CLIENT_ACKNOWLEDGE;
            } else if (ackModeStr.equalsIgnoreCase("DUPS_OK_ACKNOWLEDGE")) {
                acknowledgeMode = Session.DUPS_OK_ACKNOWLEDGE;
            } else if (ackModeStr.equalsIgnoreCase("SESSION_TRANSACTED")) {
                acknowledgeMode = Session.SESSION_TRANSACTED;
            } else {
                throw new ParseException("Invalid value for acknowledge mode: " + ackModeStr);
            }
        }

        if (line.hasOption("b")) {
            useQueueBrowser = true;
        }

        if (line.hasOption("c")) {
            clientId = line.getOptionValue("c");
        }

        if (line.hasOption("d")) {
            durable = true;
        }

        if (line.hasOption("e")) {
            perMessageSleepMS = Integer.parseInt(line.getOptionValue("e"));
        }

        if (line.hasOption("f")) {
            connectionFactoryName = line.getOptionValue("f");
        }

        if (line.hasOption("g")) {
            numThreads = Integer.parseInt(line.getOptionValue("g"));
        }

        if (line.hasOption("j")) {
            jndiLookupDestinations = true;
        }

        if (line.hasOption("k")) {
            selector = line.getOptionValue("k");
        }

        if (line.hasOption("m")) {
            numMessages = Integer.parseInt(line.getOptionValue("m"));
        }

        if (line.hasOption("n")) {
            destinationName = line.getOptionValue("n");
        }

        if (line.hasOption("p")) {
            useTemporaryDestinations = true;
        }

        if (line.hasOption("q")) {
            useQueueDestinations = true;
        }

        if (line.hasOption("r")) {
            receiveTimeoutMS = Integer.parseInt(line.getOptionValue("r"));
        }

        if (line.hasOption("s")) {
            subscriptionName = line.getOptionValue("s");
        }

        if (line.hasOption("t")) {
            transacted = true;
        }

        if (line.hasOption("y")) {
            useAsyncListener = true;
        }

        if (line.hasOption("z")) {
            batchSize = Integer.parseInt(line.getOptionValue("z"));
        }

    } catch (ParseException exp) {
        LOGGER.error("Commandline parsing exception: " + exp.getMessage(), exp);
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("ConsumerTool", options, true);
        System.exit(-1);
    }
}

From source file:tools.ProducerTool.java

public void parseCommandLine(String[] args) {
    CommandLineParser parser = new PosixParser();

    Options options = new Options();

    Option ackModeOpt = OptionBuilder.withLongOpt("acknowledgement-mode").withArgName("ackMode").hasArg()
            .withDescription(/*w  ww.  j av  a2s. c  o m*/
                    "session acknowledgement mode: AUTO_ACKNOWLEDGE, CLIENT_ACKNOWLEDGE, DUPS_OK_ACKNOWLEDGE")
            .create("a");
    options.addOption(ackModeOpt);

    Option clientIdOpt = OptionBuilder.withLongOpt("client-id").withArgName("id").hasArg()
            .withDescription("client id string that can optionally be set on a connection").create("c");
    options.addOption(clientIdOpt);

    Option durableOpt = OptionBuilder.withLongOpt("durable").withDescription("create a durable subscriber")
            .create("d");
    options.addOption(durableOpt);

    Option perMessageSleepOpt = OptionBuilder.withLongOpt("per-message-sleep").withArgName("millis").hasArg()
            .withDescription("amount of time (in ms) to sleep after receiving each message").create("e");
    options.addOption(perMessageSleepOpt);

    Option connFactOpt = OptionBuilder.withLongOpt("connection-factory-name").withArgName("name").hasArg()
            .withDescription("name of the connection factory to lookup").create("f");
    options.addOption(connFactOpt);

    Option numThreadsOpt = OptionBuilder.withLongOpt("num-threads").withArgName("num").hasArg()
            .withDescription("number of threads to run in parallel each with a connection").create("g");
    options.addOption(numThreadsOpt);

    Option helpOpt = OptionBuilder.withLongOpt("help").withDescription("show help").create("h");
    options.addOption(helpOpt);

    Option jndiDestOpt = OptionBuilder.withLongOpt("jndi-lookup-destination")
            .withDescription("lookup destinations with jndi").create("j");
    options.addOption(jndiDestOpt);

    Option bytesLengthOpt = OptionBuilder.withLongOpt("bytes-message-length").withArgName("length").hasArg()
            .withDescription("use a bytes message of a specific length").create("l");
    options.addOption(bytesLengthOpt);

    Option numMessagesOpt = OptionBuilder.withLongOpt("num-messages").withArgName("num").hasArg()
            .withDescription("number of messages to receive before stopping").create("m");
    options.addOption(numMessagesOpt);

    Option destNameOpt = OptionBuilder.withLongOpt("destination-name").withArgName("name").hasArg()
            .withDescription("name of the destination to receive from").create("n");
    options.addOption(destNameOpt);

    Option controlOpt = OptionBuilder.withLongOpt("final-control-message")
            .withDescription("use a control message as the final message").create("o");
    options.addOption(controlOpt);

    Option tempOpt = OptionBuilder.withLongOpt("temporary-destination")
            .withDescription("use a temporary destination").create("p");
    options.addOption(tempOpt);

    Option useQueueOpt = OptionBuilder.withLongOpt("queue-destination")
            .withDescription("use a queue destination").create("q");
    options.addOption(useQueueOpt);

    Option transOpt = OptionBuilder.withLongOpt("transacted").withDescription("use a transacted session")
            .create("t");
    options.addOption(transOpt);

    Option groupIdOpt = OptionBuilder.withLongOpt("message-group-id").withArgName("groupId").hasArg()
            .withDescription("JMSXGroupID").create("x");
    options.addOption(groupIdOpt);

    Option batchSizeOpt = OptionBuilder.withLongOpt("batch-size").withArgName("size").hasArg()
            .withDescription(
                    "size of the batch to ack or commit when using client ack mode or transacted sessions")
            .create("z");
    options.addOption(batchSizeOpt);

    try {
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        if (line.hasOption("h")) {
            // automatically generate the help statement
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("ProducerTool", options, true);
            System.exit(0);
        }

        if (line.hasOption("a")) {
            String ackModeStr = line.getOptionValue("a");
            if (ackModeStr.equalsIgnoreCase("AUTO_ACKNOWLEDGE")) {
                acknowledgeMode = Session.AUTO_ACKNOWLEDGE;
            } else if (ackModeStr.equalsIgnoreCase("CLIENT_ACKNOWLEDGE")) {
                acknowledgeMode = Session.CLIENT_ACKNOWLEDGE;
            } else if (ackModeStr.equalsIgnoreCase("DUPS_OK_ACKNOWLEDGE")) {
                acknowledgeMode = Session.DUPS_OK_ACKNOWLEDGE;
            } else if (ackModeStr.equalsIgnoreCase("SESSION_TRANSACTED")) {
                acknowledgeMode = Session.SESSION_TRANSACTED;
            } else {
                throw new ParseException("Invalid value for acknowledge mode: " + ackModeStr);
            }
        }

        if (line.hasOption("c")) {
            clientId = line.getOptionValue("c");
        }

        if (line.hasOption("d")) {
            durable = true;
        }

        if (line.hasOption("e")) {
            perMessageSleepMS = Integer.parseInt(line.getOptionValue("e"));
        }

        if (line.hasOption("f")) {
            connectionFactoryName = line.getOptionValue("f");
        }

        if (line.hasOption("g")) {
            numThreads = Integer.parseInt(line.getOptionValue("g"));
        }

        if (line.hasOption("j")) {
            jndiLookupDestinations = true;
        }

        if (line.hasOption("l")) {
            bytesLength = Integer.parseInt(line.getOptionValue("l"));
        }

        if (line.hasOption("m")) {
            numMessages = Integer.parseInt(line.getOptionValue("m"));
        }

        if (line.hasOption("n")) {
            destinationName = line.getOptionValue("n");
        }

        if (line.hasOption("o")) {
            useFinalControlMessage = true;
        }

        if (line.hasOption("p")) {
            useTemporaryDestinations = true;
        }

        if (line.hasOption("q")) {
            useQueueDestinations = true;
        }

        if (line.hasOption("t")) {
            transacted = true;
        }

        if (line.hasOption("x")) {
            messageGroupId = line.getOptionValue("x");
        }

        if (line.hasOption("z")) {
            batchSize = Integer.parseInt(line.getOptionValue("z"));
        }

    } catch (ParseException exp) {
        LOGGER.error("Commandline parsing exception: " + exp.getMessage(), exp);
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("ProducerTool", options, true);
        System.exit(-1);
    }
}