@Override public RemotingConnection getForwardingConnection() { if (session == null) { return null; } else { return session.getConnection(); } }
protected void nodeUP(TopologyMember member, boolean last) { if (member != null) { ClientSessionInternal sessionToUse = session; RemotingConnection connectionToUse = sessionToUse != null ? sessionToUse.getConnection() : null; if (this.targetNodeID != null && this.targetNodeID.equals(member.getNodeId())) { // this could be an update of the topology say after a backup started BridgeImpl.this.targetNode = member; } else { // we don't need synchronization here, but we need to make sure we won't get a NPE on races if (connectionToUse != null && member.isMember(connectionToUse)) { this.targetNode = member; this.targetNodeID = member.getNodeId(); } } } }
@Override public void run() { ready.countDown(); while (true) { try { Boolean poll = false; try { poll = failureQueue.poll(60, TimeUnit.SECONDS); } catch (InterruptedException e) { e.printStackTrace(); break; } Thread.sleep(1); final RemotingConnectionImpl conn = (RemotingConnectionImpl) ((ClientSessionInternal) session).getConnection(); // True means... fail session if (poll) { conn.fail(new ActiveMQNotConnectedException("poop")); } else { // false means... finish thread break; } } catch (Exception e) { e.printStackTrace(); } } } };
@Override protected void crash(final ClientSession... sessions) throws Exception { for (ClientSession session : sessions) { log.debug("Crashing session " + session); ClientSessionInternal internalSession = (ClientSessionInternal) session; internalSession.getConnection().fail(new ActiveMQNotConnectedException("oops")); } } }
/** * @param session * @throws InterruptedException */ private void fail(final ClientSession session) throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); session.addFailureListener(new CountDownSessionFailureListener(latch, session)); RemotingConnection conn = ((ClientSessionInternal) session).getConnection(); // Simulate failure on connection conn.fail(new ActiveMQNotConnectedException()); // Wait to be informed of failure boolean ok = latch.await(1000, TimeUnit.MILLISECONDS); Assert.assertTrue(ok); }
@Test public void testUsingDeadConnection() throws Exception { for (int i = 0; i < 100; i++) { final Connection conn1 = cf1.createConnection(); Session sess1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE); RemotingConnection rc1 = ((ClientSessionInternal) ((ActiveMQSession) sess1).getCoreSession()).getConnection(); rc1.fail(new ActiveMQNotConnectedException("blah")); try { conn1.createSession(false, Session.AUTO_ACKNOWLEDGE); Assert.fail("should throw exception"); } catch (JMSException e) { //pass } conn1.close(); } }
@Test public void testListenerCalledForOneConnection() throws Exception { Connection conn = cf.createConnection(); CountDownLatch latch = new CountDownLatch(1); MyExceptionListener listener = new MyExceptionListener(latch); conn.setExceptionListener(listener); ClientSessionInternal coreSession = (ClientSessionInternal) ((ActiveMQConnection) conn).getInitialSession(); coreSession.getConnection().fail(new ActiveMQInternalErrorException("blah")); latch.await(5, TimeUnit.SECONDS); Assert.assertEquals(1, listener.numCalls); conn.close(); }
@Test public void testListenerCalledForOneConnectionAndSessions() throws Exception { Connection conn = cf.createConnection(); CountDownLatch latch = new CountDownLatch(1); MyExceptionListener listener = new MyExceptionListener(latch); conn.setExceptionListener(listener); Session sess1 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); Session sess2 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); Session sess3 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); ClientSessionInternal coreSession0 = (ClientSessionInternal) ((ActiveMQConnection) conn).getInitialSession(); ClientSessionInternal coreSession1 = (ClientSessionInternal) ((ActiveMQSession) sess1).getCoreSession(); ClientSessionInternal coreSession2 = (ClientSessionInternal) ((ActiveMQSession) sess2).getCoreSession(); ClientSessionInternal coreSession3 = (ClientSessionInternal) ((ActiveMQSession) sess3).getCoreSession(); coreSession0.getConnection().fail(new ActiveMQInternalErrorException("blah")); coreSession1.getConnection().fail(new ActiveMQInternalErrorException("blah")); coreSession2.getConnection().fail(new ActiveMQInternalErrorException("blah")); coreSession3.getConnection().fail(new ActiveMQInternalErrorException("blah")); latch.await(5, TimeUnit.SECONDS); // Listener should only be called once even if all sessions connections die Assert.assertEquals(1, listener.numCalls); conn.close(); }
RemotingConnection connection = ((ClientSessionInternal) ((ActiveMQSession) session).getCoreSession()).getConnection();
@Override public synchronized void run() { RandomReattachTest.log.info("** Failing connection"); session.getConnection().fail(new ActiveMQNotConnectedException("oops")); RandomReattachTest.log.info("** Fail complete"); cancel(); executed = true; }
@Override public synchronized void run() { log.info("** Failing connection"); RemotingConnectionImpl conn = (RemotingConnectionImpl) ((ClientSessionInternal) session).getConnection(); if (failOnCreateConnection) { InVMConnector.numberOfFailures = 1; InVMConnector.failOnCreateConnection = true; } else { conn.fail(new ActiveMQNotConnectedException("blah")); } log.info("** Fail complete"); cancel(); executed = true; }
RemotingConnection rc = sessi.getConnection();
RemotingConnection rc1 = ((ClientSessionInternal) ((ActiveMQSession) sess1).getCoreSession()).getConnection(); RemotingConnection rc2 = ((ClientSessionInternal) ((ActiveMQSession) sess2).getCoreSession()).getConnection();
RemotingConnection rc = clientSession.getConnection();
RemotingConnection conn = ((ClientSessionInternal) session).getConnection();
InVMConnector.numberOfFailures = 3; RemotingConnection conn = ((ClientSessionInternal) session).getConnection();
InVMConnector.numberOfFailures = 3; RemotingConnection conn = ((ClientSessionInternal) session).getConnection();
InVMConnector.numberOfFailures = reconnectAttempts - 1; RemotingConnection conn = ((ClientSessionInternal) session).getConnection();
@Test public void testRecreateConsumerOverServerFailure() throws Exception { ServerLocator serverWithReattach = createInVMNonHALocator().setReconnectAttempts(30).setRetryInterval(1000).setConfirmationWindowSize(-1).setConnectionTTL(TemporaryQueueTest.CONNECTION_TTL).setClientFailureCheckPeriod(TemporaryQueueTest.CONNECTION_TTL / 3); ClientSessionFactory reattachSF = createSessionFactory(serverWithReattach); ClientSession session = reattachSF.createSession(false, false); session.createTemporaryQueue("tmpAd", "tmpQ"); ClientConsumer consumer = session.createConsumer("tmpQ"); ClientProducer prod = session.createProducer("tmpAd"); session.start(); RemotingConnectionImpl conn = (RemotingConnectionImpl) ((ClientSessionInternal) session).getConnection(); conn.fail(new ActiveMQIOErrorException()); prod.send(session.createMessage(false)); session.commit(); assertNotNull(consumer.receive(1000)); session.close(); reattachSF.close(); serverWithReattach.close(); }
RemotingConnection connection = ((ClientSessionInternal) session).getConnection();