managedConnectionFactory.stop();
/** * Creates a Connection Factory instance * * @return javax.resource.cci.ConnectionFactory instance * @throws ResourceException Thrown if a connection factory can't be created */ @Override public Object createConnectionFactory() throws ResourceException { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.debug("createConnectionFactory()"); } return createConnectionFactory(new ActiveMQRAConnectionManager()); }
/** * Get the connection metadata * * @return The connection metadata * @throws JMSException Thrown if an error occurs */ @Override public ConnectionMetaData getMetaData() throws JMSException { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("getMetaData()"); } checkClosed(); return mcf.getMetaData(); }
/** * Indicates whether some other object is "equal to" this one. * * @param obj Object with which to compare * @return True if this object is the same as the obj argument; false otherwise. */ @Override public boolean equals(final Object obj) { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("equals(" + obj + ")"); } if (obj == null) { return false; } if (obj instanceof ActiveMQRAManagedConnectionFactory) { ActiveMQRAManagedConnectionFactory other = (ActiveMQRAManagedConnectionFactory) obj; return mcfProperties.equals(other.getProperties()) && ra.equals(other.getResourceAdapter()); } else { return false; } }
@Test public void testJMSContext() throws Exception { resourceAdapter = newResourceAdapter(); MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setResourceAdapter(resourceAdapter); ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); JMSContext jmsctx = qraConnectionFactory.createContext(JMSContext.DUPS_OK_ACKNOWLEDGE); assertEquals(JMSContext.DUPS_OK_ACKNOWLEDGE, jmsctx.getSessionMode()); }
@Test public void testSimpleMessageSendAndReceiveNotTransacted() throws Exception { setupDLQ(10); resourceAdapter = newResourceAdapter(); MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setAllowLocalTransactions(true); mcf.setResourceAdapter(resourceAdapter); ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); QueueConnection queueConnection = qraConnectionFactory.createQueueConnection(); Session s = queueConnection.createSession(false, Session.SESSION_TRANSACTED); Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE); MessageProducer mp = s.createProducer(q); MessageConsumer consumer = s.createConsumer(q); Message message = s.createTextMessage("test"); mp.send(message); s.commit(); queueConnection.start(); TextMessage textMessage = (TextMessage) consumer.receive(1000); assertNotNull(textMessage); assertEquals(textMessage.getText(), "test"); s.rollback(); textMessage = (TextMessage) consumer.receive(1000); assertNotNull(textMessage); assertEquals(textMessage.getText(), "test"); s.commit(); textMessage = (TextMessage) consumer.receiveNoWait(); assertNull(textMessage); }
MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setResourceAdapter(resourceAdapter); ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); queueconn.close(); mcf.stop();
@Test public void testConnectionCredentialsOKRecovery() throws Exception { resourceAdapter = newResourceAdapter(); MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setResourceAdapter(resourceAdapter); ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); QueueConnection queueConnection = qraConnectionFactory.createQueueConnection(); QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE); assertNotNull(mcf.getResourceRecovery()); }
if (!mcf.isIgnoreJTA() && inJtaTransaction()) { transacted = true; if (transacted && mcf.isAllowLocalTransactions()) { acknowledgeMode = Session.SESSION_TRANSACTED; } else { if (!mcf.isAllowLocalTransactions()) { throw ActiveMQRABundle.BUNDLE.invalidSessionTransactedModeRuntimeAllowLocal(); info.setPassword(password); info.setClientID(clientID); info.setDefaults(((ActiveMQResourceAdapter) mcf.getResourceAdapter()).getProperties());
/** * Creates a new physical connection to the underlying EIS resource manager. * * @param subject Caller's security information * @param cxRequestInfo Additional resource adapter specific connection request information * @return The managed connection * @throws ResourceException Thrown if a managed connection can't be created */ @Override public ManagedConnection createManagedConnection(final Subject subject, final ConnectionRequestInfo cxRequestInfo) throws ResourceException { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("createManagedConnection(" + subject + ", " + cxRequestInfo + ")"); } ActiveMQRAConnectionRequestInfo cri = getCRI((ActiveMQRAConnectionRequestInfo) cxRequestInfo); ActiveMQRACredential credential = ActiveMQRACredential.getCredential(this, subject, cri); if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("jms credential: " + credential); } ActiveMQRAManagedConnection mc = new ActiveMQRAManagedConnection(this, cri, ra, credential.getUserName(), credential.getPassword()); if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("created new managed connection: " + mc); } registerRecovery(); return mc; }
@Override public ActiveMQResourceAdapter getResourceAdapter() { return (ActiveMQResourceAdapter) mcf.getResourceAdapter(); } }
@Test public void testValidateProperties() throws Exception { validateGettersAndSetters(new ActiveMQResourceAdapter(), "backupTransportConfiguration", "connectionParameters", "jndiParams"); validateGettersAndSetters(new ActiveMQRAManagedConnectionFactory(), "connectionParameters", "sessionDefaultType", "backupConnectionParameters", "jndiParams"); validateGettersAndSetters(new ActiveMQActivationSpec(), "connectionParameters", "acknowledgeMode", "subscriptionDurability", "jndiParams", "maxSession");
private void createCF() { if (connectionFactory == null) { connectionFactory = ra.getConnectionFactory(mcf.getProperties()); } }
/** * Aqquire a lock on the managed connection within the specified period * * @throws JMSException Thrown if an error occurs */ protected void tryLock() throws JMSException { if (logger.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("tryLock()"); } Integer tryLock = mcf.getUseTryLock(); if (tryLock == null || tryLock.intValue() <= 0) { lock(); return; } try { if (lock.tryLock(tryLock.intValue(), TimeUnit.SECONDS) == false) { throw new ResourceAllocationException("Unable to obtain lock in " + tryLock + " seconds: " + this); } } catch (InterruptedException e) { throw new ResourceAllocationException("Interrupted attempting lock: " + this); } }
ActiveMQRAConnectionRequestInfo cri = getCRI((ActiveMQRAConnectionRequestInfo) cxRequestInfo); ActiveMQRACredential credential = ActiveMQRACredential.getCredential(this, subject, cri);
@Override @Before public void setUp() throws Exception { useDummyTransactionManager(); super.setUp(); resourceAdapter = new ActiveMQResourceAdapter(); resourceAdapter.setEntries("[\"java://jmsXA\"]"); resourceAdapter.setConnectorClassName(InVMConnectorFactory.class.getName()); MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setResourceAdapter(resourceAdapter); qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); }
@Test public void testSimpleMessageSendAndReceiveSessionTransacted2() throws Exception { setupDLQ(10); resourceAdapter = newResourceAdapter(); MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setAllowLocalTransactions(true); mcf.setResourceAdapter(resourceAdapter); ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); QueueConnection queueConnection = qraConnectionFactory.createQueueConnection(); Session s = queueConnection.createSession(Session.SESSION_TRANSACTED); Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE); MessageProducer mp = s.createProducer(q); MessageConsumer consumer = s.createConsumer(q); Message message = s.createTextMessage("test"); mp.send(message); s.commit(); queueConnection.start(); TextMessage textMessage = (TextMessage) consumer.receive(1000); assertNotNull(textMessage); assertEquals(textMessage.getText(), "test"); s.rollback(); textMessage = (TextMessage) consumer.receive(1000); assertNotNull(textMessage); assertEquals(textMessage.getText(), "test"); s.commit(); textMessage = (TextMessage) consumer.receiveNoWait(); assertNull(textMessage); }
@Test public void testConnectionCredentialsFailRecovery() throws Exception { resourceAdapter = newResourceAdapter(); MyBootstrapContext ctx = new MyBootstrapContext(); resourceAdapter.start(ctx); ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory(); mcf.setResourceAdapter(resourceAdapter); ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager); try { QueueConnection queueConnection = qraConnectionFactory.createQueueConnection("testuser", "testwrongpassword"); queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE).close(); fail("should throw esxception"); } catch (JMSException e) { //make sure the recovery is null assertNull(mcf.getResourceRecovery()); } }
if (!mcf.isIgnoreJTA() && inJtaTransaction()) { transacted = true; if (transacted && mcf.isAllowLocalTransactions()) { acknowledgeMode = Session.SESSION_TRANSACTED; } else { if (!mcf.isAllowLocalTransactions()) { throw ActiveMQRABundle.BUNDLE.invalidSessionTransactedModeRuntimeAllowLocal(); info.setPassword(password); info.setClientID(clientID); info.setDefaults(((ActiveMQResourceAdapter) mcf.getResourceAdapter()).getProperties());
/** * Indicates whether some other object is "equal to" this one. * * @param obj Object with which to compare * @return True if this object is the same as the obj argument; false otherwise. */ @Override public boolean equals(final Object obj) { if (ActiveMQRALogger.LOGGER.isTraceEnabled()) { ActiveMQRALogger.LOGGER.trace("equals(" + obj + ")"); } if (obj == null) { return false; } if (obj instanceof ActiveMQRAManagedConnectionFactory) { ActiveMQRAManagedConnectionFactory other = (ActiveMQRAManagedConnectionFactory) obj; return mcfProperties.equals(other.getProperties()) && ra.equals(other.getResourceAdapter()); } else { return false; } }