@Override public void bufferReceived(final Object connectionID, final ActiveMQBuffer buffer) { RemotingConnection theConn = connection; if (theConn != null && connectionID.equals(theConn.getID())) { try { theConn.bufferReceived(connectionID, buffer); } catch (final RuntimeException e) { ActiveMQClientLogger.LOGGER.disconnectOnErrorDecoding(e); threadPool.execute(new Runnable() { @Override public void run() { theConn.fail(new ActiveMQException(e.getMessage())); } }); } } else { logger.debug("TheConn == null on ClientSessionFactoryImpl::DelegatingBufferHandler, ignoring packet"); } } }
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; } }
@Override public void run() { connectionInUse.fail(me); } });
@Override public synchronized void run() { if (cancelled || stopPingingAfterOne && !first) { return; } first = false; long now = System.currentTimeMillis(); final RemotingConnection connectionInUse = connection; if (connectionInUse != null && clientFailureCheckPeriod != -1 && connectionTTL != -1 && now >= lastCheck + connectionTTL) { if (!connectionInUse.checkDataReceived()) { // We use a different thread to send the fail // but the exception has to be created here to preserve the stack trace final ActiveMQException me = ActiveMQClientMessageBundle.BUNDLE.connectionTimedOut(connection.getTransportConnection()); cancelled = true; threadPool.execute(new Runnable() { // Must be executed on different thread @Override public void run() { connectionInUse.fail(me); } }); return; } else { lastCheck = now; } } send(); }
protected RemotingConnection establishNewConnection() { Connection transportConnection = createTransportConnection(); if (transportConnection == null) { if (ClientSessionFactoryImpl.logger.isTraceEnabled()) { logger.trace("Neither backup or live were active, will just give up now"); } return null; } RemotingConnection newConnection = clientProtocolManager.connect(transportConnection, callTimeout, callFailoverTimeout, incomingInterceptors, outgoingInterceptors, new SessionFactoryTopologyHandler()); newConnection.addFailureListener(new DelegatingFailureListener(newConnection.getID())); schedulePing(); if (logger.isTraceEnabled()) { logger.trace("returning " + newConnection); } return newConnection; }
default boolean isSameTarget(TransportConfiguration... configs) { return getTransportConnection().isSameTarget(configs); } }
List<FailureListener> oldListeners = oldConnection.getFailureListeners(); List<FailureListener> newListeners = new ArrayList<>(connection.getFailureListeners()); connection.setFailureListeners(newListeners);
@Override public void connectionReadyForWrites(Object connectionID, boolean ready) { RemotingConnection connection = connectionMap.get(connectionID); if (connection != null) { log.info("Connection " + connection.getRemoteAddress() + " ready"); connection.getTransportConnection().fireReady(true); } else { log.error("Connection with id " + connectionID + " not found in connectionReadyForWrites()!"); } }
@Override public void bufferReceived(final Object connectionID, final ActiveMQBuffer buffer) { ConnectionEntry conn = connections.get(connectionID); if (conn != null) { try { conn.connection.bufferReceived(connectionID, buffer); } catch (RuntimeException e) { ActiveMQServerLogger.LOGGER.disconnectCritical("Error decoding buffer", e); conn.connection.fail(new ActiveMQException(e.getMessage())); } } else { if (logger.isTraceEnabled()) { logger.trace("ConnectionID = " + connectionID + " was already closed, so ignoring packet"); } } } }
public Object getID() { return connection.getID(); }
@Override public boolean isWritable(ReadyListener callback) { return remotingConnection.isWritable(callback); }
private void crash() throws Exception { /* * Rather than just calling stop() on the server here we want to simulate an actual node crash or bridge failure * so the bridge's failure listener needs to get something other than a DISCONNECTED message. In this case we * simulate a NOT_CONNECTED exception. */ final CountDownLatch latch = new CountDownLatch(1); ClusterConnectionImpl next = (ClusterConnectionImpl) server1.getClusterManager().getClusterConnections().iterator().next(); BridgeImpl bridge = (BridgeImpl) next.getRecords().values().iterator().next().getBridge(); RemotingConnection forwardingConnection = getForwardingConnection(bridge); forwardingConnection.addFailureListener(new FailureListener() { @Override public void connectionFailed(ActiveMQException exception, boolean failedOver) { latch.countDown(); } @Override public void connectionFailed(final ActiveMQException me, boolean failedOver, String scaleDownTargetNodeID) { connectionFailed(me, failedOver); } }); forwardingConnection.fail(new ActiveMQNotConnectedException()); assertTrue(latch.await(5000, TimeUnit.MILLISECONDS)); if (crash) { jmsServer2.stop(); } }
csf.getConnection().addFailureListener(new FailureListener() {
@Override public void bufferReceived(Object connectionID, ActiveMQBuffer buffer) { RemotingConnection connection = connectionMap.get(connectionID); if (connection != null) { connection.bufferReceived(connectionID, buffer); } else { log.error("Connection with id " + connectionID + " not found in bufferReceived()!"); } }
if (!conn.checkDataReceived()) { if (now >= entry.lastCheck + entry.ttl) { toRemove.add(new Pair<>(conn.getID(), entry.ttl));
@Override public void connectionDestroyed(Object connectionID) { RemotingConnection connection = connectionMap.remove(connectionID); if (connection != null) { log.info("Connection " + connection.getRemoteAddress() + " destroyed"); connection.fail(new ActiveMQRemoteDisconnectException()); } else { log.error("Connection with id " + connectionID + " not found in connectionDestroyed"); } }
/** * We only need to check if the connection point to the same node, * don't need to compare the whole params map. * @param connection The connection to the target node * @return true if the connection point to the same node * as this member represents. */ @Override public boolean isMember(RemotingConnection connection) { return connection.isSameTarget(getConnector().getA(), getConnector().getB()); }
private void sendConnectionNotification(final RemotingConnection connection, final CoreNotificationType type) { final ManagementService managementService = getManagementService(); if (managementService != null && sendConnectionNotifications) { try { final TypedProperties props = new TypedProperties(); props.putSimpleStringProperty(ManagementHelper.HDR_CONNECTION_NAME, SimpleString.toSimpleString(connection.getID().toString())); props.putSimpleStringProperty(ManagementHelper.HDR_REMOTE_ADDRESS, SimpleString.toSimpleString(connection.getRemoteAddress())); managementService.sendNotification(new Notification(null, type, props)); } catch (Exception e) { logger.warn("Error sending notification: " + type, e.getMessage(), e); } } }
protected RemotingConnection establishNewConnection() { Connection transportConnection = createTransportConnection(); if (transportConnection == null) { if (ClientSessionFactoryImpl.logger.isTraceEnabled()) { logger.trace("Neither backup or live were active, will just give up now"); } return null; } RemotingConnection newConnection = clientProtocolManager.connect(transportConnection, callTimeout, callFailoverTimeout, incomingInterceptors, outgoingInterceptors, new SessionFactoryTopologyHandler()); newConnection.addFailureListener(new DelegatingFailureListener(newConnection.getID())); schedulePing(); if (logger.isTraceEnabled()) { logger.trace("returning " + newConnection); } return newConnection; }