Methods Summary |
---|
public synchronized void | destroy()
if (this.fileWriter != null) {
this.lock.lock();
try {
this.fileWriter.flush();
this.fileWriter.close();
if(!this.keepRecoverFiles && this.currentRecoverFile != null)
this.currentRecoverFile.delete();
} catch (IOException e) {
throw new RecoverException("Can't close recover writer ", e);
} finally {
this.lock.unlock();
}
}
|
public synchronized void | initialize()
if(this.recover)
return;
String filename = System.currentTimeMillis() + FILE_SUFFIX;
this.currentRecoverFile = new File(this.recoverDirectory, filename);
this.writer = new RecoverWriter();
this.fileWriter = new BufferedWriter(new FileWriter(
this.currentRecoverFile));
|
public boolean | isRecovering()
return this.recover;
|
public void | recoverEntries(org.apache.lucene.gdata.storage.lucenestorage.StorageModifier modifier)
// prevent deadlock either recovering or writing
if(!this.recover){
LOG.warn("Can't recover entries, Recovercontroller is initialized in write mode");
return;
}
this.lock.lock();
try{
this.reader = new RecoverReader();
File[] files = this.recoverDirectory.listFiles();
for (int i = 0; i < files.length; i++) {
if(!files[i].isDirectory()){
try{
LOG.info("Recover file -- "+files[i]);
this.fileReader = new BufferedReader(new FileReader(files[i]));
List<StorageEntryWrapper> entryList = this.reader.recoverEntries(this.fileReader);
if(entryList.size() == 0)
continue;
storeEntries(entryList,modifier);
this.fileReader.close();
if(!this.keepRecoverFiles){
LOG.info("Recovering file -- "+files[i]+" successful, delete file");
files[i].delete();
}
}catch (StorageException e) {
LOG.error("Can't store recover entries for file: "+files[i].getName()+" -- keep file "+e.getMessage(),e);
}catch (IOException e) {
LOG.error("Can't recover entries for file: "+files[i].getName()+" -- keep file",e);
}
}
}
}finally{
this.lock.unlock();
}
|
public void | storageModified(org.apache.lucene.gdata.storage.lucenestorage.StorageEntryWrapper wrapper)
// prevent deadlock either recovering or writing
if(this.recover){
LOG.warn("Can't write entry, Recovercontroller is initialized in recover mode");
return;
}
this.lock.lock();
try {
this.writer.writeEntry(wrapper, this.fileWriter);
} catch (Exception e) {
LOG.error("Writing entry failed -- create new recover file",e);
throw new RecoverException(
"Writing entry failed -- create new recover file",e);
} finally {
this.lock.unlock();
}
|
protected void | storeEntries(java.util.List entries, org.apache.lucene.gdata.storage.lucenestorage.StorageModifier modifier)
for (StorageEntryWrapper wrapper : entries) {
if(wrapper.getOperation() == StorageOperation.DELETE)
modifier.deleteEntry(wrapper);
else if(wrapper.getOperation() == StorageOperation.INSERT)
modifier.insertEntry(wrapper);
else if(wrapper.getOperation() == StorageOperation.UPDATE)
modifier.updateEntry(wrapper);
modifier.forceWrite();
}
|