@Override public void addFailureListener(final SessionFailureListener listener) { sessionFactory.addFailureListener(listener); }
private void addFactory(ClientSessionFactoryInternal factory) { if (factory == null) { return; } if (isClosed()) { factory.close(); return; } TransportConfiguration backup = null; if (ha) { backup = topology.getBackupForConnector((Connector) factory.getConnector()); } factory.setBackupConnector(factory.getConnectorConfiguration(), backup); synchronized (factories) { factories.add(factory); } }
@Override public void addFailoverListener(FailoverEventListener listener) { sessionFactory.addFailoverListener(listener); }
@Override public ClientSessionFactory createSessionFactory(final TransportConfiguration transportConfiguration) throws Exception { assertOpen(); initialize(); ClientSessionFactoryInternal factory = new ClientSessionFactoryImpl(this, transportConfiguration, callTimeout, callFailoverTimeout, clientFailureCheckPeriod, connectionTTL, retryInterval, retryIntervalMultiplier, maxRetryInterval, reconnectAttempts, threadPool, scheduledThreadPool, incomingInterceptors, outgoingInterceptors); addToConnecting(factory); try { try { factory.connect(reconnectAttempts, failoverOnInitialConnection); } catch (ActiveMQException e1) { //we need to make sure is closed just for garbage collection factory.close(); throw e1; } addFactory(factory); return factory; } finally { removeFromConnecting(factory); } }
try { addToConnecting(factory); factory.connect(initialConnectAttempts, failoverOnInitialConnection); } finally { removeFromConnecting(factory); factory.close(); if (e.getType() == ActiveMQExceptionType.NOT_CONNECTED) { attempts++; if (topology != null && !factory.waitForTopology(callTimeout, TimeUnit.MILLISECONDS)) { factory.cleanup(); throw ActiveMQClientMessageBundle.BUNDLE.connectionTimedOutOnReceiveTopology(discoveryGroup);
@Override public String getNodeId() { return sessionFactory.getLiveNodeId(); }
private void wrapUpSessionFactory() { sf.close(); assertEquals("Expecting 0 sessions", 0, sf.numSessions()); assertEquals("Expecting 0 connections", 0, sf.numConnections()); }
private synchronized void createConnectors() { if (connectors != null) { for (Connector conn : connectors) { if (conn != null) { conn.disconnect(); } } } connectors = new ArrayList<>(); if (initialConnectors != null) { for (TransportConfiguration initialConnector : initialConnectors) { ClientSessionFactoryInternal factory = new ClientSessionFactoryImpl(ServerLocatorImpl.this, initialConnector, callTimeout, callFailoverTimeout, clientFailureCheckPeriod, connectionTTL, retryInterval, retryIntervalMultiplier, maxRetryInterval, reconnectAttempts, threadPool, scheduledThreadPool, incomingInterceptors, outgoingInterceptors); factory.disableFinalizeCheck(); connectors.add(new Connector(initialConnector, factory)); } } }
confirmationWindowWarning = sessionFactory.getConfirmationWindowWarning();
/** * @param sessionFactory the session factory used to connect to the live server */ public void setSessionFactory(final ClientSessionFactoryInternal sessionFactory) { this.sessionFactory = sessionFactory; this.connection = (CoreRemotingConnection) sessionFactory.getConnection(); connection.addFailureListener(this); //belts and braces, there are circumstances where the connection listener doesn't get called but the session does. sessionFactory.addFailureListener(this); }
/** * close this cluster control and its resources */ @Override public void close() { sessionFactory.close(); }
public ClientSessionFactory tryConnect() throws ActiveMQException { if (logger.isDebugEnabled()) { logger.debug(this + "::Trying to connect to " + factory); } try { ClientSessionFactoryInternal factoryToUse = factory; if (factoryToUse != null) { addToConnecting(factoryToUse); try { factoryToUse.connect(1, false); } finally { removeFromConnecting(factoryToUse); } } return factoryToUse; } catch (ActiveMQException e) { logger.debug(this + "::Exception on establish connector initial connection", e); return null; } }
factory.addFailureListener(new SessionFailureListener() { final ClientSessionInternal session = (ClientSessionInternal) factory.createSession();
private static void cleanUpSessionFactory(ClientSessionFactoryInternal factory) { if (factory != null) factory.cleanup(); }
@Test public void testFailureListenerRemoved() throws Exception { cf = createSessionFactory(locator); try { ClientSession clientSession = cf.createSession(false, true, true); class MyFailureListener implements SessionFailureListener { boolean called = false; @Override public void connectionFailed(final ActiveMQException me, boolean failedOver) { called = true; } @Override public void connectionFailed(final ActiveMQException me, boolean failedOver, String scaleDownTargetNodeID) { connectionFailed(me, failedOver); } @Override public void beforeReconnect(final ActiveMQException me) { } } MyFailureListener listener = new MyFailureListener(); clientSession.addFailureListener(listener); Assert.assertTrue(clientSession.removeFailureListener(listener)); clientSession.close(); server.stop(); Assert.assertFalse(listener.called); } finally { ((ClientSessionFactoryInternal) cf).causeExit(); cf.close(); } }
try { addToConnecting(factory); factory.connect(initialConnectAttempts, failoverOnInitialConnection); } finally { removeFromConnecting(factory); factory.close(); if (e.getType() == ActiveMQExceptionType.NOT_CONNECTED) { attempts++; if (topology != null && !factory.waitForTopology(callTimeout, TimeUnit.MILLISECONDS)) { factory.cleanup(); throw ActiveMQClientMessageBundle.BUNDLE.connectionTimedOutOnReceiveTopology(discoveryGroup);
@Override public ClientSessionFactory createSessionFactory(final TransportConfiguration transportConfiguration, int reconnectAttempts, boolean failoverOnInitialConnection) throws Exception { assertOpen(); initialize(); ClientSessionFactoryInternal factory = new ClientSessionFactoryImpl(this, transportConfiguration, callTimeout, callFailoverTimeout, clientFailureCheckPeriod, connectionTTL, retryInterval, retryIntervalMultiplier, maxRetryInterval, reconnectAttempts, threadPool, scheduledThreadPool, incomingInterceptors, outgoingInterceptors); addToConnecting(factory); try { try { factory.connect(reconnectAttempts, failoverOnInitialConnection); } catch (ActiveMQException e1) { //we need to make sure is closed just for garbage collection factory.close(); throw e1; } addFactory(factory); return factory; } finally { removeFromConnecting(factory); } }