org.apache.wicket.pageStore
Class AsynchronousDataStore

java.lang.Object
  extended by org.apache.wicket.pageStore.AsynchronousDataStore
All Implemented Interfaces:
IDataStore

public class AsynchronousDataStore
extends java.lang.Object
implements IDataStore

Facade for IDataStore that does the actual saving in worker thread.

Creates an Entry for each triple (sessionId, pageId, data) and puts it in entries queue if there is room. Acts as producer.
Later PageSavingRunnable reads in blocking manner from entries and saves each entry. Acts as consumer.

It starts only one instance of PageSavingRunnable because all we need is to make the page storing asynchronous. We don't want to write concurrently in the wrapped IDataStore, though it may happen in the extreme case when the queue is full. These cases should be avoided.

Author:
Matej Knopp

Constructor Summary
AsynchronousDataStore(IDataStore dataStore, int capacity)
          Construct.
 
Method Summary
 void destroy()
          Properly close the data store and possibly open resource handles
 byte[] getData(java.lang.String sessionId, int id)
          Get data associated with the session id and page id.
 boolean isReplicated()
           
 void removeData(java.lang.String sessionId)
          Remove all page data for the session id
 void removeData(java.lang.String sessionId, int id)
          Remove all persisted data related to the session id and page id
 void storeData(java.lang.String sessionId, int id, byte[] data)
          Save the entry in the queue if there is a room or directly pass it to the wrapped IDataStore if there is no such
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsynchronousDataStore

public AsynchronousDataStore(IDataStore dataStore,
                             int capacity)
Construct.

Parameters:
dataStore - the wrapped IDataStore that actually saved the data
capacity - the capacity of the queue that delays the saving
Method Detail

destroy

public void destroy()
Description copied from interface: IDataStore
Properly close the data store and possibly open resource handles

Specified by:
destroy in interface IDataStore
See Also:
IDataStore.destroy()

getData

public byte[] getData(java.lang.String sessionId,
                      int id)
Description copied from interface: IDataStore
Get data associated with the session id and page id.

Specified by:
getData in interface IDataStore
Parameters:
sessionId - Session ID
id - Page ID
Returns:
All the page data persisted
See Also:
IDataStore.getData(java.lang.String, int)

isReplicated

public boolean isReplicated()
Specified by:
isReplicated in interface IDataStore
Returns:
whether the data store is replicated
See Also:
IDataStore.isReplicated()

removeData

public void removeData(java.lang.String sessionId,
                       int id)
Description copied from interface: IDataStore
Remove all persisted data related to the session id and page id

Specified by:
removeData in interface IDataStore
Parameters:
sessionId - Session ID
id - Page ID
See Also:
IDataStore.removeData(java.lang.String, int)

removeData

public void removeData(java.lang.String sessionId)
Description copied from interface: IDataStore
Remove all page data for the session id

Specified by:
removeData in interface IDataStore
Parameters:
sessionId - Session ID
See Also:
IDataStore.removeData(java.lang.String)

storeData

public void storeData(java.lang.String sessionId,
                      int id,
                      byte[] data)
Save the entry in the queue if there is a room or directly pass it to the wrapped IDataStore if there is no such

Specified by:
storeData in interface IDataStore
Parameters:
sessionId - Session ID
id - Page ID
data - Page data
See Also:
IDataStore.storeData(java.lang.String, int, byte[])


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.