refs #2247: Accounting lib doesn't elaborate fallBack file if the files name has the old format name

https://support.d4science.org/issues/2247

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-publishing/document-store-lib@124113 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-02-12 10:41:22 +00:00
parent c13840c9d4
commit 0df6fda7bc
2 changed files with 39 additions and 11 deletions

View File

@ -24,7 +24,7 @@ public abstract class PersistenceBackendFactory {
public final static String HOME_SYSTEM_PROPERTY = "user.home";
private static final String FALLBACK_FILENAME = "fallback.log";
protected static final String FALLBACK_FILENAME = "fallback.log";
private static String fallbackLocation;

View File

@ -8,6 +8,7 @@ import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Calendar;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@ -61,19 +62,31 @@ public class PersistenceBackendMonitor implements Runnable {
}
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
logger.debug("Trying to persist {}s which failed and were persisted using fallback", Record.class.getSimpleName());
@Deprecated
protected void manageOldAccountingFile(){
FallbackPersistenceBackend fallbackPersistenceBackend = persistenceBackend.getFallbackPersistence();
File file = fallbackPersistenceBackend.getFallbackFile();
File newFile = fallbackPersistenceBackend.getFallbackFile();
String oldAccountingFileName = newFile.getName();
int lastIndexOf_ = oldAccountingFileName.lastIndexOf("_");
oldAccountingFileName = oldAccountingFileName.substring(lastIndexOf_+1);
oldAccountingFileName = oldAccountingFileName.replace(
PersistenceBackendFactory.FALLBACK_FILENAME, "accountingFallback.log");
File oldAccountingFile = new File(newFile.getParentFile(), oldAccountingFileName);
elaborateFallbackFile(oldAccountingFile);
}
protected void elaborateFallbackFile(File file){
File elaborationFile = null;
synchronized (file) {
if(file.exists()){
elaborationFile = new File(file.getAbsolutePath()+ELABORATION_FILE_SUFFIX);
Long timestamp = Calendar.getInstance().getTimeInMillis();
elaborationFile = new File(file.getAbsolutePath(), ELABORATION_FILE_SUFFIX + "." + timestamp.toString());
file.renameTo(elaborationFile);
}
}
@ -90,6 +103,21 @@ public class PersistenceBackendMonitor implements Runnable {
}
}
}
/* (non-Javadoc)
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
logger.debug("Trying to persist {}s which failed and were persisted using fallback", Record.class.getSimpleName());
FallbackPersistenceBackend fallbackPersistenceBackend = persistenceBackend.getFallbackPersistence();
File file = fallbackPersistenceBackend.getFallbackFile();
elaborateFallbackFile(file);
manageOldAccountingFile();
}
}