org.apache.wicket.protocol.http.pagestore
Class DiskPageStore

java.lang.Object
  extended by org.apache.wicket.protocol.http.pagestore.AbstractPageStore
      extended by org.apache.wicket.protocol.http.pagestore.DiskPageStore
All Implemented Interfaces:
SecondLevelCacheSessionStore.IPageStore, SecondLevelCacheSessionStore.ISerializationAwarePageStore

public class DiskPageStore
extends AbstractPageStore
implements SecondLevelCacheSessionStore.ISerializationAwarePageStore

SecondLevelCacheSessionStore.IPageStore implementation that stores the serialized pages grouped in a single file per pagemap.

This store was designed to overcome the problems of FilePageStore which stores the pages in separate files per page.

DiskPageStore allows to set maximum size for pagemap file and maximum size for session. If the maximum size for session is exceeded, the last recently used pagemap file is removed.

Author:
Matej Knopp

Nested Class Summary
protected static class DiskPageStore.PageMapEntry
          Each PageMap is represented by this class.
protected static class DiskPageStore.SessionEntry
          Represents a session,
 
Nested classes/interfaces inherited from class org.apache.wicket.protocol.http.pagestore.AbstractPageStore
AbstractPageStore.SerializedPage
 
Constructor Summary
DiskPageStore()
          Creates a new DiskPageStore instance.
DiskPageStore(java.io.File fileStoreFolder, int maxSizePerPagemap, int maxSizePerSession, int fileChannelPoolCapacity)
          Creates a new DiskPageStore instance.
DiskPageStore(int maxSizePerPagemap, int maxSizePerSession, int fileChannelPoolCapacity)
          Creates a new DiskPageStore instance.
 
Method Summary
 boolean containsPage(java.lang.String sessionId, java.lang.String pageMapName, int pageId, int pageVersion)
          Returns whether the PageStore contains given page.
 Page convertToPage(java.lang.Object page)
           
 void destroy()
          Destroy the store.
protected  void flushPagesToSaveList(java.lang.String sessionId, java.util.List list)
          Saves all entries from the specified list.
protected  java.io.File getFileStoreFolder()
          Returns the "root" file store folder.
protected  int getLastRecentlySerializedPagesCacheSize()
           
protected  int getMaxSizePerPageMap()
          Return maximum pagemap file size (in bytes).
protected  int getMaxSizePerSession()
          Returns maximum size per session (in bytes).
 Page getPage(java.lang.String sessionId, java.lang.String pagemap, int id, int versionNumber, int ajaxVersionNumber)
          Restores a page version from the persistent layer.
protected  java.util.List getPagesToSaveList(java.lang.String sessionId)
          Returns the list of pages to be saved for the specified session id.
protected  int getSavingThreadSleepTime()
          Returns the amount time in milliseconds for the saving thread to sleep between checking whether there are pending serialized pages to be saved.
protected  DiskPageStore.SessionEntry getSessionEntry(java.lang.String sessionId, boolean createIfDoesNotExist)
          Returns the SessionEntry for session with given id.
protected  java.io.File getSessionFolder(java.lang.String sessionId, boolean create)
          Returns the folder for the specified sessions.
protected  boolean isSynchronous()
          Returns whether the DiskPageStore should work in synchronous or asynchronous mode.
