}
}
@Override
public void onFileReceived(String tablespace, Integer partition, Long version, File file) {
BalanceFileReceivingProgress progress = getProgressFromLocalPanel(tablespace, partition, version);
if(file.getName().endsWith(".meta")) {
progress.metaFileReceived(file);
} else if(file.getName().endsWith(".db")) {
progress.binaryFileReceived(file);
}
// this can be reached simultaneously by 2 different threads so we must synchronized it
// (thread that downloaded the .meta file and thread that downloaded the .db file)
synchronized(FileReceiverCallback.this) {
if(progress.isReceivedMetaFile() && progress.isReceivedBinaryFile()) {
// This assures that the move will only be done once
if(new File(progress.getMetaFile()).exists() && new File(progress.getBinaryFile()).exists()) {
// check if we already have the binary & meta -> then move partition
// and then remove this action from the panel so that it's completed.
try {
// we need to remove existing files if they exist
// they might be stalled from old deployments
File meta = getLocalMetadataFile(tablespace, partition, version);
if(meta.exists()) {
meta.delete();
}
FileUtils.moveFile(new File(progress.getMetaFile()), meta);
File binaryToMove = new File(progress.getBinaryFile());
File binary = new File(getLocalStorageFolder(tablespace, partition, version),
binaryToMove.getName());
if(binary.exists()) {
binary.delete();
}