private void finishSynchronization(String liveID) throws Exception { for (JournalContent jc : EnumSet.allOf(JournalContent.class)) { Journal journal = journalsHolder.remove(jc); journal.synchronizationLock(); try { // files should be already in place. filesReservedForSync.remove(jc); registerJournal(jc.typeByte, journal); journal.stop(); journal.start(); journal.loadSyncOnly(JournalState.SYNCING_UP_TO_DATE); } finally { journal.synchronizationUnlock(); } } ByteBuffer buffer = ByteBuffer.allocate(4 * 1024); for (Entry<Long, ReplicatedLargeMessage> entry : largeMessages.entrySet()) { ReplicatedLargeMessage lm = entry.getValue(); if (lm instanceof LargeServerMessageInSync) { LargeServerMessageInSync lmSync = (LargeServerMessageInSync) lm; lmSync.joinSyncedData(buffer); } } journalsHolder = null; backupQuorum.liveIDSet(liveID); activation.setRemoteBackupUpToDate(); ActiveMQServerLogger.LOGGER.backupServerSynched(server); return; }
/** * Receives 'raw' journal/page/large-message data from live server for synchronization of logs. * * @param msg * @throws Exception */ private synchronized void handleReplicationSynchronization(ReplicationSyncFileMessage msg) throws Exception { Long id = Long.valueOf(msg.getId()); byte[] data = msg.getData(); SequentialFile channel1; switch (msg.getFileType()) { case LARGE_MESSAGE: { ReplicatedLargeMessage largeMessage = lookupLargeMessage(id, false); if (!(largeMessage instanceof LargeServerMessageInSync)) { ActiveMQServerLogger.LOGGER.largeMessageIncompatible(); return; } LargeServerMessageInSync largeMessageInSync = (LargeServerMessageInSync) largeMessage; channel1 = largeMessageInSync.getSyncFile(); break; } case PAGE: { Page page = getPage(msg.getPageStore(), (int) msg.getId()); channel1 = page.getFile(); break; } case JOURNAL: { JournalSyncFile journalSyncFile = filesReservedForSync.get(msg.getJournalContent()).get(id); FileChannel channel2 = journalSyncFile.getChannel(); if (data == null) { channel2.close(); return; } channel2.write(ByteBuffer.wrap(data)); return; } default: throw ActiveMQMessageBundle.BUNDLE.replicationUnhandledFileType(msg.getFileType()); } if (data == null) { channel1.close(); return; } if (!channel1.isOpen()) { channel1.open(); } channel1.writeDirect(ByteBuffer.wrap(data), true); }