javax.resource.spi.ManagedConnection Java Examples
The following examples show how to use
javax.resource.spi.ManagedConnection.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ManagedPoolCacheImpl.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Destroys the underline physical connection to EIS. * * @param connectionObject connection Object. */ @Override void destroyPooledConnection(Object connectionObject) { try { ((ManagedConnection) connectionObject) .removeConnectionEventListener((ConnectionEventListener) connEventListner); ((ManagedConnection) connectionObject).destroy(); connectionObject = null; } catch (ResourceException rex) { LogWriterI18n writer = TransactionUtils.getLogWriterI18n(); if (writer.finerEnabled()) writer .finer( "ManagedPoolcacheImpl::destroyPooledConnection:Exception in closing the connection.Ignoring it. The exeption is " + rex.toString(), rex); } }
Example #2
Source File: AbstractConnectionListener.java From lams with GNU General Public License v2.0 | 6 votes |
/** * {@inheritDoc} */ public void destroy() { if (getState() == ConnectionState.DESTROYED) { log.tracef("ManagedConnection is already destroyed %s", this); return; } getManagedConnectionPool().connectionListenerDestroyed(this); setState(ConnectionState.DESTROYED); final ManagedConnection mc = getManagedConnection(); try { mc.destroy(); } catch (Throwable t) { if (log.isDebugEnabled()) log.debug("Exception destroying ManagedConnection " + this, t); } mc.removeConnectionEventListener(this); }
Example #3
Source File: TestManagedConnectionFactory.java From ironjacamar with Eclipse Public License 1.0 | 6 votes |
/** * {@inheritDoc} */ public ManagedConnection matchManagedConnections(Set connectionSet, Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException { ManagedConnection result = null; Iterator it = connectionSet.iterator(); while (result == null && it.hasNext()) { ManagedConnection mc = (ManagedConnection)it.next(); if (mc instanceof TestManagedConnection) { result = mc; } } return result; }
Example #4
Source File: WorkManagedConnectionFactoryNoHashCode.java From ironjacamar with Eclipse Public License 1.0 | 6 votes |
/** * Returns a matched connection from the candidate set of connections. * * @param connectionSet Candidate connection set * @param subject Caller's security information * @param cxRequestInfo Additional resource adapter specific connection request information * @throws ResourceException generic exception * @return ManagedConnection if resource adapter finds an acceptable match otherwise null */ public ManagedConnection matchManagedConnections(Set connectionSet, Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException { ManagedConnection result = null; Iterator it = connectionSet.iterator(); while (result == null && it.hasNext()) { ManagedConnection mc = (ManagedConnection)it.next(); if (mc instanceof WorkManagedConnection) { result = mc; } } return result; }
Example #5
Source File: TransactionIntegrationImpl.java From ironjacamar with Eclipse Public License 1.0 | 6 votes |
/** * {@inheritDoc} */ public LocalXAResource createConnectableLocalXAResource(ConnectionManager cm, String productName, String productVersion, String jndiName, ManagedConnection mc, XAResourceStatistics xastat) { LocalXAResource result = null; if (xastat != null && xastat.isEnabled()) { result = new LocalConnectableXAResourceStatImpl(productName, productVersion, jndiName, (org.jboss.tm.ConnectableResource)mc, xastat); } else { result = new LocalConnectableXAResourceImpl(productName, productVersion, jndiName, (org.jboss.tm.ConnectableResource)mc); } result.setConnectionManager(cm); return result; }
Example #6
Source File: ManagedPoolCacheImpl.java From gemfirexd-oss with Apache License 2.0 | 6 votes |
/** * Destroys the underline physical connection to EIS. * * @param connectionObject connection Object. */ @Override void destroyPooledConnection(Object connectionObject) { try { ((ManagedConnection) connectionObject) .removeConnectionEventListener((ConnectionEventListener) connEventListner); ((ManagedConnection) connectionObject).destroy(); connectionObject = null; } catch (ResourceException rex) { LogWriterI18n writer = TransactionUtils.getLogWriterI18n(); if (writer.finerEnabled()) writer .finer( "ManagedPoolcacheImpl::destroyPooledConnection:Exception in closing the connection.Ignoring it. The exeption is " + rex.toString(), rex); } }
Example #7
Source File: LazyManagedConnectionFactory.java From ironjacamar with Eclipse Public License 1.0 | 6 votes |
/** * Returns a matched connection from the candidate set of connections. * * @param connectionSet Candidate connection set * @param subject Caller's security information * @param cxRequestInfo Additional resource adapter specific connection request information * @throws ResourceException generic exception * @return ManagedConnection if resource adapter finds an acceptable match otherwise null */ public ManagedConnection matchManagedConnections(Set connectionSet, Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException { log.trace("matchManagedConnections()"); ManagedConnection result = null; Iterator it = connectionSet.iterator(); while (result == null && it.hasNext()) { ManagedConnection mc = (ManagedConnection)it.next(); if (mc instanceof LazyManagedConnection) { result = mc; } } return result; }
Example #8
Source File: ConnectionFactoryImpl.java From cxf with Apache License 2.0 | 6 votes |
public Object getConnection(CXFConnectionParam param) throws ResourceException { if (param.getInterface() == null) { throw new ResourceAdapterInternalException(new Message("INTERFACE_IS_NULL", BUNDLE).toString()); } if (!param.getInterface().isInterface()) { throw new ResourceAdapterInternalException(new Message("IS_NOT_AN_INTERFACE", BUNDLE, param.getInterface()).toString()); } CXFConnectionRequestInfo reqInfo = (CXFConnectionRequestInfo) param; if (connectionManager == null) { // non-managed, null Subject ManagedConnection connection = managedConnectionFactory.createManagedConnection(null, reqInfo); return connection.getConnection(null, reqInfo); } return connectionManager.allocateConnection(managedConnectionFactory, reqInfo); }
Example #9
Source File: OutgoingConnectionTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testConnectionCredentialsFail() 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); ManagedConnection mc = ((ActiveMQRASession) session).getManagedConnection(); queueConnection.close(); mc.destroy(); try { queueConnection = qraConnectionFactory.createQueueConnection("testuser", "testwrongpassword"); queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE).close(); fail("should throw esxception"); } catch (JMSException e) { //pass } }
Example #10
Source File: SemaphoreArrayListManagedConnectionPool.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Create a connection event listener * * @param subject the subject * @param cri the connection request information * @return the new listener * @throws ResourceException for any error */ private ConnectionListener createConnectionEventListener(Subject subject, ConnectionRequestInfo cri) throws ResourceException { long start = pool.getInternalStatistics().isEnabled() ? System.currentTimeMillis() : 0L; ManagedConnection mc = mcf.createManagedConnection(subject, cri); if (pool.getInternalStatistics().isEnabled()) { pool.getInternalStatistics().deltaTotalCreationTime(System.currentTimeMillis() - start); pool.getInternalStatistics().deltaCreatedCount(); } try { return cm.createConnectionListener(mc, this); } catch (ResourceException re) { if (pool.getInternalStatistics().isEnabled()) pool.getInternalStatistics().deltaDestroyedCount(); mc.destroy(); throw re; } }
Example #11
Source File: AutoConnectionTrackerTest.java From tomee with Apache License 2.0 | 5 votes |
@Override public ManagedConnection matchManagedConnections(Set connectionSet, Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException { ManagedConnection result = null; Iterator it = connectionSet.iterator(); while (result == null && it.hasNext()) { ManagedConnection mc = (ManagedConnection) it.next(); if (mc instanceof FakeManagedConnection) { result = mc; } } return result; }
Example #12
Source File: ManagedConnectionFactoryImplTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testMatchConnectionSameConnectioRequestInfoNotBound() throws Exception { Subject subject = null; Set<AbstractManagedConnectionImpl> connectionSet = new HashSet<>(); ConnectionRequestInfo cri = new DummyConnectionRequestInfo(); DummyManagedConnectionImpl con1 = new DummyManagedConnectionImpl(mcf, cri, subject); connectionSet.add(con1); ManagedConnection mcon = mcf.matchManagedConnections(connectionSet, subject, cri); assertEquals(con1, mcon); }
Example #13
Source File: ManagedConnectionFactoryImplTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testCreateManagedConnection() throws Exception { ManagedConnectionFactoryImplTester mcit = new ManagedConnectionFactoryImplTester(); assertTrue("We get a ManagedConnection back", mcit.createManagedConnection(null, null) instanceof ManagedConnection); assertEquals("init was called once", 1, mcit.initCalledCount); }
Example #14
Source File: ManagedConnectionFactoryImplTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testMatchManagedConnectionsWithBoundConnections() throws Exception { Subject subj = new Subject(); BusFactory bf = BusFactory.newInstance(); Bus bus = bf.createBus(); BusFactory.setDefaultBus(bus); ManagedConnectionFactoryImpl factory = EasyMock.createMock(ManagedConnectionFactoryImpl.class); factory.getBus(); // In ManagedConnectionImpl: // one for getCXFServiceFromBus , another for createInvocationHandler EasyMock.expectLastCall().andReturn(bus).times(4); EasyMock.replay(factory); ManagedConnectionImpl mc1 = new ManagedConnectionImpl(factory, cri, subj); Object connection = mc1.getConnection(subj, cri); assertNotNull("connection must not be null.", connection); /* ManagedConnectionImpl mc2 = new ManagedConnectionImpl(factory, cri2, subj); connection = mc2.getConnection(subj, cri2); assertNotNull("connection must not be null.", connection); */ // EasyMock.verify(factory); Set<ManagedConnection> mcSet = new HashSet<>(); mcSet.add(mc1); //mcSet.add(mc2); assertSame("MC1 must be selected.", mci.matchManagedConnections(mcSet, subj, cri), mc1); //assertSame("MC2 must be selected.", mci.matchManagedConnections(mcSet, subj, cri2), mc2); //assertNull("No connection must be selected.", mci.matchManagedConnections(mcSet, subj, cri3)); bus.shutdown(true); }
Example #15
Source File: HelloWorldConnectionImpl.java From ci.maven with Apache License 2.0 | 5 votes |
/** * Constructor for HelloWorldConnectionImpl */ public HelloWorldConnectionImpl(ManagedConnection mc) { super(); this.mc = mc; valid = true; }
Example #16
Source File: ManagedConnectionFactoryImplTest.java From cxf with Apache License 2.0 | 5 votes |
@Test public void testMatchConnectionInvalidatedWithSameConnectioRequestInfo() throws Exception { Subject subject = null; Set<AbstractManagedConnectionImpl> connectionSet = new HashSet<>(); ConnectionRequestInfo cri = new DummyConnectionRequestInfo(); DummyManagedConnectionImpl con1 = new DummyManagedConnectionImpl(mcf, cri, subject); con1.setBound(true); con1.setCon(connectionSet); connectionSet.add(con1); ManagedConnection mcon = mcf.matchManagedConnections(connectionSet, subject, cri); assertNull("Connection must be null", mcon); }
Example #17
Source File: ManagedPoolCacheImpl.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * Creates a new connection for the managed connection pool. * * @return the managed connection from the EIS as ManagedConnection object. * @throws PoolException */ @Override public Object getNewPoolConnection() throws PoolException { ManagedConnection manConn = null; try { manConn = connFactory.createManagedConnection(sub, connReqInfo); } catch (ResourceException rex) { rex.printStackTrace(); throw new PoolException(LocalizedStrings.ManagedPoolCacheImpl_MANAGEDPOOLCACHEIMPLGETNEWCONNECTION_EXCEPTION_IN_CREATING_NEW_MANAGED_POOLEDCONNECTION.toLocalizedString(), rex); } manConn .addConnectionEventListener((javax.resource.spi.ConnectionEventListener) connEventListner); return manConn; }
Example #18
Source File: JCAConnectionManagerImpl.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * CallBack for Connection Error. * * @param event ConnectionEvent */ public void connectionErrorOccurred(ConnectionEvent event) { if (isActive) { // If its an XAConnection ManagedConnection conn = (ManagedConnection) event.getSource(); XAResource xar = (XAResource) xaResourcesMap.get(conn); xaResourcesMap.remove(conn); TransactionManagerImpl transManager = TransactionManagerImpl .getTransactionManager(); try { Transaction txn = transManager.getTransaction(); if (txn != null && xar != null) txn.delistResource(xar, XAResource.TMSUCCESS); } catch (SystemException se) { se.printStackTrace(); } try { mannPoolCache.expirePooledConnection(conn); //mannPoolCache.destroyPooledConnection(conn); } catch (Exception ex) { String exception = "JCAConnectionManagerImpl::connectionErrorOccured: Exception occured due to " + ex; LogWriterI18n writer = TransactionUtils.getLogWriterI18n(); if (writer.fineEnabled()) writer.fine(exception, ex); } } }
Example #19
Source File: FacetsJCAConnectionManagerImpl.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * CallBack for Connection Error. * * @param event ConnectionEvent */ public void connectionErrorOccurred(ConnectionEvent event) { if (isActive) { // If its an XAConnection ManagedConnection conn = (ManagedConnection) event.getSource(); // XAResource xar = (XAResource) xaResourcesMap.get(conn); ((List) xalistThreadLocal.get()).remove(conn); TransactionManagerImpl transManager = TransactionManagerImpl .getTransactionManager(); try { Transaction txn = transManager.getTransaction(); if (txn == null) { mannPoolCache.returnPooledConnectionToPool(conn); } else { // do nothing. } } catch (Exception se) { se.printStackTrace(); } try { mannPoolCache.expirePooledConnection(conn); //mannPoolCache.destroyPooledConnection(conn); } catch (Exception ex) { String exception = "FacetsJCAConnectionManagerImpl::connectionErrorOccured: Exception occured due to " + ex; LogWriterI18n writer = TransactionUtils.getLogWriterI18n(); if (writer.fineEnabled()) writer.fine(exception, ex); } } }
Example #20
Source File: NoTxConnectionManagerImpl.java From lams with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ public ConnectionListener createConnectionListener(ManagedConnection managedConnection, ManagedConnectionPool mcp) throws ResourceException { ConnectionListener cli = new NoTxConnectionListener(this, managedConnection, getPool(), mcp, getFlushStrategy(), getTracking()); managedConnection.addConnectionEventListener(cli); return cli; }
Example #21
Source File: ManagedConnectionFactoryImpl.java From cxf with Apache License 2.0 | 5 votes |
public ManagedConnection matchManagedConnections(@SuppressWarnings("rawtypes") Set mcs, Subject subject, ConnectionRequestInfo reqInfo) throws ResourceException { if (LOG.isLoggable(Level.FINER)) { LOG.finer("match connections: set=" + mcs + ", subject=" + subject + " reqInfo=" + reqInfo); } // find the first managed connection that matches the bus and request info @SuppressWarnings("rawtypes") Iterator iter = mcs.iterator(); while (iter.hasNext()) { Object obj = iter.next(); if (!(obj instanceof ManagedConnectionImpl)) { continue; } ManagedConnectionImpl mc = (ManagedConnectionImpl)obj; if (!Objects.equals(busConfigURL, mc.getManagedConnectionFactoryImpl().getBusConfigURL())) { continue; } if (!Objects.equals(reqInfo, mc.getRequestInfo())) { continue; } if (LOG.isLoggable(Level.FINER)) { LOG.finer("found matched connection " + mc); } return mc; } return null; }
Example #22
Source File: OutBoundConnectionTest.java From cxf with Apache License 2.0 | 5 votes |
@Test @org.junit.Ignore public void testBasicConnection() throws Exception { URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl"); assertNotNull(wsdl); SOAPService service = new SOAPService(wsdl, serviceName); assertNotNull(service); CXFConnectionRequestInfo cri = new CXFConnectionRequestInfo(Greeter.class, wsdl, service.getServiceName(), portName); cri.setAddress("http://localhost:" + PORT + "/SoapContext/SoapPort"); ManagedConnectionFactory managedFactory = new ManagedConnectionFactoryImpl(); Subject subject = new Subject(); ManagedConnection mc = managedFactory.createManagedConnection(subject, cri); Object o = mc.getConnection(subject, cri); // test for the Object hash() try { o.hashCode(); o.toString(); } catch (WebServiceException ex) { fail("The connection object should support Object method"); } verifyResult(o); }
Example #23
Source File: AbstractPool.java From ironjacamar with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} */ public ConnectionListener findConnectionListener(ManagedConnection mc, Object c) { for (ManagedConnectionPool mcp : pools.values()) { ConnectionListener cl = mcp.findConnectionListener(mc, c); if (cl != null) return cl; } return null; }
Example #24
Source File: JCAConnectionManagerImpl.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
/** * CallBack for Connection Error. * * @param event ConnectionEvent */ public void connectionErrorOccurred(ConnectionEvent event) { if (isActive) { // If its an XAConnection ManagedConnection conn = (ManagedConnection) event.getSource(); XAResource xar = (XAResource) xaResourcesMap.get(conn); xaResourcesMap.remove(conn); TransactionManagerImpl transManager = TransactionManagerImpl .getTransactionManager(); try { Transaction txn = transManager.getTransaction(); if (txn != null && xar != null) txn.delistResource(xar, XAResource.TMSUCCESS); } catch (SystemException se) { se.printStackTrace(); } try { mannPoolCache.expirePooledConnection(conn); //mannPoolCache.destroyPooledConnection(conn); } catch (Exception ex) { String exception = "JCAConnectionManagerImpl::connectionErrorOccured: Exception occured due to " + ex; LogWriterI18n writer = TransactionUtils.getLogWriterI18n(); if (writer.fineEnabled()) writer.fine(exception, ex); } } }
Example #25
Source File: LazyManagedConnectionFactory.java From ironjacamar with Eclipse Public License 1.0 | 5 votes |
/** * 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 * @throws ResourceException generic exception * @return ManagedConnection instance */ public ManagedConnection createManagedConnection(Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException { log.trace("createManagedConnection()"); LazyResourceAdapter lra = (LazyResourceAdapter)ra; return new LazyManagedConnection(lra.getLocalTransaction().booleanValue(), lra.getXATransaction().booleanValue(), this, cm); }
Example #26
Source File: XAResourceRecoveryImpl.java From ironjacamar with Eclipse Public License 1.0 | 5 votes |
/** * Open a managed connection * @param s The subject * @return The managed connection * @exception ResourceException Thrown in case of an error */ @SuppressWarnings("unchecked") private ManagedConnection open(Subject s) throws ResourceException { log.debugf("Open managed connection (%s)", s); if (recoverMC == null) recoverMC = mcf.createManagedConnection(s, null); if (plugin == null) { try { ValidatingManagedConnectionFactory vmcf = (ValidatingManagedConnectionFactory)mcf; Set connectionSet = new HashSet(1); connectionSet.add(recoverMC); Set invalid = vmcf.getInvalidConnections(connectionSet); if (invalid != null && !invalid.isEmpty()) { log.debugf("Invalid managed connection: %s", recoverMC); close(recoverMC); recoverMC = mcf.createManagedConnection(s, null); } } catch (ResourceException re) { log.debugf("Exception during invalid check", re); close(recoverMC); recoverMC = mcf.createManagedConnection(s, null); } } return recoverMC; }
Example #27
Source File: TransactionIntegrationImpl.java From ironjacamar with Eclipse Public License 1.0 | 5 votes |
/** * {@inheritDoc} */ public XAResourceWrapper createConnectableXAResourceWrapper(XAResource xares, boolean pad, Boolean override, String productName, String productVersion, String jndiName, ManagedConnection mc, XAResourceStatistics xastat) { return new ConnectableXAResourceWrapperImpl(xares, override, productName, productVersion, jndiName, (ConnectableResource)mc); }
Example #28
Source File: SampleManagedConnectionFactory.java From tomee with Apache License 2.0 | 5 votes |
public ManagedConnection matchManagedConnections(Set connectionSet, Subject subject, ConnectionRequestInfo cxRequestInfo) throws ResourceException { log.finest("matchManagedConnections()"); ManagedConnection result = null; Iterator it = connectionSet.iterator(); while (result == null && it.hasNext()) { ManagedConnection mc = (ManagedConnection) it.next(); if (mc instanceof SampleManagedConnection) { result = mc; } } return result; }
Example #29
Source File: AbstractConnectionManager.java From lams with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ public ManagedConnection associateManagedConnection(Object connection, ManagedConnectionFactory mcf, ConnectionRequestInfo cri) throws ResourceException { // Check for pooling! if (pool == null || shutdown.get()) { throw new ResourceException(bundle.tryingUseConnectionFactoryShutDown(jndiName)); } // It is an explicit spec requirement that equals be used for matching rather than ==. if (!pool.getManagedConnectionFactory().equals(mcf)) { throw new ResourceException( bundle.wrongManagedConnectionFactorySentToAllocateConnection(pool.getManagedConnectionFactory(), mcf)); } if (connection == null) throw new ResourceException(bundle.connectionIsNull()); // Pick a managed connection from the pool Subject subject = getSubject(); ConnectionListener cl = getManagedConnection(subject, cri); // Tell each connection manager the managed connection is active reconnectManagedConnection(cl); // Associate managed connection with the connection cl.getManagedConnection().associateConnection(connection); registerAssociation(cl, connection); if (cachedConnectionManager != null) { cachedConnectionManager.registerConnection(this, cl, connection); } return cl.getManagedConnection(); }
Example #30
Source File: XAResourceRecoveryImpl.java From ironjacamar with Eclipse Public License 1.0 | 5 votes |
/** * Open a connection * @param mc The managed connection * @param s The subject * @return The connection handle * @exception ResourceException Thrown in case of an error */ private Object openConnection(ManagedConnection mc, Subject s) throws ResourceException { if (plugin == null) return null; log.debugf("Open connection (%s, %s)", mc, s); return mc.getConnection(s, null); }