List of usage examples for javax.jms XASession createTextMessage
TextMessage createTextMessage(String text) throws JMSException;
From source file:org.apache.activemq.bugs.AMQ7067Test.java
protected static void createDanglingTransaction(XAResource xaRes, XASession xaSession, Queue queue) throws JMSException, IOException, XAException { MessageProducer producer = xaSession.createProducer(queue); XATransactionId txId = createXATransaction(); xaRes.start(txId, TMNOFLAGS);//from ww w . j a v a2 s . c o m TextMessage helloMessage = xaSession.createTextMessage(StringUtils.repeat("dangler", 10)); producer.send(helloMessage); xaRes.end(txId, TMSUCCESS); xaRes.prepare(txId); System.out.println("****** createDanglingTransaction txId = " + txId); }
From source file:org.apache.activemq.bugs.AMQ7067Test.java
protected static void produce(XAResource xaRes, XASession xaSession, Queue queue, int messageCount, int messageSize) throws JMSException, IOException, XAException { MessageProducer producer = xaSession.createProducer(queue); for (int i = 0; i < messageCount; i++) { XATransactionId txid = createXATransaction(); xaRes.start(txid, TMNOFLAGS);//from w w w . j a va2s . c o m TextMessage helloMessage = xaSession.createTextMessage(StringUtils.repeat("a", messageSize)); producer.send(helloMessage); xaRes.end(txid, TMSUCCESS); xaRes.commit(txid, true); } }
From source file:org.apache.activemq.store.jdbc.JDBCCleanupLimitedPoolTest.java
@Test public void testNoDeadlockOnXaPoolExhaustion() throws Exception { final CountDownLatch done = new CountDownLatch(1); final CountDownLatch doneCommit = new CountDownLatch(1000); final ActiveMQXAConnectionFactory factory = new ActiveMQXAConnectionFactory( broker.getTransportConnectorByScheme("tcp").getPublishableConnectString()); ExecutorService executorService = Executors.newCachedThreadPool(); // some contention over pool of 2 for (int i = 0; i < 3; i++) { executorService.execute(new Runnable() { @Override//from w w w . j a va 2 s. c o m public void run() { try { ActiveMQXAConnection conn = (ActiveMQXAConnection) factory.createXAConnection(); conn.start(); XASession sess = conn.createXASession(); while (done.getCount() > 0 && doneCommit.getCount() > 0) { Xid xid = createXid(); sess.getXAResource().start(xid, XAResource.TMNOFLAGS); MessageProducer producer = sess.createProducer(sess.createQueue("test")); producer.send(sess.createTextMessage("test")); sess.getXAResource().end(xid, XAResource.TMSUCCESS); sess.getXAResource().prepare(xid); sess.getXAResource().commit(xid, false); doneCommit.countDown(); } conn.close(); } catch (Exception ignored) { ignored.printStackTrace(); } } }); } executorService.execute(new Runnable() { @Override public void run() { try { while (!done.await(10, TimeUnit.MILLISECONDS) && doneCommit.getCount() > 0) { jdbcPersistenceAdapter.cleanup(); } } catch (Exception ignored) { } } }); executorService.shutdown(); boolean allComplete = executorService.awaitTermination(40, TimeUnit.SECONDS); done.countDown(); assertTrue("all complete", allComplete); executorService.shutdownNow(); assertTrue("xa tx done", doneCommit.await(10, TimeUnit.SECONDS)); }