Methods Summary |
---|
private void | close()
if(this.isClosed.get())
throw new IllegalStateException("StorageController is already closed -- server is shutting down");
this.storageControllerLock.lock();
try{
if(this.isClosed.get())
throw new IllegalStateException("StorageController is already closed -- server is shutting down");
this.isClosed.set(true);
while(this.storageControllerLock.getQueueLength()>0)
try{
this.closeCondition.await();
}catch (Exception e) {
//
}
if (LOG.isInfoEnabled())
LOG.info("StorageController has been closed -- server is shutting down -- release all resources");
if (this.storageQuery != null)
this.storageQuery.decrementRef();
if(this.recoverController != null)
this.recoverController.destroy();
this.storageLock.close();
this.modifier.close();
this.idGenerator.stopIDGenerator();
}finally{
this.storageControllerLock.unlock();
}
|
private void | createAdminAccount()
GDataAccount adminAccount = GDataAccount.createAdminAccount();
StorageAccountWrapper wrapper = new StorageAccountWrapper(adminAccount);
this.getStorageModifier().createAccount(wrapper);
|
protected org.apache.lucene.index.IndexModifier | createIndexModifier()Creates a new IndexModifier on the storage index
if(this.isClosed.get())
throw new IllegalStateException("StorageController is already closed -- server is shutting down");
this.storageControllerLock.lock();
try{
if(this.isClosed.get())
throw new IllegalStateException("StorageController is already closed -- server is shutting down");
if (LOG.isInfoEnabled())
LOG.info("new IndexModifier created - release to StorageModifier");
return new IndexModifier(this.storageDir, new StandardAnalyzer(),
false);
}finally{
try{
this.closeCondition.signalAll();
}catch (Throwable e) {/**/}
this.storageControllerLock.unlock();
}
|
private boolean | createLuceneStorageLog(java.io.File directory)
if (directory.isDirectory() && !directory.exists()) {
if(!directory.createNewFile())
throw new StorageException("Can not create directory -- "+directory);
}
File file = new File(directory.getAbsolutePath()
+ System.getProperty("file.separator") + STORAGELOG);
return file.createNewFile();
|
private org.apache.lucene.gdata.storage.lucenestorage.recover.RecoverController | createRecoverController(boolean doRecover, boolean keepfiles)
String recoverDirectory = null;
if(this.storageDirectory.endsWith("/") || this.storageDirectory.endsWith("\\"))
recoverDirectory = this.storageDirectory.substring(0,this.storageDirectory.length()-1)+System.getProperty("file.separator")+RECOVERDIRECTORY;
else
recoverDirectory = this.storageDirectory+System.getProperty("file.separator")+RECOVERDIRECTORY;
File recoverDirectoryFile = new File(recoverDirectory);
return new RecoverController(recoverDirectoryFile,doRecover,keepfiles);
|
private StorageModifier | createStorageModifier(boolean create)
IndexModifier indexModifier = new IndexModifier(this.storageDir,
new StandardAnalyzer(), create);
return new StorageModifier(this, indexModifier, this.currentBuffer,
this.storagePersistFactor, this.indexOptimizeInterval);
|
public void | destroy()
try {
close();
} catch (Exception e) {
LOG.error("Closing StorageCoreController failed -- "
+ e.getMessage(), e);
}
|
public void | forceWrite()Forces the StorageModifier to write all buffered changes.
if(this.isClosed.get())
throw new IllegalStateException("StorageController is already closed -- server is shutting down");
this.modifier.forceWrite();
|
public int | getBufferSize()The size of the StorageBuffer.
return this.storageBufferSize;
|
protected org.apache.lucene.store.Directory | getDirectory()
return this.storageDir;
|
public int | getIndexOptimizeInterval()
return this.indexOptimizeInterval;
|
protected ConcurrentStorageLock | getLock()
return this.storageLock;
|
private org.apache.lucene.gdata.utils.ReferenceCounter | getNewStorageQueryHolder(StorageQuery query)
ReferenceCounter<StorageQuery> holder = new ReferenceCounter<StorageQuery>(
query) {
@Override
public void close() {
try {
if (LOG.isInfoEnabled())
LOG
.info("close StorageQuery -- zero references remaining");
this.resource.close();
} catch (IOException e) {
LOG.warn("Error during close call on StorageQuery"
+ e.getMessage(), e);
}
}
};
holder.increamentReference();
return holder;
|
public int | getPersistFactor()An integer value after how many changes to the StorageModifier the
buffered changes will be persisted / written to the index
return this.storagePersistFactor;
|
public org.apache.lucene.gdata.storage.Storage | getStorage()
try {
return new StorageImplementation();
} catch (StorageException e) {
StorageException ex = new StorageException(
"Can't create Storage instance -- " + e.getMessage(), e);
ex.setStackTrace(e.getStackTrace());
throw ex;
}
|
protected StorageModifier | getStorageModifier()returns the current storage modifier
return this.modifier;
|
protected org.apache.lucene.gdata.utils.ReferenceCounter | getStorageQuery()returns a StorageQuery to query the storage index. The
returned object is a reference counter to keep track of the references to
the StorageQuery. The reference is already incremented before
returned from this method.
if the reference counter has no remaining references the resource e.g.
the StorageQuery will be closed. This ensures that a
StorageQuery instance will be around as long as needed and
the resources will be released. The reference counter should be
decremented by clients after finished using the query instance.
if(this.isClosed.get())
throw new IllegalStateException("StorageController is already closed -- server is shutting down");
this.storageControllerLock.lock();
try{
if(this.isClosed.get())
throw new IllegalStateException("StorageController is already closed -- server is shutting down");
if (this.storageQuery == null) {
this.storageQuery = getNewStorageQueryHolder(new StorageQuery(
this.currentBuffer, this.searcher));
if (LOG.isInfoEnabled())
LOG.info("Release new StorageQuery");
}
this.storageQuery.increamentReference();
return this.storageQuery;
}finally{
try{
this.closeCondition.signalAll();
}catch (Throwable e) {/**/}
this.storageControllerLock.unlock();
}
|
public void | initialize()
synchronized (StorageCoreController.class) {
try {
this.idGenerator = new IDGenerator(10);
} catch (Exception e) {
throw new StorageException("Can't create ID Generator", e);
}
boolean createNewStorage = false;
if (this.storageDir == null) {
File storeDir = new File(this.storageDirectory);
File storageLog = new File(storeDir.getAbsolutePath()
+ System.getProperty("file.separator") + STORAGELOG);
try {
if (storeDir.isDirectory() && !storageLog.exists()) {
if (createLuceneStorageLog(storeDir)) {
this.storageDir = FSDirectory.getDirectory(
storeDir, true);
createNewStorage = true;
} else
throw new StorageException(
"could not create storage lock file in "
+ this.storageDirectory);
} else
this.storageDir = FSDirectory.getDirectory(storeDir,
false);
} catch (IOException e) {
storageLog.delete();
throw new StorageException(e);
}
this.storageBufferSize = this.storageBufferSize < DEFAULT_STORAGE_BUFFER_SIZE ? DEFAULT_STORAGE_BUFFER_SIZE
: this.storageBufferSize;
this.storagePersistFactor = this.storagePersistFactor < DEFAULT_STORAGE_PERSIST_FACTOR ? DEFAULT_STORAGE_PERSIST_FACTOR
: this.storagePersistFactor;
}else
createNewStorage = true;
this.currentBuffer = new StorageBuffer(this.storageBufferSize);
try{
this.modifier = createStorageModifier(createNewStorage);
this.searcher = new IndexSearcher(this.storageDir);
}catch (Exception e) {
throw new StorageException("Can not create Searcher/Modifier -- "+e.getMessage(),e);
}
if(createNewStorage)
createAdminAccount();
if(!this.recover)
return;
try{
tryRecover();
}catch (Exception e) {
LOG.fatal("Recovering failed",e);
throw new StorageException("Recovering failed -- "+e.getMessage(),e);
}
this.recoverController = createRecoverController(false,false);
try{
this.recoverController.initialize();
}catch (Exception e) {
LOG.fatal("Can not initialize recover controller",e);
throw new StorageException("Can not initialize recover controller -- "+e.getMessage(),e);
}
}
|
public boolean | isKeepRecoveredFiles()
return this.keepRecoveredFiles;
|
public boolean | isRecover()
return this.recover;
|
protected void | registerNewRecoverWriter()
if(this.recoverController == null || this.recoverController.isRecovering())
return;
this.recoverController.destroy();
this.recoverController = createRecoverController(false,false);
this.recoverController.initialize();
|
protected void | registerNewStorageQuery()Forces the controller to register a new StorageQuery instance.
This method will be called after an index has been modified to make the
changes available for searching.
if(this.isClosed.get())
throw new IllegalStateException("StorageController is already closed -- server is shutting down");
this.storageControllerLock.lock();
try{
if(this.isClosed.get())
throw new IllegalStateException("StorageController is already closed -- server is shutting down");
if (LOG.isInfoEnabled())
LOG.info("new StorageQuery requested -- create new storage buffer");
if (this.storageQuery != null)
this.storageQuery.decrementRef();
this.searcher = new IndexSearcher(this.storageDir);
this.storageQuery = null;
this.currentBuffer = new StorageBuffer(this.storageBufferSize);
}finally{
try{
this.closeCondition.signalAll();
}catch (Throwable e) {/**/}
this.storageControllerLock.unlock();
}
|
public synchronized java.lang.String | releaseId()Creates a unique ID to store as an id for
{@link org.apache.lucene.gdata.data.ServerBaseEntry} instances
try {
return this.idGenerator.getUID();
} catch (InterruptedException e) {
throw new StorageException("Can't release new ID", e);
}
|
protected StorageBuffer | releaseNewStorageBuffer()Creates a new StorageBuffer
if(this.isClosed.get())
throw new IllegalStateException("StorageController is already closed -- server is shutting down");
this.storageControllerLock.lock();
try{
if(this.isClosed.get())
throw new IllegalStateException("StorageController is already closed -- server is shutting down");
return this.currentBuffer;
}finally{
try{
this.closeCondition.signalAll();
}catch (Throwable e) {/**/}
this.storageControllerLock.unlock();
}
|
public void | setBufferSize(int storageBufferSize)The size of the StorageBuffer. This size should be at least
as big as the persist factor to prevent the StorageBuffer from
resizing
this.storageBufferSize = storageBufferSize;
|
public void | setDirectory(java.lang.String storageDirectory)
this.storageDirectory = storageDirectory;
|
public void | setKeepRecoveredFiles(boolean keepRecoveredFiles)
this.keepRecoveredFiles = keepRecoveredFiles;
|
public void | setOptimizeInterval(int indexOptimizeInterval)
this.indexOptimizeInterval = indexOptimizeInterval;
|
public void | setPersistFactor(int storagePersistFactor)
this.storagePersistFactor = storagePersistFactor;
|
public void | setRecover(boolean recover)
this.recover = recover;
|
public void | setStorageDir(org.apache.lucene.store.Directory storageDir)
this.storageDir = storageDir;
|
private void | tryRecover()
if(!this.recover)
return;
LOG.info("try to recover files if there are any");
this.recoverController = createRecoverController(true,false);
this.recoverController.initialize();
this.recoverController.recoverEntries(this.modifier);
this.recoverController.destroy();
|
protected void | writeRecoverEntry(StorageEntryWrapper wrapper)
if(this.recoverController!= null &&!this.recoverController.isRecovering() )
this.recoverController.storageModified(wrapper);
|