Methods Summary |
---|
protected void | close()
if(this.isClosed.get())
throw new IllegalStateException("StorageModifier is already closed");
this.lock.lock();
try {
if(this.isClosed.get())
throw new IllegalStateException("StorageModifier is already closed");
this.isClosed.set(true);
if (LOG.isInfoEnabled())
LOG.info("ForceWrite called -- current modifiedCounter: "
+ this.modifiedCounter + " - persisting changes");
writePersistentIndex(true);
this.modifiedCounter = 0;
} finally {
this.lock.unlock();
}
|
public void | createAccount(StorageAccountWrapper account)Adds a new accountr to the storage. User action will be not buffered. Call to
this method forces the index to be written.
this.lock.lock();
try {
this.forceWriteDocuments.add(account.getLuceneDocument());
storageModified();
} finally {
this.lock.unlock();
}
|
public void | createFeed(StorageFeedWrapper wrapper)Adds a new Feed to the storage. Feed action will be not buffered. Call to
this method forces the index to be written.
this.lock.lock();
try {
this.forceWriteDocuments.add(wrapper.getLuceneDocument());
storageModified();
} finally {
this.lock.unlock();
}
|
public void | deleteAccount(java.lang.String accountName)Deletes the user with the given username. User action will be not
buffered. Call to this method forces the index to be written.
this.lock.lock();
try {
//TODO delete all feeds and entries of this account
this.forceWriteTerms.add(new Term(
StorageAccountWrapper.FIELD_ACCOUNTNAME, accountName));
storageModified();
} finally {
this.lock.unlock();
}
|
public void | deleteEntry(StorageEntryWrapper wrapper)Deletes the entry for the given entry id.
if(wrapper.getOperation() != StorageOperation.DELETE)
throw new StorageException("Illegal method call -- insertEntry does not accept other storage operations than delete");
this.lock.lock();
try {
Term tempTerm = new Term(StorageEntryWrapper.FIELD_ENTRY_ID,
wrapper.getEntryId());
this.deletedDocumentQueue.add(tempTerm);
storageModified();
/*
* If storage not written write entry to recoverfile
* and make the entry available via the buffer
*/
if(this.modifiedCounter != 0)
try{
this.controller.writeRecoverEntry(wrapper);
this.buffer.addDeleted(wrapper.getEntryId(), wrapper.getFeedId());
}catch (Exception e) {
/*
* remove from all resources
*/
this.deletedDocumentQueue.remove(tempTerm);
}
} finally {
this.lock.unlock();
}
|
public void | deleteFeed(java.lang.String feedId)Deletes the feed with the given feed id Feed action will be not buffered.
Call to this method forces the index to be written.
All entries referencing the given feed id will be deleted as well!
this.lock.lock();
try {
this.deletedDocumentQueue.add(new Term(StorageEntryWrapper.FIELD_FEED_REFERENCE,feedId));
this.forceWriteTerms.add(new Term(StorageFeedWrapper.FIELD_FEED_ID,
feedId));
storageModified();
} finally {
this.lock.unlock();
}
|
public void | forceWrite()Persists all changes imediately
if(this.isClosed.get())
throw new IllegalStateException("StorageModifier is already closed");
this.lock.lock();
try {
if (LOG.isInfoEnabled())
LOG.info("ForceWrite called -- current modifiedCounter: "
+ this.modifiedCounter + " - persisting changes");
writePersistentIndex(true);
requestNewIndexModifier();
this.modifiedCounter = 0;
} finally {
this.lock.unlock();
}
|
private void | incrementCounter()
this.optimizeCounter++;
this.modifiedCounter++;
|
public void | insertEntry(StorageEntryWrapper wrapper)Inserts a new Entry to the Lucene index storage
if(wrapper.getOperation() != StorageOperation.INSERT)
throw new StorageException("Illegal method call -- insertEntry does not accept other storage operations than insert");
this.lock.lock();
try {
this.documentMap.put(wrapper.getEntryId(), wrapper
.getLuceneDocument());
storageModified();
/*
* If storage not written write entry to recoverfile
* and make the entry available via the buffer
*/
if(this.modifiedCounter != 0)
try{
this.controller.writeRecoverEntry(wrapper);
this.buffer.addEntry(wrapper);
}catch (Exception e) {
/*
* remove from all resources
*/
this.documentMap.remove(wrapper.getEntryId());
}
} finally {
this.lock.unlock();
}
|
private void | requestNewIndexModifier()
this.controller.registerNewRecoverWriter();
this.controller.registerNewStorageQuery();
this.buffer = this.controller.releaseNewStorageBuffer();
this.modifier = this.controller.createIndexModifier();
|
private void | storageModified()
if(this.isClosed.get())
throw new IllegalStateException("StorageModifier is already closed");
try {
if(this.isClosed.get())
throw new IllegalStateException("StorageModifier is already closed");
incrementCounter();
if (this.persistFactor > this.modifiedCounter
&& this.forceWriteDocuments.size() <= 0
&& this.forceWriteTerms.size() <= 0)
return;
if (LOG.isInfoEnabled())
LOG.info("Storage modified for " + this.modifiedCounter
+ " times. Write Persistent index");
writePersistentIndex((this.optimizeCounter >= this.optimizeInterval));
requestNewIndexModifier();
this.modifiedCounter = 0;
} catch (IOException e) {
LOG.error("Writing persistent index failed - Recovering", e);
throw new StorageException("could not write to storage index -- "+e.getMessage(),e);
}
|
public void | updateAccount(StorageAccountWrapper user)User action will be not buffered. Call to this method forces the index to
be written.
this.lock.lock();
try {
this.forceWriteTerms.add(new Term(
StorageAccountWrapper.FIELD_ACCOUNTNAME, user.getUser()
.getName()));
this.forceWriteDocuments.add(user.getLuceneDocument());
storageModified();
} finally {
this.lock.unlock();
}
|
public void | updateEntry(StorageEntryWrapper wrapper)Updates the given entry. First the alredy persisted entry will be
removed, after marking as deleted the new Entry will be written.
if(wrapper.getOperation() != StorageOperation.UPDATE)
throw new StorageException("Illegal method call -- updateEntry does not accept other storageOperations than update");
this.lock.lock();
try {
Term tempTerm = new Term(StorageEntryWrapper.FIELD_ENTRY_ID,
wrapper.getEntryId());
this.documentMap.put(wrapper.getEntryId(), wrapper
.getLuceneDocument());
this.deletedForUpdateDocumentQueue.add(tempTerm);
storageModified();
/*
* If storage not written write entry to recoverfile
* and make the entry available via the buffer
*/
if(this.modifiedCounter != 0)
try{
this.controller.writeRecoverEntry(wrapper);
this.buffer.addEntry(wrapper);
}catch (Exception e) {
/*
* remove from all resources
*/
this.documentMap.remove(wrapper.getEntryId());
this.deletedForUpdateDocumentQueue.remove(tempTerm);
}
} finally {
this.lock.unlock();
}
|
public void | updateFeed(StorageFeedWrapper wrapper)Feed action will be not buffered. Call to this method forces the index to
be written.
this.lock.lock();
try {
this.forceWriteTerms.add(new Term(StorageFeedWrapper.FIELD_FEED_ID,
wrapper.getFeed().getId()));
this.forceWriteDocuments.add(wrapper.getLuceneDocument());
storageModified();
} finally {
this.lock.unlock();
}
|
private void | writePersistentIndex(boolean optimize)
try {
/*
* first delete all updated documents
*/
for (Term entryIdTerm : this.deletedForUpdateDocumentQueue) {
this.modifier.deleteDocuments(entryIdTerm);
}
for (Term term : this.forceWriteTerms) {
this.modifier.deleteDocuments(term);
}
/*
* add all documents
*/
Collection<Document> documents = this.documentMap.values();
for (Document doc : documents) {
this.modifier.addDocument(doc);
}
/*
* write all users or feeds
*/
for (Document docs : this.forceWriteDocuments) {
this.modifier.addDocument(docs);
}
/*
* delete all documents marked as deleted. As the DocumentIDs are
* unique the document marked as deleted must not persist after the
* index has been written. In the case of an update of a document
* and a previous delete the concurrency component will not allow an
* update. new inserted entries can not be deleted accidently-
*/
for (Term entryIdTerm : this.deletedDocumentQueue) {
this.modifier.deleteDocuments(entryIdTerm);
}
this.modifier.flush();
if (optimize) {
if (LOG.isInfoEnabled())
LOG.info("Optimizing index -- optimize interval "
+ this.optimizeInterval);
this.modifier.optimize();
}
} finally {
if (optimize)
this.optimizeCounter = 0;
this.modifier.close();
this.deletedForUpdateDocumentQueue.clear();
this.deletedDocumentQueue.clear();
this.documentMap.clear();
this.forceWriteDocuments.clear();
this.forceWriteTerms.clear();
}
|