public class AsynchronousPageStore extends Object implements IPageStore
IPageStore that does the actual saving in worker thread.
Creates an Entry for each double (sessionId, page) 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.
PageSavingRunnable because all we need is to make the page
storing asynchronous. We don't want to write concurrently in the wrapped IPageStore,
though it may happen in the extreme case when the queue is full. These cases should be avoided.
Based on AsynchronousDataStore (@author Matej Knopp).| Constructor and Description |
|---|
AsynchronousPageStore(IPageStore delegate,
int capacity)
Construct.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
canBeAsynchronous() |
IManageablePage |
convertToPage(Object page)
Converts a page representation to an instance of
IManageablePage |
void |
destroy()
Destroy the store.
|
IManageablePage |
getPage(String sessionId,
int pageId)
Restores a page from the persistent layer.
|
Serializable |
prepareForSerialization(String sessionId,
Serializable page)
Process the page before the it gets serialized.
|
void |
removePage(String sessionId,
int pageId)
Removes a page from the persistent layer.
|
Object |
restoreAfterSerialization(Serializable serializable)
This method should restore the serialized page to intermediate object that can be converted
to real page instance using
IPageStore.convertToPage(Object). |
void |
storePage(String sessionId,
IManageablePage page)
Stores the page to a persistent layer.
|
void |
unbind(String sessionId)
The page store should cleanup all the pages for that sessionid.
|
public AsynchronousPageStore(IPageStore delegate, int capacity)
delegate - the wrapped IPageStore that actually saved the pagecapacity - the capacity of the queue that delays the savingpublic void destroy()
IPageStoredestroy in interface IPageStorepublic IManageablePage getPage(String sessionId, int pageId)
IPageStoregetPage in interface IPageStoresessionId - The session of the page that must be removedpageId - The id of the page.public void removePage(String sessionId, int pageId)
IPageStoreremovePage in interface IPageStoresessionId - The session of the page that must be removedpageId - The id of the page.public void storePage(String sessionId, IManageablePage page)
IPageStorestorePage in interface IPageStoresessionId - The session of the page that must be removedpage - The page to storepublic void unbind(String sessionId)
IPageStoreunbind in interface IPageStoresessionId - The session of the page that must be removedpublic Serializable prepareForSerialization(String sessionId, Serializable page)
IPageStoreIPageStore.restoreAfterSerialization(Serializable).prepareForSerialization in interface IPageStoresessionId - The session of the page that must be removedpublic Object restoreAfterSerialization(Serializable serializable)
IPageStoreIPageStore.convertToPage(Object).restoreAfterSerialization in interface IPageStorepublic IManageablePage convertToPage(Object page)
IPageStoreIManageablePageconvertToPage in interface IPageStorepage - some kind of page representationpublic boolean canBeAsynchronous()
canBeAsynchronous in interface IPageStoreAsynchronousPageStoreCopyright © 2006–2018 Apache Software Foundation. All rights reserved.