sendChangesLogUpDate(packet.getTimeStamp(), packet.getOwnerName(), packet.getIdentifier());
break;
case Packet.PacketType.BINARY_FILE_PACKET :
PendingBinaryFile container = mapPendingBinaryFile.get(packet.getIdentifier());
if (container == null)
{
container = new PendingBinaryFile();
mapPendingBinaryFile.put(packet.getIdentifier(), container);
}
ChangesFile chf;
synchronized (container)
{
chf = container.getChangesFile(packet.getOwnerName(), packet.getFileName());
if (chf == null)
{
chf =
container.addChangesFile(packet.getOwnerName(), packet.getFileName(), packet.getSystemId(), packet
.getTotalPacketCount());
}
}
chf.write(packet.getOffset(), packet.getByteArray());
if (chf.isStored())
{
if (log.isDebugEnabled())
log.debug("Last packet of file has been received : " + packet.getFileName());
}
break;
case Packet.PacketType.ALL_BINARY_FILE_TRANSFERRED_OK :
if (mapPendingBinaryFile.containsKey(packet.getIdentifier()))
{
PendingBinaryFile pbf = mapPendingBinaryFile.get(packet.getIdentifier());
pbf.addToSuccessfulTransferCounter(packet.getSize());
if (pbf.isSuccessfulTransfer())
{
if (log.isDebugEnabled())
log.debug("The signal ALL_BinaryFile_transferred_OK has been received from "
+ packet.getOwnerName());
List<ChangesFile> fileDescriptorList = pbf.getSortedFilesDescriptorList();
if (log.isDebugEnabled())
log.info("fileDescriptorList.size() == pbf.getNeedTransferCounter() : "
+ fileDescriptorList.size() + "== " + pbf.getNeedTransferCounter());
if (fileDescriptorList.size() == pbf.getNeedTransferCounter())
{
List<String> failList = new ArrayList<String>();
for (ChangesFile fileDescriptor : fileDescriptorList)
{
try
{
TransactionChangesLog transactionChangesLog =
recoveryReader.getChangesLog(PrivilegedFileHelper.getAbsolutePath(fileDescriptor.getFile()));
transactionChangesLog.setSystemId(fileDescriptor.getSystemId());
Calendar cLogTime = fileNameFactory.getDateFromFileName(fileDescriptor.getFile().getName());
if (log.isDebugEnabled())
{
log.debug("Save to JCR : "
+ PrivilegedFileHelper.getAbsolutePath(fileDescriptor.getFile()));
log.debug("SystemID : " + transactionChangesLog.getSystemId());
log.debug("list size : " + fileDescriptorList.size());
}
// dump log
if (log.isDebugEnabled())
{
ChangesLogIterator logIterator = transactionChangesLog.getLogIterator();
while (logIterator.hasNextLog())
{
PlainChangesLog pcl = logIterator.nextLog();
log.debug(pcl.dump());
}
}
saveChangesLog(dataKeeper, transactionChangesLog, cLogTime);
if (log.isDebugEnabled())
{
log.debug("After save message: the owner systemId --> "
+ transactionChangesLog.getSystemId());
log.debug("After save message: --> " + systemId);
}
}
catch (Exception e)
{
failList.add(fileDescriptor.getFile().getName());
log.error("Can't save to JCR ", e);
}
}
// Send file name list
List<String> fileNameList =
new ArrayList<String>(mapPendingBinaryFile.get(packet.getIdentifier()).getFileNameList());
if (failList.size() != 0)
fileNameList.removeAll(failList);
Packet packetFileNameList =
new Packet(Packet.PacketType.ALL_CHANGESLOG_SAVED_OK, packet.getIdentifier(), ownName,
fileNameList);
send(packetFileNameList);
log.info("The " + fileDescriptorList.size() + " changeslogs were received and "
+ fileNameList.size() + " saved");
}
else if (log.isDebugEnabled())
{
log.debug("Do not start save : " + fileDescriptorList.size() + " of "
+ pbf.getNeedTransferCounter());
}
}
}
break;
case Packet.PacketType.ALL_CHANGESLOG_SAVED_OK :
long removeCounter = recoveryWriter.removeChangesLog(packet.getFileNameList(), packet.getOwnerName());
if (log.isDebugEnabled())
log.debug("Remove from file system : " + removeCounter);
Packet removedOldChangesLogPacket =
new Packet(Packet.PacketType.REMOVED_OLD_CHANGESLOG_COUNTER, packet.getIdentifier(), ownName);
removedOldChangesLogPacket.setSize(removeCounter);
channelManager.sendPacket(removedOldChangesLogPacket);
break;
case Packet.PacketType.REMOVED_OLD_CHANGESLOG_COUNTER :
if (mapPendingBinaryFile.containsKey(packet.getIdentifier()) == true)
{
PendingBinaryFile pbf = mapPendingBinaryFile.get(packet.getIdentifier());
pbf.setRemovedOldChangesLogCounter(pbf.getRemovedOldChangesLogCounter() + packet.getSize());
if (pbf.isAllOldChangesLogsRemoved())
{
// remove temporary files
for (ChangesFile fd : pbf.getSortedFilesDescriptorList())
fileCleaner.addFile(fd.getFile());
// remove PendingBinaryFile
mapPendingBinaryFile.remove(packet.getIdentifier());
// next iteration
if (log.isDebugEnabled())
log.debug("Next iteration of recovery ...");
synchronizRepository();
}
}
else
log.warn("Can not find the PendingBinaryFile whith id: " + packet.getIdentifier());
break;
case Packet.PacketType.NEED_TRANSFER_COUNTER :
if (mapPendingBinaryFile.containsKey(packet.getIdentifier()) == false)
mapPendingBinaryFile.put(packet.getIdentifier(), new PendingBinaryFile());
PendingBinaryFile pbf = mapPendingBinaryFile.get(packet.getIdentifier());
pbf.setNeedTransferCounter(pbf.getNeedTransferCounter() + packet.getSize());
if (log.isDebugEnabled())
log.debug("NeedTransferCounter : " + pbf.getNeedTransferCounter());
break;
case Packet.PacketType.SYNCHRONIZED_OK :
if (successfulSynchronizedList.contains(packet.getOwnerName()) == false)
successfulSynchronizedList.add(packet.getOwnerName());