@Override public synchronized void handlePacket(Packet packet) { if (onHold != null && deliver) { deliver(); } if (typeToIntercept == PacketImpl.REPLICATION_START_FINISH_SYNC) { if (packet.getType() == PacketImpl.REPLICATION_START_FINISH_SYNC && mustHold) { ReplicationStartSyncMessage syncMsg = (ReplicationStartSyncMessage) packet; if (syncMsg.isSynchronizationFinished() && !deliver) { receivedUpToDate = true; assert onHold == null; onHold = packet; PacketImpl response = new ReplicationResponseMessage(); channel.send(response); return; } } } else if (typeToIntercept == packet.getType()) { channel.send(new ReplicationResponseMessage()); return; } handler.handlePacket(packet); }
@Override public boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException { if (packet.getType() == PacketImpl.BACKUP_REGISTRATION) { try { SharedNothingBackupActivation activation = (SharedNothingBackupActivation) backup.getActivation(); ReplicationEndpoint repEnd = activation.getReplicationEndpoint(); handler.addSubHandler(repEnd); Channel repChannel = repEnd.getChannel(); repChannel.setHandler(handler); handler.setChannel(repChannel); live.getRemotingService().removeIncomingInterceptor(this); } catch (Exception e) { throw new RuntimeException(e); } } return true; }
public synchronized void deliver() { deliver = true; if (!receivedUpToDate) return; if (delivered) return; if (onHold == null) { throw new NullPointerException("Don't have the 'sync is done' packet to deliver"); } // Use wrapper to avoid sending a response ChannelWrapper wrapper = new ChannelWrapper(channel); handler.setChannel(wrapper); try { handler.handlePacket(onHold); delivered = true; } finally { handler.setChannel(channel); channel.setHandler(handler); onHold = null; } }