private void handleConnectionFailure(final Object connectionID, final ActiveMQException me, String scaleDownTargetNodeID) { try { failoverOrReconnect(connectionID, me, scaleDownTargetNodeID); } catch (ActiveMQInterruptedException e1) { // this is just a debug, since an interrupt is an expected event (in case of a shutdown) logger.debug(e1.getMessage(), e1); } catch (Throwable t) { ActiveMQClientLogger.LOGGER.unableToHandleConnectionFailure(t); //for anything else just close so clients are un blocked close(); throw t; } }
if (getConnection() != null) { if (oldConnection != null && oldConnection instanceof CoreRemotingConnection) {
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)); } } }
ActiveMQSessionContext sessionContext = (ActiveMQSessionContext) context; if (sessionContext.isKilled()) { setReconnectAttempts(0); if (!clientProtocolManager.isAlive()) return; Lock localFailoverLock = lockFailover(); try { if (connection == null || !connection.getID().equals(connectionID) || !clientProtocolManager.isAlive()) { callFailoverListeners(FailoverEventType.FAILURE_DETECTED); callSessionFailureListeners(me, false, false, scaleDownTargetNodeID); cancelScheduledTasks(); reconnectSessions(oldConnection, reconnectAttempts, me); callFailoverListeners(FailoverEventType.FAILOVER_COMPLETED); sessionsToClose = new HashSet<>(sessions); callFailoverListeners(FailoverEventType.FAILOVER_FAILED); callSessionFailureListeners(me, true, false, scaleDownTargetNodeID); callSessionFailureListeners(me, true, true);
connectorFactory = instantiateConnectorFactory(connectorConfig.getFactoryClassName()); checkTransportKeys(connectorFactory, connectorConfig);
ClientSession session1_c1 = csf.createSession(); ClientSession session2_c1 = csf.createSession(); ClientSession session1_c2 = csf2.createSession(); ClientSession session2_c2 = csf2.createSession(); ClientSession session3_c2 = csf2.createSession(); ClientSession session4_c2 = csf2.createSession(); ClientSession session1_c4 = csf3.createSession(); ClientSession session2_c4 = csf3.createSession(); ClientSession session3_c4 = csf3.createSession(); Assert.assertEquals("connection1 default Order", csf.getConnection().getID(), array.getJsonObject(0).getString("connectionID")); Assert.assertEquals("connection2 default Order", csf2.getConnection().getID(), array.getJsonObject(1).getString("connectionID")); Assert.assertEquals("connection3 session Order", csf3.getConnection().getID(), array.getJsonObject(2).getString("connectionID")); Assert.assertEquals("connection2 session Order", csf2.getConnection().getID(), array.getJsonObject(0).getString("connectionID")); Assert.assertEquals("connection3 session Order", csf3.getConnection().getID(), array.getJsonObject(1).getString("connectionID")); Assert.assertEquals("connection1 session Order", csf.getConnection().getID(), array.getJsonObject(2).getString("connectionID")); Assert.assertEquals("connection3 creationTime Order", csf3.getConnection().getID(), array.getJsonObject(0).getString("connectionID")); Assert.assertEquals("connection2 creationTime Order", csf2.getConnection().getID(), array.getJsonObject(1).getString("connectionID")); Assert.assertEquals("connection1 creationTime Order", csf.getConnection().getID(), array.getJsonObject(2).getString("connectionID")); } finally { if (csf != null) { csf.close(); csf.close();
@Override protected void finalize() throws Throwable { if (!closed && finalizeCheck) { ActiveMQClientLogger.LOGGER.factoryLeftOpen(createTrace, System.identityHashCode(this)); close(); } super.finalize(); }
public ClientSessionFactoryImpl stop() { causeExit(); CLOSE_RUNNABLES.remove(this); return ClientSessionFactoryImpl.this; }
private void interruptConnectAndCloseAllSessions(boolean close) { clientProtocolManager.stop(); synchronized (createSessionLock) { closeCleanSessions(close); closed = true; } }
private void callSessionFailureListeners(final ActiveMQException me, final boolean afterReconnect, final boolean failedOver, final String scaleDownTargetNodeID) { final List<SessionFailureListener> listenersClone = new ArrayList<>(listeners); for (final SessionFailureListener listener : listenersClone) { try { if (afterReconnect) { listener.connectionFailed(me, failedOver, scaleDownTargetNodeID); } else { listener.beforeReconnect(me); } } catch (final Throwable t) { // Failure of one listener to execute shouldn't prevent others // from // executing ActiveMQClientLogger.LOGGER.failedToExecuteListener(t); } } }
private void checkCloseConnection() { RemotingConnection connectionInUse = connection; Connector connectorInUse = connector; if (connectionInUse != null && sessions.size() == 0) { cancelScheduledTasks(); try { connectionInUse.destroy(); } catch (Throwable ignore) { } connection = null; try { if (connectorInUse != null) { connectorInUse.close(); } } catch (Throwable ignore) { } connector = null; } }
/** * @param close */ private void closeCleanSessions(boolean close) { HashSet<ClientSessionInternal> sessionsToClose; synchronized (sessions) { sessionsToClose = new HashSet<>(sessions); } // work on a copied set. the session will be removed from sessions when session.close() is // called for (ClientSessionInternal session : sessionsToClose) { try { if (close) session.close(); else session.cleanUp(false); } catch (Exception e1) { ActiveMQClientLogger.LOGGER.unableToCloseSession(e1); } } checkCloseConnection(); }
ClientSession session = csf.createSession(false, true, true); Assert.assertEquals(1, csf.numConnections()); csf.stopPingingAfterOne(); csf.close();
@Test public void testConnectionTimeoutConfig() throws Exception { final int timeout = 23456; TransportConfiguration transport = new TransportConfiguration(NETTY_CONNECTOR_FACTORY); transport.getParams().put(TransportConstants.NETTY_CONNECT_TIMEOUT, timeout); ServerLocator locator = ActiveMQClient.createServerLocatorWithoutHA(transport); ClientSessionFactoryImpl factory = (ClientSessionFactoryImpl) locator.createSessionFactory(); NettyConnector connector = (NettyConnector) factory.getConnector(); Bootstrap bootstrap = connector.getBootStrap(); assertEquals(timeout, bootstrap.register().channel().config().getConnectTimeoutMillis()); factory.close(); locator.close(); } }
@Test public void testListConnectionsClientID() throws Exception { SimpleString queueName1 = new SimpleString("my_queue_one"); SimpleString addressName1 = new SimpleString("my_address_one"); ActiveMQServerControl serverControl = createManagementControl(); server.addAddressInfo(new AddressInfo(addressName1, RoutingType.ANYCAST)); server.createQueue(addressName1, RoutingType.ANYCAST, queueName1, null, false, false); ClientSessionFactoryImpl csf = null; // create some consumers try (ServerLocator locator = createInVMNonHALocator()) { //sleep as test compares creationTime csf = (ClientSessionFactoryImpl) createSessionFactory(locator); ClientSession session1_c1 = csf.createSession(); ClientSession session2_c1 = csf.createSession(); session1_c1.addMetaData(ClientSession.JMS_SESSION_IDENTIFIER_PROPERTY, ""); session1_c1.addMetaData(JMS_SESSION_CLIENT_ID_PROPERTY, "MYClientID"); String filterString = createJsonFilter("SESSION_COUNT", "GREATER_THAN", "1"); String connectionsAsJsonString = serverControl.listConnections(filterString, 1, 50); JsonObject connectionsAsJsonObject = JsonUtil.readJsonObject(connectionsAsJsonString); JsonArray array = (JsonArray) connectionsAsJsonObject.get("data"); Assert.assertEquals("number of connections returned from query", 1, array.size()); JsonObject jsonConnection = array.getJsonObject(0); //check all fields Assert.assertEquals("clientID", "MYClientID", jsonConnection.getString("clientID")); } finally { if (csf != null) { csf.close(); } } }
ActiveMQSessionContext sessionContext = (ActiveMQSessionContext) context; if (sessionContext.isKilled()) { setReconnectAttempts(0); if (!clientProtocolManager.isAlive()) return; Lock localFailoverLock = lockFailover(); try { if (connection == null || !connection.getID().equals(connectionID) || !clientProtocolManager.isAlive()) { callFailoverListeners(FailoverEventType.FAILURE_DETECTED); callSessionFailureListeners(me, false, false, scaleDownTargetNodeID); cancelScheduledTasks(); reconnectSessions(oldConnection, reconnectAttempts, me); callFailoverListeners(FailoverEventType.FAILOVER_COMPLETED); sessionsToClose = new HashSet<>(sessions); callFailoverListeners(FailoverEventType.FAILOVER_FAILED); callSessionFailureListeners(me, true, false, scaleDownTargetNodeID); callSessionFailureListeners(me, true, true);
connectorFactory = instantiateConnectorFactory(connectorConfig.getFactoryClassName()); checkTransportKeys(connectorFactory, connectorConfig);
@Override protected void finalize() throws Throwable { if (!closed && finalizeCheck) { ActiveMQClientLogger.LOGGER.factoryLeftOpen(createTrace, System.identityHashCode(this)); close(); } super.finalize(); }
public ClientSessionFactoryImpl stop() { causeExit(); CLOSE_RUNNABLES.remove(this); return ClientSessionFactoryImpl.this; }
private void interruptConnectAndCloseAllSessions(boolean close) { clientProtocolManager.stop(); synchronized (createSessionLock) { closeCleanSessions(close); closed = true; } }