Search in sources :

Example 1 with ActiveMQAlreadyReplicatingException

use of org.apache.activemq.artemis.api.core.ActiveMQAlreadyReplicatingException in project activemq-artemis by apache.

the class SharedNothingLiveActivation method startReplication.

public void startReplication(CoreRemotingConnection rc, final ClusterConnection clusterConnection, final Pair<TransportConfiguration, TransportConfiguration> pair, final boolean isFailBackRequest) throws ActiveMQException {
    if (replicationManager != null) {
        throw new ActiveMQAlreadyReplicatingException();
    }
    if (!activeMQServer.isStarted()) {
        throw new ActiveMQIllegalStateException();
    }
    synchronized (replicationLock) {
        if (replicationManager != null) {
            throw new ActiveMQAlreadyReplicatingException();
        }
        ReplicationFailureListener listener = new ReplicationFailureListener();
        rc.addCloseListener(listener);
        rc.addFailureListener(listener);
        replicationManager = new ReplicationManager(rc, clusterConnection.getCallTimeout(), replicatedPolicy.getInitialReplicationSyncTimeout(), activeMQServer.getExecutorFactory());
        replicationManager.start();
        Thread t = new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    activeMQServer.getStorageManager().startReplication(replicationManager, activeMQServer.getPagingManager(), activeMQServer.getNodeID().toString(), isFailBackRequest && replicatedPolicy.isAllowAutoFailBack(), replicatedPolicy.getInitialReplicationSyncTimeout());
                    clusterConnection.nodeAnnounced(System.currentTimeMillis(), activeMQServer.getNodeID().toString(), replicatedPolicy.getGroupName(), replicatedPolicy.getScaleDownGroupName(), pair, true);
                    if (isFailBackRequest && replicatedPolicy.isAllowAutoFailBack()) {
                        BackupTopologyListener listener1 = new BackupTopologyListener(activeMQServer.getNodeID().toString(), clusterConnection.getConnector());
                        clusterConnection.addClusterTopologyListener(listener1);
                        if (listener1.waitForBackup()) {
                            // if we have to many backups kept or are not configured to restart just stop, otherwise restart as a backup
                            activeMQServer.fail(true);
                            ActiveMQServerLogger.LOGGER.restartingReplicatedBackupAfterFailback();
                            // activeMQServer.moveServerData(replicatedPolicy.getReplicaPolicy().getMaxSavedReplicatedJournalsSize());
                            activeMQServer.setHAPolicy(replicatedPolicy.getReplicaPolicy());
                            activeMQServer.start();
                        } else {
                            ActiveMQServerLogger.LOGGER.failbackMissedBackupAnnouncement();
                        }
                    }
                } catch (Exception e) {
                    if (activeMQServer.getState() == ActiveMQServerImpl.SERVER_STATE.STARTED) {
                        /*
                   * The reasoning here is that the exception was either caused by (1) the
                   * (interaction with) the backup, or (2) by an IO Error at the storage. If (1), we
                   * can swallow the exception and ignore the replication request. If (2) the live
                   * will crash shortly.
                   */
                        ActiveMQServerLogger.LOGGER.errorStartingReplication(e);
                    }
                    try {
                        ActiveMQServerImpl.stopComponent(replicationManager);
                    } catch (Exception amqe) {
                        ActiveMQServerLogger.LOGGER.errorStoppingReplication(amqe);
                    } finally {
                        synchronized (replicationLock) {
                            replicationManager = null;
                        }
                    }
                }
            }
        });
        t.start();
    }
}
Also used : ReplicationManager(org.apache.activemq.artemis.core.replication.ReplicationManager) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) ActiveMQAlreadyReplicatingException(org.apache.activemq.artemis.api.core.ActiveMQAlreadyReplicatingException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQDisconnectedException(org.apache.activemq.artemis.api.core.ActiveMQDisconnectedException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) ActiveMQAlreadyReplicatingException(org.apache.activemq.artemis.api.core.ActiveMQAlreadyReplicatingException)

Example 2 with ActiveMQAlreadyReplicatingException

use of org.apache.activemq.artemis.api.core.ActiveMQAlreadyReplicatingException in project activemq-artemis by apache.

the class SharedNothingLiveActivation method getActivationChannelHandler.

@Override
public ChannelHandler getActivationChannelHandler(final Channel channel, final Acceptor acceptorUsed) {
    return new ChannelHandler() {

        @Override
        public void handlePacket(Packet packet) {
            if (packet.getType() == PacketImpl.BACKUP_REGISTRATION) {
                BackupRegistrationMessage msg = (BackupRegistrationMessage) packet;
                ClusterConnection clusterConnection = acceptorUsed.getClusterConnection();
                try {
                    startReplication(channel.getConnection(), clusterConnection, getPair(msg.getConnector(), true), msg.isFailBackRequest());
                } catch (ActiveMQAlreadyReplicatingException are) {
                    channel.send(new BackupReplicationStartFailedMessage(BackupReplicationStartFailedMessage.BackupRegistrationProblem.ALREADY_REPLICATING));
                } catch (ActiveMQException e) {
                    logger.debug("Failed to process backup registration packet", e);
                    channel.send(new BackupReplicationStartFailedMessage(BackupReplicationStartFailedMessage.BackupRegistrationProblem.EXCEPTION));
                }
            }
        }
    };
}
Also used : BackupRegistrationMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.BackupRegistrationMessage) Packet(org.apache.activemq.artemis.core.protocol.core.Packet) ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) BackupReplicationStartFailedMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.BackupReplicationStartFailedMessage) ActiveMQAlreadyReplicatingException(org.apache.activemq.artemis.api.core.ActiveMQAlreadyReplicatingException) ChannelHandler(org.apache.activemq.artemis.core.protocol.core.ChannelHandler)

Aggregations

ActiveMQAlreadyReplicatingException (org.apache.activemq.artemis.api.core.ActiveMQAlreadyReplicatingException)2 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)2 ActiveMQDisconnectedException (org.apache.activemq.artemis.api.core.ActiveMQDisconnectedException)1 ActiveMQIllegalStateException (org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)1 ChannelHandler (org.apache.activemq.artemis.core.protocol.core.ChannelHandler)1 Packet (org.apache.activemq.artemis.core.protocol.core.Packet)1 BackupRegistrationMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.BackupRegistrationMessage)1 BackupReplicationStartFailedMessage (org.apache.activemq.artemis.core.protocol.core.impl.wireformat.BackupReplicationStartFailedMessage)1 ReplicationManager (org.apache.activemq.artemis.core.replication.ReplicationManager)1 ClusterConnection (org.apache.activemq.artemis.core.server.cluster.ClusterConnection)1