List of usage examples for javax.jms XASession getXAResource
XAResource getXAResource();
From source file:org.bytesoft.bytejta.supports.serialize.XAResourceDeserializerImpl.java
private XAResource deserializeResource(String identifier, Object bean) throws Exception { if (DataSourceHolder.class.isInstance(bean)) { DataSourceHolder holder = (DataSourceHolder) bean; RecoveredResource xares = new RecoveredResource(); xares.setDataSource(holder.getDataSource()); return xares; } else if (javax.sql.DataSource.class.isInstance(bean)) { javax.sql.DataSource dataSource = (javax.sql.DataSource) bean; RecoveredResource xares = new RecoveredResource(); xares.setDataSource(dataSource); return xares; } else if (XADataSource.class.isInstance(bean)) { XADataSource xaDataSource = (XADataSource) bean; XAConnection xaConnection = null; try {//from www . j a v a 2s .c o m xaConnection = xaDataSource.getXAConnection(); return xaConnection.getXAResource(); } finally { this.closeQuietly(xaConnection); } } else if (XAConnectionFactory.class.isInstance(bean)) { XAConnectionFactory connectionFactory = (XAConnectionFactory) bean; javax.jms.XAConnection xaConnection = null; XASession xaSession = null; try { xaConnection = connectionFactory.createXAConnection(); xaSession = xaConnection.createXASession(); return xaSession.getXAResource(); } finally { this.closeQuietly(xaSession); this.closeQuietly(xaConnection); } } else if (ManagedConnectionFactory.class.isInstance(bean)) { ManagedConnectionFactory connectionFactory = (ManagedConnectionFactory) bean; ManagedConnection managedConnection = null; try { managedConnection = connectionFactory.createManagedConnection(null, null); return managedConnection.getXAResource(); } finally { this.closeQuietly(managedConnection); } } else { return null; } }
From source file:com.atomikos.jms.AtomikosJmsXaSessionProxy.java
private AtomikosJmsXaSessionProxy(XASession s, XATransactionalResource jmsTransactionalResource, SessionHandleStateChangeListener pooledConnection, SessionHandleStateChangeListener connectionProxy) { this.delegate = s; this.jmsTransactionalResource = jmsTransactionalResource; this.state = new SessionHandleState(jmsTransactionalResource, s.getXAResource()); state.registerSessionHandleStateChangeListener(pooledConnection); state.registerSessionHandleStateChangeListener(connectionProxy); state.registerSessionHandleStateChangeListener(this); //for JMS, session borrowed corresponds to creation of the session state.notifySessionBorrowed();//from w w w.j a v a2 s . co m }
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/* w w w .ja v a 2s . 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)); }
From source file:org.mule.transport.jms.xa.SessionInvocationHandler.java
private SessionInvocationHandler(XASession xaSession, Session session, Boolean sameRMOverrideValue) { super();// w w w. j a v a 2 s .c o m this.xaSession = xaSession; this.session = session; this.xaResource = new XAResourceWrapper(xaSession.getXAResource(), this, sameRMOverrideValue); }
From source file:org.soulwing.oaq.ServerSessionFactory.java
/** * {@inheritDoc}//from ww w .j a va 2 s. c om */ @Override public ServerSession makeObject() throws JMSException, UnavailableException { Validate.notNull(getSessionPool()); Validate.notNull(getConnection()); XASession session = getConnection().createXASession(); XAResource resource = session.getXAResource(); MessageEndpointProxy endpoint = new MessageEndpointProxy( details.getEndpointFactory().createEndpoint(resource)); session.setMessageListener(endpoint); return new ServerSessionWork(session, details.getWorkManager(), getSessionPool()); }