protected  void onPagesSerialized(java.lang.String sessionId, java.util.List pages)
          Hook for processing serialized pages (e.g.
 void pageAccessed(java.lang.String sessionId, Page page)
          This method is called when the page is accessed.
 java.io.Serializable prepareForSerialization(java.lang.String sessionId, java.lang.Object page)
          Process the page before the it gets serialized.
 void removePage(java.lang.String sessionId, java.lang.String pageMap, int id)
          Removes a page from the persistent layer.
 java.lang.Object restoreAfterSerialization(java.io.Serializable serializable)
          This method should restore the serialized page to intermediate object that can be converted to real page instance using SecondLevelCacheSessionStore.ISerializationAwarePageStore.convertToPage(Object).
 void setLastRecentlySerializedPagesCacheSize(int lastRecentlySerializedPagesCacheSize)
          Sets the number of last recently serialized pages kept in cache.
protected  boolean storeAfterSessionReplication()
           
 void storePage(java.lang.String sessionId, Page page)
          Stores the page to a persistent layer.
protected  void storeSerializedPages(java.lang.String sessionId, java.util.List pages)
          Stores the serialized pages.
 void unbind(java.lang.String sessionId)
          The pagestore should cleanup all the pages for that sessionid.
 
Methods inherited from class org.apache.wicket.protocol.http.pagestore.AbstractPageStore
deserializePage, serializePage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DiskPageStore

public DiskPageStore(java.io.File fileStoreFolder,
                     int maxSizePerPagemap,
                     int maxSizePerSession,
                     int fileChannelPoolCapacity)
Creates a new DiskPageStore instance.

Parameters:
fileStoreFolder - folder in which the session folders containing pagemap files will be stored
maxSizePerPagemap - the maximum size of pagemap file (in bytes)
maxSizePerSession - the maximum size of session (in bytes)
fileChannelPoolCapacity - the maximum number of concurrently opened files (higher number improves performance under heavy load).

DiskPageStore

public DiskPageStore(int maxSizePerPagemap,
                     int maxSizePerSession,
                     int fileChannelPoolCapacity)
Creates a new DiskPageStore instance.

Parameters:
maxSizePerPagemap - the maximum size of pagemap file (in bytes)
maxSizePerSession - the maximum size of session (in bytes)
fileChannelPoolCapacity - the maximum number of concurrently opened files (higher number improves performance under heavy load).

DiskPageStore

public DiskPageStore()
Creates a new DiskPageStore instance.

Method Detail

getSessionFolder

protected java.io.File getSessionFolder(java.lang.String sessionId,
                                        boolean create)
Returns the folder for the specified sessions. If the folder doesn't exist and the create flag is set, the folder will be created.

Parameters:
sessionId -
create -
Returns:
folder used to store session data

getMaxSizePerPageMap

protected int getMaxSizePerPageMap()
Return maximum pagemap file size (in bytes).

Returns:

getMaxSizePerSession

protected int getMaxSizePerSession()
Returns maximum size per session (in bytes). After the session exceeds this size, appropriate number of last recently used pagemap files will be removed.

Returns:

getFileStoreFolder

protected java.io.File getFileStoreFolder()
Returns the "root" file store folder.

Returns:

destroy

public void destroy()
Description copied from interface: SecondLevelCacheSessionStore.IPageStore
Destroy the store.

Specified by:
destroy in interface SecondLevelCacheSessionStore.IPageStore
See Also:
SecondLevelCacheSessionStore.IPageStore.destroy()

getSessionEntry

protected DiskPageStore.SessionEntry getSessionEntry(java.lang.String sessionId,
                                                     boolean createIfDoesNotExist)
Returns the SessionEntry for session with given id. If the entry does not yet exist and the createIfDoesNotExist attribute is set, new SessionEntry will be created.

Parameters:
sessionId -
createIfDoesNotExist -
Returns:

getPage

public Page getPage(java.lang.String sessionId,
                    java.lang.String pagemap,
                    int id,
                    int versionNumber,
                    int ajaxVersionNumber)
Description copied from interface: SecondLevelCacheSessionStore.IPageStore
Restores a page version from the persistent layer.

Note that the versionNumber and ajaxVersionNumber parameters may be -1.

Specified by:
getPage in interface SecondLevelCacheSessionStore.IPageStore
Returns:
The page
See Also:
SecondLevelCacheSessionStore.IPageStore.getPage(java.lang.String, java.lang.String, int, int, int)

pageAccessed

public void pageAccessed(java.lang.String sessionId,
                         Page page)
Description copied from interface: SecondLevelCacheSessionStore.IPageStore
This method is called when the page is accessed. A IPageStore implementation can block until a save of that page version is done. So that a specific page version is always restore able.

Specified by:
pageAccessed in interface SecondLevelCacheSessionStore.IPageStore
See Also:
SecondLevelCacheSessionStore.IPageStore.pageAccessed(java.lang.String, org.apache.wicket.Page)

removePage

public void removePage(java.lang.String sessionId,
                       java.lang.String pageMap,
                       int id)
Description copied from interface: SecondLevelCacheSessionStore.IPageStore
Removes a page from the persistent layer.

Specified by:
removePage in interface SecondLevelCacheSessionStore.IPageStore
Parameters:
sessionId - The session of the page that must be removed
pageMap - The pagemap of the page that must be removed
id - The id of the page.
See Also:
SecondLevelCacheSessionStore.IPageStore.removePage(java.lang.String, java.lang.String, int)

storeSerializedPages

protected void storeSerializedPages(java.lang.String sessionId,
                                    java.util.List pages)
Stores the serialized pages. The storing is done either immediately (in synchronous mode) or it's scheduled to be stored by the worker thread.

Parameters:
sessionId -
pages -

onPagesSerialized

protected void onPagesSerialized(java.lang.String sessionId,
                                 java.util.List pages)
Hook for processing serialized pages (e.g. sending those across cluster)

Parameters:
sessionId -
pages -

storePage

public void storePage(java.lang.String sessionId,
                      Page page)
Description copied from interface: SecondLevelCacheSessionStore.IPageStore
Stores the page to a persistent layer. The page should be stored under the id and the version number.

Specified by:
storePage in interface SecondLevelCacheSessionStore.IPageStore
See Also:
SecondLevelCacheSessionStore.IPageStore.storePage(java.lang.String, org.apache.wicket.Page)

unbind

public void unbind(java.lang.String sessionId)
Description copied from interface: SecondLevelCacheSessionStore.IPageStore
The pagestore should cleanup all the pages for that sessionid.

Specified by:
unbind in interface SecondLevelCacheSessionStore.IPageStore
See Also:
SecondLevelCacheSessionStore.IPageStore.unbind(java.lang.String)

getPagesToSaveList

protected java.util.List getPagesToSaveList(java.lang.String sessionId)
Returns the list of pages to be saved for the specified session id. If the list is not found, new list is created.

Parameters:
sessionId -
Returns:

flushPagesToSaveList

protected void flushPagesToSaveList(java.lang.String sessionId,
                                    java.util.List list)
Saves all entries from the specified list.

Parameters:
sessionId -
list -

getSavingThreadSleepTime

protected int getSavingThreadSleepTime()
Returns the amount time in milliseconds for the saving thread to sleep between checking whether there are pending serialized pages to be saved.

Returns:

isSynchronous

protected boolean isSynchronous()
Returns whether the DiskPageStore should work in synchronous or asynchronous mode. Asynchronous mode uses a worker thread to save pages, which results in smoother performance.

Returns:

setLastRecentlySerializedPagesCacheSize

public void setLastRecentlySerializedPagesCacheSize(int lastRecentlySerializedPagesCacheSize)
Sets the number of last recently serialized pages kept in cache. The cache is used to aid performance on session replication.

Parameters:
lastRecentlySerializedPagesCacheSize -

getLastRecentlySerializedPagesCacheSize

protected int getLastRecentlySerializedPagesCacheSize()
Returns:

prepareForSerialization

public java.io.Serializable prepareForSerialization(java.lang.String sessionId,
                                                    java.lang.Object page)
Process the page before the it gets serialized. The page can be either real page instance of object returned by SecondLevelCacheSessionStore.ISerializationAwarePageStore.restoreAfterSerialization(Serializable).

Specified by:
prepareForSerialization in interface SecondLevelCacheSessionStore.ISerializationAwarePageStore
Returns:
The Page itself or a SerializedContainer for that page

storeAfterSessionReplication

protected boolean storeAfterSessionReplication()

restoreAfterSerialization

public java.lang.Object restoreAfterSerialization(java.io.Serializable serializable)
Description copied from interface: SecondLevelCacheSessionStore.ISerializationAwarePageStore
This method should restore the serialized page to intermediate object that can be converted to real page instance using SecondLevelCacheSessionStore.ISerializationAwarePageStore.convertToPage(Object).

Specified by:
restoreAfterSerialization in interface SecondLevelCacheSessionStore.ISerializationAwarePageStore
Returns:
Page
See Also:
SecondLevelCacheSessionStore.ISerializationAwarePageStore.restoreAfterSerialization(java.io.Serializable)

convertToPage

public Page convertToPage(java.lang.Object page)
Specified by:
convertToPage in interface SecondLevelCacheSessionStore.ISerializationAwarePageStore
Returns:

containsPage

public boolean containsPage(java.lang.String sessionId,
                            java.lang.String pageMapName,
                            int pageId,
                            int pageVersion)
Description copied from interface: SecondLevelCacheSessionStore.IPageStore
Returns whether the PageStore contains given page.

Specified by:
containsPage in interface SecondLevelCacheSessionStore.IPageStore
Returns:
boolean If the page was found
See Also:
SecondLevelCacheSessionStore.IPageStore.containsPage(java.lang.String, java.lang.String, int, int)


Copyright © 2004-2010 Apache Software Foundation. All Rights Reserved.