org.apache.lucene.gdata.storage.lucenestorage
Class StorageBuffer

java.lang.Object
  extended by org.apache.lucene.gdata.storage.lucenestorage.StorageBuffer

public class StorageBuffer
extends Object

The StorageBuffer is used to buffer incoming updates, deletes and inserts to the storage. The storage uses an lucene index to store the enries. As modifying the index all the time an altering request comes in is not efficent. The entries will be added to the buffer to be available for incoming storage queries. If the loadfactor for the StorageModifier is reached the modifier will perform a batch update on the index. Each entry will be associated with a feed id inside a associative datastructure to return a requested entry efficiently.

This implementation uses ReadWriteLock. The read lock may be held simultaneously by multiple reader threads, so long as there are no writers. The write lock is exclusive.

The entry and feed ID's must not be a composite key. The entry and feed ID must be unique.

Author:
Simon Willnauer
See Also:
ReentrantReadWriteLock, StorageModifier, StorageCoreController

Field Summary
protected static int DEFAULT_BUFFER_COUNT
           
 
Constructor Summary
protected StorageBuffer(int expectedBufferCount)
          Constructs a new StorageBuffer.
 
Method Summary
 void addDeleted(String entryId, String feedId)
          Adds a deleted entry to the buffer.
 void addEntry(StorageEntryWrapper wrapper)
          Adds a StorageEntryWrapper to the buffer.
 void close()
          clears the buffer -
 int getBufferSize()
           
 StorageEntryWrapper getEntry(String entryId, String feedId)
          Returns an entry for the given entry id in the feed context spezified by the feed id;
 String[] getExculdList()
          The buffer contains updated and delete entries.
protected  Long getFeedLastModified(String feedId)
          the timestamp of the last modification for the given feed id
protected  Set<Map.Entry<String,Long>> getLastModified()
           
 List<StorageEntryWrapper> getSortedEntries(String feedId)
          Returns all entries for the given feed id sorted by the update timestamp desc.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BUFFER_COUNT

protected static final int DEFAULT_BUFFER_COUNT
See Also:
Constant Field Values
Constructor Detail

StorageBuffer

protected StorageBuffer(int expectedBufferCount)
Constructs a new StorageBuffer.

The expectedBufferCount sould be higher than the maximum of entries added to the buffer, resizing the buffer is very efficient. For detailed infomation HashMap as this is used inside the buffer

Parameters:
expectedBufferCount - - the expected size of the buffer
Method Detail

addEntry

public void addEntry(StorageEntryWrapper wrapper)
Adds a StorageEntryWrapper to the buffer. If a wrapper representing the same entry are already in the buffer the wrapper will be replaced.

This method does ignore already delted entries. This should before the entry is added to the buffer.

Parameters:
wrapper - - the wrapper to buffer

getFeedLastModified

protected Long getFeedLastModified(String feedId)
the timestamp of the last modification for the given feed id

Parameters:
feedId - - feed id
Returns:
timestamp

getLastModified

protected Set<Map.Entry<String,Long>> getLastModified()

getSortedEntries

public List<StorageEntryWrapper> getSortedEntries(String feedId)
Returns all entries for the given feed id sorted by the update timestamp desc.

Parameters:
feedId - - the feed id
Returns:
a List of all StorageEntryWrapper object buffered in this buffer or an empty list if not entry has been buffered for the given feed

addDeleted

public void addDeleted(String entryId,
                       String feedId)
Adds a deleted entry to the buffer.

Parameters:
entryId - - the deleted entry id
feedId - - the feed of the entry

getEntry

public StorageEntryWrapper getEntry(String entryId,
                                    String feedId)
Returns an entry for the given entry id in the feed context spezified by the feed id;

Parameters:
entryId - - the id of the entry to return
feedId - - the feed containing the entry
Returns:
- the entry or null if the corresponding entry is not in the buffer.

getExculdList

public String[] getExculdList()
The buffer contains updated and delete entries. These entries are already available in the lucene index but should not be found during search.

This list contains all entries should not be found by the index searcher. This method creates a copy of the current list to prevent concurrent modification exceptions while iteration over the collection.

Returns:
- a String array of entries to be omitted from a lucene index search
See Also:
ModifiedEntryFilter

close

public void close()
clears the buffer -


getBufferSize

public int getBufferSize()
Returns:
Returns the bufferSize.


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.