You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by sv...@apache.org on 2018/11/09 14:52:10 UTC

[17/21] wicket git commit: WICKET-6563 new IPageStore implementation

http://git-wip-us.apache.org/repos/asf/wicket/blob/f6485517/wicket-core/src/main/java/org/apache/wicket/pageStore/SerializingPageStore.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/pageStore/SerializingPageStore.java b/wicket-core/src/main/java/org/apache/wicket/pageStore/SerializingPageStore.java
new file mode 100644
index 0000000..d588262
--- /dev/null
+++ b/wicket-core/src/main/java/org/apache/wicket/pageStore/SerializingPageStore.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.pageStore;
+
+import org.apache.wicket.page.IManageablePage;
+import org.apache.wicket.serialize.ISerializer;
+import org.apache.wicket.util.lang.Args;
+
+/**
+ * A store that serializes all pages before delegating and vice versa.
+ */
+public class SerializingPageStore extends DelegatingPageStore
+{
+
+	private ISerializer serializer;
+
+	/**
+	 * @param delegate
+	 *            store to delegate to
+	 * @param serializer
+	 *            serializer to use if session gets persisted
+	 */
+	public SerializingPageStore(IPageStore delegate, ISerializer serializer)
+	{
+		super(delegate);
+
+		this.serializer = Args.notNull(serializer, "serializer");
+	}
+
+	/**
+	 * Versioning is supported, since pages are always serialized.
+	 */
+	@Override
+	public boolean supportsVersioning()
+	{
+		return true;
+	}
+
+	/**
+	 * Supports asynchronous add if the delegate supports it.
+	 */
+	@Override
+	public boolean canBeAsynchronous(IPageContext context)
+	{
+		return getDelegate().canBeAsynchronous(context);
+	}
+	
+	@Override
+	public IManageablePage getPage(IPageContext context, int id)
+	{
+		IManageablePage page = super.getPage(context, id);
+
+		if (page instanceof SerializedPage) {
+			page = (IManageablePage)serializer.deserialize(((SerializedPage)page).getData());
+		}
+		return page;
+	}
+
+	@Override
+	public void addPage(IPageContext context, IManageablePage page)
+	{
+		if (page instanceof SerializedPage == false) {
+			page = new SerializedPage(page.getPageId(), page.getClass().getName(), serializer.serialize(page));
+		}
+		super.addPage(context, page);
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/wicket/blob/f6485517/wicket-core/src/main/java/org/apache/wicket/pageStore/disk/NestedFolders.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/pageStore/disk/NestedFolders.java b/wicket-core/src/main/java/org/apache/wicket/pageStore/disk/NestedFolders.java
new file mode 100644
index 0000000..0f2077c
--- /dev/null
+++ b/wicket-core/src/main/java/org/apache/wicket/pageStore/disk/NestedFolders.java
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.pageStore.disk;
+
+import java.io.File;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.wicket.util.file.Files;
+import org.apache.wicket.util.lang.Args;
+
+/**
+ * Helps creating nested folders.
+ * 
+ * @author svenmeier
+ */
+public class NestedFolders
+{
+	private final File base;
+	
+	/**
+	 * Create folders in the given base folder.
+	 * 
+	 * @param base base has to be a folder
+	 */
+	public NestedFolders(File base) {
+		this.base = Args.notNull(base, "base");
+	}
+	
+	public File getBase()
+	{
+		return base;
+	}
+	
+	/**
+	 * Get a nested folder for the given name.
+	 * 
+	 * @param name name 
+	 * @param create
+	 * @return
+	 */
+	public File get(String name, final boolean create) {
+		name = name.replace('*', '_');
+		name = name.replace('/', '_');
+		name = name.replace(':', '_');
+
+		String path = createPathFrom(name);
+
+		File folder = new File(base, path);
+		if (create && folder.exists() == false) {
+			Files.mkdirs(folder);
+		}
+		return folder;
+	}
+
+	private String createPathFrom(final String name) {
+		int hash = Math.abs(name.hashCode());
+		String low = String.valueOf(hash % 9973);
+		String high = String.valueOf((hash / 9973) % 9973);
+		StringBuilder bs = new StringBuilder(name.length() + 10);
+		bs.append(low);
+		bs.append(File.separator);
+		bs.append(high);
+		bs.append(File.separator);
+		bs.append(name);
+
+		return bs.toString();
+	}
+
+	/**
+	 * Remove a nested folder.
+	 * 
+	 * @param name name of folder
+	 */
+	public void remove(String name)
+	{
+		File folder = get(name, false);
+		if (folder.exists()) {
+			Files.removeFolder(folder);
+			
+			File high = folder.getParentFile();
+			if (high.list().length == 0) {
+				if (Files.removeFolder(high)) {
+					File low = high.getParentFile();
+					if (low.list().length == 0) {
+						Files.removeFolder(low);
+					}
+				}
+			}
+		}
+	}
+
+	public Set<File> getAll()
+	{
+		Set<File> files = new HashSet<>();
+		
+		if (base.exists()) {
+			for (File low : base.listFiles()) {
+				for (File high: low.listFiles()) {
+					for (File file : high.listFiles()) {
+						files.add(file);
+					}
+				}
+			}
+		}
+		
+		return files;
+	}
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/f6485517/wicket-core/src/main/java/org/apache/wicket/pageStore/disk/PageWindowManager.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/pageStore/disk/PageWindowManager.java b/wicket-core/src/main/java/org/apache/wicket/pageStore/disk/PageWindowManager.java
new file mode 100644
index 0000000..f20d156
--- /dev/null
+++ b/wicket-core/src/main/java/org/apache/wicket/pageStore/disk/PageWindowManager.java
@@ -0,0 +1,493 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.pageStore.disk;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.wicket.pageStore.IPersistedPage;
+import org.apache.wicket.util.collections.IntHashMap;
+import org.apache.wicket.util.lang.Bytes;
+
+/**
+ * Manages positions and size of chunks of data in a file.
+ * <p>
+ * The data is stored inside the file in a cyclic way. Newer pages are placed after older ones,
+ * until the maximum file size is reached. After that, the next page is stored in the beginning of
+ * the file.
+ * 
+ * @author Matej Knopp
+ */
+public class PageWindowManager implements Serializable
+{
+	private static final long serialVersionUID = 1L;
+
+	/**
+	 * Contains information about a page inside the file.
+	 * 
+	 * @author Matej Knopp
+	 */
+	public static class FileWindow implements IPersistedPage, Serializable
+	{
+		private static final long serialVersionUID = 1L;
+
+		/** id of data or -1 if the window is empty */
+		private int id;
+
+		private String type;
+
+		/** offset in the file where the serialized page data begins */
+		private int filePartOffset;
+
+		/** size of serialized page data */
+		private int filePartSize;
+
+		@Override
+		public int getPageId()
+		{
+			return id;
+		}
+
+		@Override
+		public String getPageType() {
+			return type;
+		}
+		
+		@Override
+		public Bytes getPageSize()
+		{
+			return Bytes.bytes(filePartSize);
+		}
+
+		public int getFilePartOffset()
+		{
+			return filePartOffset;
+		}
+		
+		public int getFilePartSize()
+		{
+			return filePartSize;
+		}
+	}
+
+	private final List<FileWindow> windows = new ArrayList<FileWindow>();
+
+	/**
+	 * map from page id to list of pagewindow indices (referring to the windows list) - to improve
+	 * searching speed the index must be cleaned when the instances in the windows list change their
+	 * indexes (e.g. items are shifted on page window removal)
+	 */
+	private IntHashMap<Integer> idToWindowIndex = null;
+
+	/**
+	 * Inversed index of #idToWindowIndex
+	 */
+	private IntHashMap<Integer> windowIndexToPageId = null;
+
+	/** index of last added page */
+	private int indexPointer = -1;
+
+	private int totalSize = 0;
+
+	/**
+	 * Maximum page size. After this size is exceeded, the pages will be saved starting at the
+	 * beginning of file.
+	 */
+	private final long maxSize;
+
+	/**
+	 * 
+	 * @param pageId
+	 * @param windowIndex
+	 */
+	private void putWindowIndex(int pageId, int windowIndex)
+	{
+		if (idToWindowIndex != null && pageId != -1 && windowIndex != -1)
+		{
+			Integer oldPageId = windowIndexToPageId.remove(windowIndex);
+			if (oldPageId != null)
+			{
+				idToWindowIndex.remove(oldPageId);
+			}
+			idToWindowIndex.put(pageId, windowIndex);
+			windowIndexToPageId.put(windowIndex, pageId);
+		}
+	}
+
+	/**
+	 * 
+	 * @param pageId
+	 */
+	private void removeWindowIndex(int pageId)
+	{
+		Integer windowIndex = idToWindowIndex.remove(pageId);
+		if (windowIndex != null)
+		{
+			windowIndexToPageId.remove(windowIndex);
+		}
+	}
+
+	/**
+	 * 
+	 */
+	private void rebuildIndices()
+	{
+		idToWindowIndex = null;
+		idToWindowIndex = new IntHashMap<Integer>();
+		windowIndexToPageId = null;
+		windowIndexToPageId = new IntHashMap<Integer>();
+		for (int i = 0; i < windows.size(); ++i)
+		{
+			FileWindow window = windows.get(i);
+			putWindowIndex(window.id, i);
+		}
+	}
+
+	/**
+	 * Returns the index of the given page in the {@link #windows} list.
+	 * 
+	 * @param pageId
+	 * @return window index
+	 */
+	private int getWindowIndex(int pageId)
+	{
+		if (idToWindowIndex == null)
+		{
+			rebuildIndices();
+		}
+
+		Integer result = idToWindowIndex.get(pageId);
+		return result != null ? result : -1;
+	}
+
+	/**
+	 * Increments the {@link #indexPointer}. If the maximum file size has been reached, the
+	 * {@link #indexPointer} is set to 0.
+	 * 
+	 * @return new index pointer
+	 */
+	private int incrementIndexPointer()
+	{
+		if ((maxSize > 0) && (totalSize >= maxSize) && (indexPointer == windows.size() - 1))
+		{
+			indexPointer = 0;
+		}
+		else
+		{
+			++indexPointer;
+		}
+		return indexPointer;
+	}
+
+	/**
+	 * Returns the offset in file of the window on given index. The offset is counted by getting the
+	 * previous page offset and adding the previous page size to it.
+	 * 
+	 * @param index
+	 * @return window file offset
+	 */
+	private int getWindowFileOffset(int index)
+	{
+		if (index > 0)
+		{
+			FileWindow window = windows.get(index - 1);
+			return window.filePartOffset + window.filePartSize;
+		}
+		return 0;
+	}
+
+	/**
+	 * Splits the window with given index to two windows. First of those will have size specified by
+	 * the argument, the other one will fill up the rest of the original window.
+	 * 
+	 * @param index
+	 * @param size
+	 */
+	private void splitWindow(int index, int size)
+	{
+		FileWindow window = windows.get(index);
+		int delta = window.filePartSize - size;
+
+		if (index == windows.size() - 1)
+		{
+			// if this is last window
+			totalSize -= delta;
+			window.filePartSize = size;
+		}
+		else if (window.filePartSize != size)
+		{
+			FileWindow newWindow = new FileWindow();
+			newWindow.id = -1;
+			window.filePartSize = size;
+
+			windows.add(index + 1, newWindow);
+
+			newWindow.filePartOffset = getWindowFileOffset(index + 1);
+			newWindow.filePartSize = delta;
+		}
+
+		idToWindowIndex = null;
+		windowIndexToPageId = null;
+	}
+
+	/**
+	 * Merges the window with given index with the next window. The resulting window will have size
+	 * of the two windows summed together.
+	 * 
+	 * @param index
+	 */
+	private void mergeWindowWithNext(int index)
+	{
+		if (index < windows.size() - 1)
+		{
+			FileWindow window = windows.get(index);
+			FileWindow next = windows.get(index + 1);
+			window.filePartSize += next.filePartSize;
+
+			windows.remove(index + 1);
+			idToWindowIndex = null; // reset index
+			windowIndexToPageId = null;
+		}
+	}
+
+	/**
+	 * Adjusts the window on given index to the specified size. If the new size is smaller than the
+	 * window size, the window will be split. Otherwise the window will be merged with as many
+	 * subsequent window as necessary. In case the window is last window in the file, the size will
+	 * be adjusted without splitting or merging.
+	 * 
+	 * @param index
+	 * @param size
+	 */
+	private void adjustWindowSize(int index, int size)
+	{
+		FileWindow window = windows.get(index);
+
+		// last window, just adjust size
+		if (index == windows.size() - 1)
+		{
+			int delta = size - window.filePartSize;
+			totalSize += delta;
+			window.filePartSize = size;
+		}
+		else
+		{
+			// merge as many times as necessary
+			while (window.filePartSize < size && index < windows.size() - 1)
+			{
+				mergeWindowWithNext(index);
+			}
+
+			// done merging - do we have enough room ?
+			if (window.filePartSize < size)
+			{
+				// no, this is the last window
+				int delta = size - window.filePartSize;
+				totalSize += delta;
+				window.filePartSize = size;
+			}
+			else
+			{
+				// yes, we might want to split the window, so that we don't lose
+				// space when the created window was too big
+				splitWindow(index, size);
+			}
+		}
+
+		window.id = -1;
+	}
+
+	/**
+	 * Allocates window on given index with to size. If the index is pointing to existing window,
+	 * the window size will be adjusted. Otherwise a new window with appropriated size will be
+	 * created.
+	 * 
+	 * @param index
+	 * @param size
+	 * @return page window
+	 */
+	private FileWindow allocatePageWindow(int index, int size)
+	{
+		final FileWindow window;
+
+		// new window
+		if (index == windows.size())
+		{
+			// new page window
+			window = new FileWindow();
+			window.filePartOffset = getWindowFileOffset(index);
+			totalSize += size;
+			window.filePartSize = size;
+			windows.add(window);
+		}
+		else
+		{
+			// get the window
+			window = windows.get(index);
+
+			// adjust if necessary
+			if (window.filePartSize != size)
+			{
+				adjustWindowSize(index, size);
+			}
+		}
+
+		return window;
+	}
+
+	/**
+	 * Creates and returns a new page window for given page.
+	 * 
+	 * @param pageId
+	 * @param type 
+	 * @param size
+	 * @return page window
+	 */
+	public synchronized FileWindow createPageWindow(int pageId, String pageType, int size)
+	{
+		int index = getWindowIndex(pageId);
+
+		// if we found the page window, mark it as invalid
+		if (index != -1)
+		{
+			removeWindowIndex(pageId);
+			(windows.get(index)).id = -1;
+		}
+
+		// if we are not going to reuse a page window (because it's not on
+		// indexPointer position or because we didn't find it), increment the
+		// indexPointer
+		if (index == -1 || index != indexPointer)
+		{
+			index = incrementIndexPointer();
+		}
+
+		FileWindow window = allocatePageWindow(index, size);
+		window.id = pageId;
+		window.type = pageType;
+
+		putWindowIndex(pageId, index);
+		return window;
+	}
+
+	/**
+	 * Returns the page window for given page or null if no window was found.
+	 * 
+	 * @param pageId
+	 * @return page window or null
+	 */
+	public synchronized FileWindow getPageWindow(int pageId)
+	{
+		int index = getWindowIndex(pageId);
+		if (index != -1)
+		{
+			return windows.get(index);
+		}
+		return null;
+	}
+
+	/**
+	 * Removes the page window for given page.
+	 * 
+	 * @param pageId
+	 */
+	public synchronized void removePage(int pageId)
+	{
+		int index = getWindowIndex(pageId);
+		if (index != -1)
+		{
+			FileWindow window = windows.get(index);
+			removeWindowIndex(pageId);
+			if (index == windows.size() - 1)
+			{
+				windows.remove(index);
+				totalSize -= window.filePartSize;
+				if (indexPointer == index)
+				{
+					--indexPointer;
+				}
+			}
+			else
+			{
+				window.id = -1;
+			}
+		}
+	}
+
+	/**
+	 * Returns last n saved page windows.
+	 * 
+	 * @return list of page windows
+	 */
+	public synchronized List<FileWindow> getFileWindows()
+	{
+		List<FileWindow> result = new ArrayList<FileWindow>();
+
+		// start from current index to 0
+		int currentIndex = indexPointer;
+
+		do
+		{
+			if (currentIndex == -1)
+			{
+				break;
+			}
+
+			if (currentIndex < windows.size())
+			{
+				FileWindow window = windows.get(currentIndex);
+				if (window.id != -1)
+				{
+					result.add(window);
+				}
+			}
+
+			--currentIndex;
+			if (currentIndex == -1)
+			{
+				// rewind to the last entry and collect all entries until current index
+				currentIndex = windows.size() - 1;
+			}
+		}
+		while (currentIndex != indexPointer);
+
+		return result;
+	}
+
+	/**
+	 * Creates a new PageWindowManager.
+	 * 
+	 * @param maxSize
+	 *            maximum page size. After this size is exceeded, the pages will be saved starting
+	 *            at the beginning of file
+	 */
+	public PageWindowManager(long maxSize)
+	{
+		this.maxSize = maxSize;
+	}
+
+	/**
+	 * Returns the size of all saved pages
+	 * 
+	 * @return total size
+	 */
+	public synchronized int getTotalSize()
+	{
+		return totalSize;
+	}
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/f6485517/wicket-core/src/main/java/org/apache/wicket/pageStore/memory/HttpSessionDataStore.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/pageStore/memory/HttpSessionDataStore.java b/wicket-core/src/main/java/org/apache/wicket/pageStore/memory/HttpSessionDataStore.java
deleted file mode 100644
index fcc4f7a..0000000
--- a/wicket-core/src/main/java/org/apache/wicket/pageStore/memory/HttpSessionDataStore.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.pageStore.memory;
-
-import javax.servlet.http.HttpSession;
-
-import org.apache.wicket.Session;
-import org.apache.wicket.page.IPageManagerContext;
-import org.apache.wicket.pageStore.IDataStore;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * A {@link IDataStore} which stores the pages in the {@link HttpSession}. Uses
- * {@link IDataStoreEvictionStrategy} to keep the memory footprint reasonable.
- *
- * <p>
- * Usage:
- *
- * <pre>
- * <!--@formatter:off-->
- * MyApp#init()
- * {
- *
- * 	setPageManagerProvider(new DefaultPageManagerProvider(this)
- * 	{
- * 		protected IDataStore newDataStore() 
- * 		{ 
- * 			return  new HttpSessionDataStore(pageManagerContext, new PageNumberEvictionStrategy(20));
- * 		}
- * 	}
- * }
- * <!--@formatter:on-->
- * </pre>
- */
-public class HttpSessionDataStore implements IDataStore
-{
-	private static final Logger LOG = LoggerFactory.getLogger(HttpSessionDataStore.class);
-
-	/** the session attribute key. auto-prefixed with application.getSessionAttributePrefix() */
-	private static final String PAGE_TABLE_KEY = "page:store:memory";
-
-	private final IPageManagerContext pageManagerContext;
-
-	private final IDataStoreEvictionStrategy evictionStrategy;
-
-	/**
-	 * Construct.
-	 * 
-	 * @param pageManagerContext
-	 * @param evictionStrategy
-	 */
-	public HttpSessionDataStore(IPageManagerContext pageManagerContext,
-		IDataStoreEvictionStrategy evictionStrategy)
-	{
-		this.pageManagerContext = pageManagerContext;
-		this.evictionStrategy = evictionStrategy;
-	}
-
-	/**
-	 * @param sessionId
-	 *            Ignored. Only pages from the current http session can be read
-	 * @see org.apache.wicket.pageStore.IDataStore#getData(java.lang.String, int)
-	 */
-	@Override
-	public byte[] getData(String sessionId, int pageId)
-	{
-		PageTable pageTable = getPageTable(false, false);
-		byte[] pageAsBytes = null;
-		if (pageTable != null)
-		{
-			pageAsBytes = pageTable.getPage(pageId);
-		}
-
-		if (LOG.isDebugEnabled())
-		{
-			int bytesLength = pageAsBytes != null ? pageAsBytes.length : -1;
-			LOG.debug("Loaded '{}' bytes for page with id '{}' in session '{}'",
-					bytesLength, pageId, sessionId);
-		}
-
-
-		return pageAsBytes;
-	}
-
-	@Override
-	public void removeData(String sessionId, int pageId)
-	{
-		PageTable pageTable = getPageTable(false, true);
-		if (pageTable != null)
-		{
-			byte[] bytes = pageTable.removePage(pageId);
-
-			if (LOG.isDebugEnabled() && bytes != null)
-			{
-				LOG.debug("Removed page '{}' in session '{}'", pageId, sessionId);
-			}
-		}
-	}
-
-	@Override
-	public void removeData(String sessionId)
-	{
-		PageTable pageTable = getPageTable(false, true);
-		if (pageTable != null)
-		{
-			pageTable.clear();
-			LOG.debug("Removed all pages in session '{}'", sessionId);
-		}
-	}
-
-	@Override
-	public void storeData(String sessionId, int pageId, byte[] pageAsBytes)
-	{
-		PageTable pageTable = getPageTable(true, true);
-		if (pageTable != null)
-		{
-			pageTable.storePage(pageId, pageAsBytes);
-			if (LOG.isDebugEnabled())
-			{
-				LOG.debug("Stored '{}' bytes for page '{}' in session '{}'",
-						pageAsBytes.length, pageId, sessionId);
-			}
-			evictionStrategy.evict(pageTable);
-		}
-		else
-		{
-			LOG.error("Cannot store the data for page with id '{}' in session with id '{}'",
-				pageId, sessionId);
-		}
-	}
-
-	@Override
-	public void destroy()
-	{
-		// do nothing
-		// this is application lifecycle thread (WicketFilter#destroy())
-		// so there is no reachable http session
-	}
-
-	@Override
-	public boolean isReplicated()
-	{
-		return true;
-	}
-
-	private PageTable getPageTable(boolean create, boolean rewriteToSession)
-	{
-		PageTable pageTable = null;
-		if (Session.exists())
-		{
-			pageTable = (PageTable)pageManagerContext.getSessionAttribute(PAGE_TABLE_KEY);
-			if (pageTable == null && create)
-			{
-				pageTable = new PageTable();
-				pageManagerContext.setSessionAttribute(PAGE_TABLE_KEY, pageTable);
-			} else if (rewriteToSession) {
-				pageManagerContext.setSessionAttribute(PAGE_TABLE_KEY, pageTable);
-			}
-		}
-		return pageTable;
-	}
-
-	@Override
-	public final boolean canBeAsynchronous()
-	{
-		// HttpSessionDataStore needs access to the current http session
-		// and this is not possible in AsychronousDataStore
-		return false;
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/wicket/blob/f6485517/wicket-core/src/main/java/org/apache/wicket/pageStore/memory/IDataStoreEvictionStrategy.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/pageStore/memory/IDataStoreEvictionStrategy.java b/wicket-core/src/main/java/org/apache/wicket/pageStore/memory/IDataStoreEvictionStrategy.java
deleted file mode 100644
index 6b6e556..0000000
--- a/wicket-core/src/main/java/org/apache/wicket/pageStore/memory/IDataStoreEvictionStrategy.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.pageStore.memory;
-
-
-/**
- * An eviction strategy that decides whether the in-memory data structure used as page store should
- * be compacted
- */
-@FunctionalInterface
-public interface IDataStoreEvictionStrategy
-{
-
-	/**
-	 * Called after each {@link org.apache.wicket.pageStore.IDataStore#storeData(String, int, byte[])} call.
-	 * 
-	 * @param pageTable
-	 *            the in-memory data store with <strong>all</strong> pages
-	 */
-	void evict(PageTable pageTable);
-}

http://git-wip-us.apache.org/repos/asf/wicket/blob/f6485517/wicket-core/src/main/java/org/apache/wicket/pageStore/memory/MemorySizeEvictionStrategy.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/pageStore/memory/MemorySizeEvictionStrategy.java b/wicket-core/src/main/java/org/apache/wicket/pageStore/memory/MemorySizeEvictionStrategy.java
deleted file mode 100644
index 92f985b..0000000
--- a/wicket-core/src/main/java/org/apache/wicket/pageStore/memory/MemorySizeEvictionStrategy.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.pageStore.memory;
-
-import org.apache.wicket.util.lang.Args;
-import org.apache.wicket.util.lang.Bytes;
-import org.apache.wicket.core.util.lang.WicketObjects;
-
-/**
- * An eviction strategy that keeps the data store size up to configured bytes
- */
-public class MemorySizeEvictionStrategy implements IDataStoreEvictionStrategy
-{
-
-	private final Bytes maxBytes;
-
-	/**
-	 * Construct.
-	 * 
-	 * @param maxBytes
-	 *            the maximum size of the data store
-	 */
-	public MemorySizeEvictionStrategy(Bytes maxBytes)
-	{
-		Args.notNull(maxBytes, "maxBytes");
-
-		this.maxBytes = maxBytes;
-	}
-
-	/**
-	 * 
-	 * @see IDataStoreEvictionStrategy#evict(org.apache.wicket.pageStore.memory.PageTable)
-	 */
-	@Override
-	public void evict(PageTable pageTable)
-	{
-
-		long storeCurrentSize = WicketObjects.sizeof(pageTable);
-
-		if (storeCurrentSize > maxBytes.bytes())
-		{
-			PageTableCleaner cleaner = new PageTableCleaner();
-			cleaner.drop(pageTable, 1);
-
-			// recurse until enough space is cleaned
-			evict(pageTable);
-		}
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/wicket/blob/f6485517/wicket-core/src/main/java/org/apache/wicket/pageStore/memory/PageNumberEvictionStrategy.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/pageStore/memory/PageNumberEvictionStrategy.java b/wicket-core/src/main/java/org/apache/wicket/pageStore/memory/PageNumberEvictionStrategy.java
deleted file mode 100644
index 9857a6b..0000000
--- a/wicket-core/src/main/java/org/apache/wicket/pageStore/memory/PageNumberEvictionStrategy.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.pageStore.memory;
-
-
-/**
- * An eviction strategy which decides whether to evict entries from the in-memory data store
- * depending on the number of stored paged per session
- */
-public class PageNumberEvictionStrategy implements IDataStoreEvictionStrategy
-{
-
-	private final int pagesNumber;
-
-	/**
-	 * Construct.
-	 * 
-	 * @param pagesNumber
-	 *            the maximum number of pages the data store can hold
-	 */
-	public PageNumberEvictionStrategy(int pagesNumber)
-	{
-		if (pagesNumber < 1)
-		{
-			throw new IllegalArgumentException("'pagesNumber' must be greater than 0.");
-		}
-
-		this.pagesNumber = pagesNumber;
-	}
-
-	/**
-	 * 
-	 * @see IDataStoreEvictionStrategy#evict(org.apache.wicket.pageStore.memory.PageTable)
-	 */
-	@Override
-	public void evict(PageTable pageTable)
-	{
-		int size = pageTable.size();
-		int pagesToDrop = size - pagesNumber;
-
-		if (pagesToDrop > 0)
-		{
-			PageTableCleaner cleaner = new PageTableCleaner();
-			cleaner.drop(pageTable, pagesToDrop);
-		}
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/wicket/blob/f6485517/wicket-core/src/main/java/org/apache/wicket/pageStore/memory/PageTable.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/pageStore/memory/PageTable.java b/wicket-core/src/main/java/org/apache/wicket/pageStore/memory/PageTable.java
deleted file mode 100644
index dfad4af..0000000
--- a/wicket-core/src/main/java/org/apache/wicket/pageStore/memory/PageTable.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.pageStore.memory;
-
-import java.util.Iterator;
-import java.util.Queue;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.ConcurrentMap;
-
-import org.apache.wicket.util.io.IClusterable;
-
-/**
- * A structure that holds page id => pageAsBytes.
- * 
- * <p>
- * Additionally it has an index of the least recently used pages
- */
-public class PageTable implements IClusterable
-{
-	private static final long serialVersionUID = 1L;
-
-	/**
-	 * Holds the index of last/least recently used page ids. The most recently used page id is in
-	 * the tail, the least recently used is in the head.
-	 */
-	/*
-	 * Can be replaced later with PriorityQueue to deal with lightweight (Ajax) and heavyweight
-	 * pages
-	 */
-	private final Queue<Integer> index;
-
-	/**
-	 * The actual container for the pages.
-	 * 
-	 * <p>
-	 * page id => page as bytes
-	 */
-	private final ConcurrentMap<Integer, byte[]> pages;
-
-	public PageTable()
-	{
-		pages = new ConcurrentHashMap<>();
-		index = new ConcurrentLinkedQueue<>();
-	}
-
-	public void storePage(Integer pageId, byte[] pageAsBytes)
-	{
-		synchronized (index)
-		{
-			pages.put(pageId, pageAsBytes);
-
-			updateIndex(pageId);
-		}
-	}
-
-	public byte[] getPage(final Integer pageId)
-	{
-		synchronized (index)
-		{
-			updateIndex(pageId);
-
-			return pages.get(pageId);
-		}
-	}
-
-	public byte[] removePage(Integer pageId)
-	{
-		synchronized (index)
-		{
-			index.remove(pageId);
-
-			return pages.remove(pageId);
-		}
-	}
-
-	public void clear()
-	{
-		synchronized (index)
-		{
-			index.clear();
-			pages.clear();
-		}
-	}
-
-	public int size()
-	{
-		return pages.size();
-	}
-
-	public Integer getOldest()
-	{
-		return index.peek();
-	}
-
-	public Iterator<Integer> indexIterator()
-	{
-		return index.iterator();
-	}
-
-	/**
-	 * Updates the index of last/least recently used pages by removing the page id from the index
-	 * (in case it is already in) and (re-)adding it at the head
-	 * 
-	 * @param pageId
-	 *            the id of a recently used page
-	 */
-	private void updateIndex(Integer pageId)
-	{
-		index.remove(pageId);
-		index.offer(pageId);
-	}
-
-}

http://git-wip-us.apache.org/repos/asf/wicket/blob/f6485517/wicket-core/src/main/java/org/apache/wicket/pageStore/memory/PageTableCleaner.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/pageStore/memory/PageTableCleaner.java b/wicket-core/src/main/java/org/apache/wicket/pageStore/memory/PageTableCleaner.java
deleted file mode 100644
index 2c9a9cb..0000000
--- a/wicket-core/src/main/java/org/apache/wicket/pageStore/memory/PageTableCleaner.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.pageStore.memory;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Helper class that knows how to remove the nth oldest pages from {@link PageTable}
- */
-public class PageTableCleaner
-{
-	private static final Logger LOG = LoggerFactory.getLogger(PageTableCleaner.class);
-
-	/**
-	 * Removes {@code pagesNumber} of pages from the {@link PageTable pageTable}
-	 * 
-	 * @param pageTable
-	 *            the {@link PageTable} to clean
-	 * @param pagesNumber
-	 *            the number of pages to remove
-	 */
-	public void drop(final PageTable pageTable, final int pagesNumber)
-	{
-		for (int i = 0; i < pagesNumber; i++)
-		{
-			Integer pageIdOfTheOldest = pageTable.getOldest();
-			pageTable.removePage(pageIdOfTheOldest);
-			LOG.debug("Evicted page with id '{}' from the HttpSessionDataStore");
-		}
-	}
-}

http://git-wip-us.apache.org/repos/asf/wicket/blob/f6485517/wicket-core/src/main/java/org/apache/wicket/settings/StoreSettings.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/settings/StoreSettings.java b/wicket-core/src/main/java/org/apache/wicket/settings/StoreSettings.java
index 8852208..7c32101 100644
--- a/wicket-core/src/main/java/org/apache/wicket/settings/StoreSettings.java
+++ b/wicket-core/src/main/java/org/apache/wicket/settings/StoreSettings.java
@@ -26,9 +26,8 @@ import org.apache.wicket.util.lang.Args;
 import org.apache.wicket.util.lang.Bytes;
 
 /**
- * A class for settings related to the the storages where page instances are persisted -
- * {@link org.apache.wicket.pageStore.IPageStore},
- * {@link org.apache.wicket.pageStore.IDataStore} and {@link org.apache.wicket.page.IPageManager}.
+ * A class for settings related to the the storages where page instances are persisted, used by
+ * {@link org.apache.wicket.pageStore.IPageStore} {@link org.apache.wicket.page.IPageManager}.
  * <p>
  * For more information about page storages read <a
  * href="https://cwiki.apache.org/confluence/x/qIaoAQ">Page Storage - Wiki page</a>
@@ -38,28 +37,18 @@ import org.apache.wicket.util.lang.Bytes;
  */
 public class StoreSettings
 {
-	/**
-	 * By default the second level cache is disabled.
-	 *
-	 * @see <a href="https://issues.apache.org/jira/browse/WICKET-5554">WICKET-5554</a>
-	 * @see <a href="https://cwiki.apache.org/confluence/x/qIaoAQ">Wicket Page storages</a>
-	 */
-	private static final int DEFAULT_CACHE_SIZE = 0;
-
 	private static final Bytes DEFAULT_MAX_SIZE_PER_SESSION = Bytes.megabytes(10);
 
 	private static final int DEFAULT_ASYNCHRONOUS_QUEUE_CAPACITY = 100;
 
-	private int inmemoryCacheSize = DEFAULT_CACHE_SIZE;
-
 	private Bytes maxSizePerSession = DEFAULT_MAX_SIZE_PER_SESSION;
 
 	private File fileStoreFolder = null;
 
 	private int asynchronousQueueCapacity = DEFAULT_ASYNCHRONOUS_QUEUE_CAPACITY;
 
-	private boolean isAsynchronous = true;
-
+	private boolean asynchronous = true;
+	
 	/**
 	 * Construct.
 	 * 
@@ -70,32 +59,8 @@ public class StoreSettings
 	}
 
 	/**
-	 * @return the number of page instances which will be stored in the application scoped cache for
-	 *         faster retrieval
-	 */
-	public int getInmemoryCacheSize()
-	{
-		return inmemoryCacheSize;
-	}
-
-	/**
-	 * Sets the maximum number of page instances which will be stored in the application scoped
-	 * second level cache for faster retrieval
-	 *
-	 * @param inmemoryCacheSize
-	 *            the maximum number of page instances which will be held in the application scoped
-	 *            cache
-	 * @return {@code this} object for chaining
-	 */
-	public StoreSettings setInmemoryCacheSize(int inmemoryCacheSize)
-	{
-		this.inmemoryCacheSize = inmemoryCacheSize;
-		return this;
-	}
-
-	/**
 	 * @return maximum page size. After this size is exceeded,
-	 * the {@link org.apache.wicket.pageStore.DiskDataStore} will start saving the
+	 * the {@link org.apache.wicket.pageStore.DiskPageStore} will start saving the
 	 * pages at the beginning of file.
 	 */
 	public Bytes getMaxSizePerSession()
@@ -105,7 +70,7 @@ public class StoreSettings
 
 	/**
 	 * Sets the maximum size of the {@link File} where page instances per session are stored. After
-	 * reaching this size the {@link org.apache.wicket.pageStore.DiskDataStore} will start overriding the
+	 * reaching this size the {@link org.apache.wicket.pageStore.DiskPageStore} will start overriding the
 	 * oldest pages at the beginning of the file.
 	 *
 	 * @param maxSizePerSession
@@ -120,7 +85,7 @@ public class StoreSettings
 	}
 
 	/**
-	 * @return the location of the folder where {@link org.apache.wicket.pageStore.DiskDataStore} will store the files with page
+	 * @return the location of the folder where {@link org.apache.wicket.pageStore.DiskPageStore} will store the files with page
 	 *         instances per session
 	 */
 	public File getFileStoreFolder()
@@ -151,7 +116,7 @@ public class StoreSettings
 	}
 
 	/**
-	 * Sets the folder where {@link org.apache.wicket.pageStore.DiskDataStore} will store the files with page instances per
+	 * Sets the folder where {@link org.apache.wicket.pageStore.DiskPageStore} will store the files with page instances per
 	 * session
 	 *
 	 * @param fileStoreFolder
@@ -166,7 +131,7 @@ public class StoreSettings
 
 	/**
 	 * @return the capacity of the queue used to store the pages which will be stored asynchronously
-	 * @see org.apache.wicket.pageStore.AsynchronousDataStore
+	 * @see org.apache.wicket.pageStore.AsynchronousPageStore
 	 */
 	public int getAsynchronousQueueCapacity()
 	{
@@ -178,7 +143,7 @@ public class StoreSettings
 	 *
 	 * @param queueCapacity
 	 *            the capacity of the queue
-	 * @see org.apache.wicket.pageStore.AsynchronousDataStore
+	 * @see org.apache.wicket.pageStore.AsynchronousPageStore
 	 * @return {@code this} object for chaining
 	 */
 	public StoreSettings setAsynchronousQueueCapacity(int queueCapacity)
@@ -193,9 +158,9 @@ public class StoreSettings
 	}
 
 	/**
-	 * Sets a flag whether to wrap the configured {@link org.apache.wicket.pageStore.IDataStore} with
-	 * {@link org.apache.wicket.pageStore.AsynchronousDataStore}. By doing this the HTTP worker thread will not wait for the
-	 * actual write of the page's bytes into the wrapped {@link org.apache.wicket.pageStore.IDataStore}.
+	 * Sets a flag whether to wrap the configured {@link org.apache.wicket.pageStore.IPageStore} with
+	 * {@link org.apache.wicket.pageStore.AsynchronousPageStore}. By doing this the HTTP worker thread will not wait for the
+	 * actual write of the page's bytes into the wrapped {@link org.apache.wicket.pageStore.IPageStore}.
 	 *
 	 * @param async
 	 *            {@code true} to make it asynchronous, {@code false} - otherwise
@@ -203,15 +168,15 @@ public class StoreSettings
 	 */
 	public StoreSettings setAsynchronous(boolean async)
 	{
-		isAsynchronous = async;
+		asynchronous = async;
 		return this;
 	}
 
 	/**
-	 * @return {@code true} if the storing of page's bytes is asynchronous
+	 * @return {@code true} if the storing of page is asynchronous
 	 */
 	public boolean isAsynchronous()
 	{
-		return isAsynchronous;
+		return asynchronous;
 	}
-}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/wicket/blob/f6485517/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java b/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
index ce09dd9..f7a3c44 100644
--- a/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
+++ b/wicket-core/src/main/java/org/apache/wicket/util/tester/BaseWicketTester.java
@@ -92,11 +92,11 @@ import org.apache.wicket.markup.html.list.ListView;
 import org.apache.wicket.markup.parser.XmlPullParser;
 import org.apache.wicket.markup.parser.XmlTag;
 import org.apache.wicket.mock.MockApplication;
-import org.apache.wicket.mock.MockPageManager;
+import org.apache.wicket.mock.MockPageStore;
 import org.apache.wicket.mock.MockRequestParameters;
 import org.apache.wicket.model.PropertyModel;
 import org.apache.wicket.page.IPageManager;
-import org.apache.wicket.page.IPageManagerContext;
+import org.apache.wicket.page.PageManager;
 import org.apache.wicket.protocol.http.AjaxEnclosureListener;
 import org.apache.wicket.protocol.http.IMetaDataBufferingWebResponse;
 import org.apache.wicket.protocol.http.WebApplication;
@@ -2817,9 +2817,9 @@ public class BaseWicketTester
 	private static class TestPageManagerProvider implements IPageManagerProvider
 	{
 		@Override
-		public IPageManager apply(IPageManagerContext pageManagerContext)
+		public IPageManager get()
 		{
-			return new MockPageManager();
+			return new PageManager(new MockPageStore());
 		}
 	}
 

http://git-wip-us.apache.org/repos/asf/wicket/blob/f6485517/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/TestMapperContext.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/TestMapperContext.java b/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/TestMapperContext.java
index 2fff6cc..9f1c44d 100644
--- a/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/TestMapperContext.java
+++ b/wicket-core/src/test/java/org/apache/wicket/core/request/mapper/TestMapperContext.java
@@ -20,19 +20,20 @@ import org.apache.wicket.MockPage;
 import org.apache.wicket.WicketRuntimeException;
 import org.apache.wicket.core.request.handler.PageProvider;
 import org.apache.wicket.markup.MarkupParser;
-import org.apache.wicket.page.IPageManagerContext;
-import org.apache.wicket.page.PageStoreManager;
-import org.apache.wicket.pageStore.DefaultPageStore;
-import org.apache.wicket.pageStore.IDataStore;
-import org.apache.wicket.pageStore.IPageStore;
-import org.apache.wicket.pageStore.memory.DummyPageManagerContext;
+import org.apache.wicket.mock.MockPageStore;
+import org.apache.wicket.page.IPageManager;
+import org.apache.wicket.page.PageManager;
+import org.apache.wicket.pageStore.DummyPageContext;
+import org.apache.wicket.pageStore.IPageContext;
+import org.apache.wicket.pageStore.InMemoryPageStore;
+import org.apache.wicket.pageStore.RequestPageStore;
+import org.apache.wicket.pageStore.InSessionPageStore;
 import org.apache.wicket.request.component.IRequestablePage;
 import org.apache.wicket.request.mapper.parameter.PageParameters;
 import org.apache.wicket.request.resource.ResourceReference;
 import org.apache.wicket.request.resource.ResourceReference.Key;
 import org.apache.wicket.request.resource.ResourceReferenceRegistry;
 import org.apache.wicket.serialize.java.JavaSerializer;
-import org.apache.wicket.versioning.InMemoryPageStore;
 
 /**
  * Simple {@link IMapperContext} implementation for testing purposes
@@ -43,10 +44,10 @@ public class TestMapperContext implements IMapperContext
 {
 	private static final String APP_NAME = "test_app";
 	private static int count;
-	private IDataStore dataStore;
-	private IPageStore pageStore;
-	private IPageManagerContext pageManagerContext;
-	private PageStoreManager pageManager;
+
+	InSessionPageStore pageStore;
+	DummyPageContext pageContext;
+	IPageManager pageManager;
 	private String appName;
 	private boolean createMockPageIfInstanceNotFound = true;
 
@@ -56,10 +57,18 @@ public class TestMapperContext implements IMapperContext
 	public TestMapperContext()
 	{
 		appName = APP_NAME + count++;
-		dataStore = new InMemoryPageStore();
-		pageStore = new DefaultPageStore(new JavaSerializer(appName), dataStore, 4);
-		pageManagerContext = new DummyPageManagerContext();
-		pageManager = new PageStoreManager(appName, pageStore, pageManagerContext);
+		
+		pageContext = new DummyPageContext();
+		
+		InMemoryPageStore inMemoryPageStore = new InMemoryPageStore(appName, Integer.MAX_VALUE);
+		pageStore = new InSessionPageStore(inMemoryPageStore, 4, new JavaSerializer(appName));
+		pageManager = new PageManager(new RequestPageStore(pageStore)) {
+			@Override
+			protected IPageContext createPageContext()
+			{
+				return pageContext;
+			}
+		};
 	}
 
 	/**
@@ -67,17 +76,17 @@ public class TestMapperContext implements IMapperContext
 	 */
 	public void cleanSessionCache()
 	{
-		getPageManager().getContext().setRequestData(null);
+		pageContext.clearRequest();
 		MockPage other = new MockPage();
 		other.setPageId(Integer.MAX_VALUE);
-		getPageManager().touchPage(other);
-		getPageManager().commitRequest();
+		getPageManager().addPage(other);
+		pageManager.detach();
 	}
 
 	/**
 	 * @return pageManager
 	 */
-	public PageStoreManager getPageManager()
+	public IPageManager getPageManager()
 	{
 		return pageManager;
 	}
@@ -175,7 +184,7 @@ public class TestMapperContext implements IMapperContext
 
 	}
 
-	private int idCounter = 0;
+	int idCounter = 0;
 
 	@Override
 	public IRequestablePage newPageInstance(Class<? extends IRequestablePage> pageClass,
@@ -184,7 +193,7 @@ public class TestMapperContext implements IMapperContext
 		try
 		{
 			MockPage page;
-			page = (MockPage)pageClass.getDeclaredConstructor().newInstance();
+			page = (MockPage)pageClass.newInstance();
 			page.setPageId(++idCounter);
 			page.setBookmarkable(true);
 			page.setCreatedBookmarkable(true);

http://git-wip-us.apache.org/repos/asf/wicket/blob/f6485517/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/DontStoreNotRenderedPageTestCase.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/DontStoreNotRenderedPageTestCase.java b/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/DontStoreNotRenderedPageTestCase.java
index ceac5e3..857c715 100644
--- a/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/DontStoreNotRenderedPageTestCase.java
+++ b/wicket-core/src/test/java/org/apache/wicket/dontstoreunrendered/DontStoreNotRenderedPageTestCase.java
@@ -24,8 +24,6 @@ import org.apache.wicket.application.IComponentInstantiationListener;
 import org.apache.wicket.behavior.Behavior;
 import org.apache.wicket.mock.MockPageManager;
 import org.apache.wicket.page.IManageablePage;
-import org.apache.wicket.page.IPageManager;
-import org.apache.wicket.page.IPageManagerContext;
 import org.apache.wicket.protocol.http.WebApplication;
 import org.apache.wicket.util.tester.WicketTestCase;
 import org.apache.wicket.util.tester.WicketTester;
@@ -34,7 +32,7 @@ import org.junit.jupiter.api.Test;
 /**
  * https://issues.apache.org/jira/browse/WICKET-5415
  */
-abstract class DontStoreNotRenderedPageTestCase extends WicketTestCase
+public abstract class DontStoreNotRenderedPageTestCase extends WicketTestCase
 {
 	@Override
 	protected WicketTester newWicketTester(WebApplication app)
@@ -56,30 +54,27 @@ abstract class DontStoreNotRenderedPageTestCase extends WicketTestCase
 			@Override
 			protected IPageManagerProvider newTestPageManagerProvider()
 			{
-				return new IPageManagerProvider()
-				{
-					@Override
-					public IPageManager apply(IPageManagerContext context)
+				return () -> {
+					return new MockPageManager()
 					{
-						return new MockPageManager()
+						@Override
+						public void addPage(IManageablePage page)
 						{
-							@Override
-							public void touchPage(IManageablePage page)
-							{
-								assertFalse(page instanceof PageB, "PageB should not be touched!");
-								super.touchPage(page);
-							}
-						};
-					}
+							assertFalse(page instanceof PageB, "PageB should not be touched!");
+							super.addPage(page);
+						}
+					};
 				};
 			}
 		};
 	}
 
 	/**
-	 * Start with PageA. Then click a link to go to PageB. PageB throws a
-	 * RestartResponseException(PageC) in its constructor, so it shouldn't be neither initialized
-	 * nor rendered. PageC is rendered.
+	 * Start with PageA.
+	 * Then click a link to go to PageB.
+	 * PageB throws a RestartResponseException(PageC) in its constructor, so
+	 * it shouldn't be neither initialized nor rendered.
+	 * PageC is rendered.
 	 *
 	 * Verifies that PageB is not initialized, rendered and stored by PageManager
 	 */

http://git-wip-us.apache.org/repos/asf/wicket/blob/f6485517/wicket-core/src/test/java/org/apache/wicket/markup/html/TransparentWebMarkupContainerTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/html/TransparentWebMarkupContainerTest.java b/wicket-core/src/test/java/org/apache/wicket/markup/html/TransparentWebMarkupContainerTest.java
index da853e4..39d81c3 100644
--- a/wicket-core/src/test/java/org/apache/wicket/markup/html/TransparentWebMarkupContainerTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/html/TransparentWebMarkupContainerTest.java
@@ -38,7 +38,7 @@ import org.apache.wicket.markup.html.panel.Fragment;
 import org.apache.wicket.mock.MockPageManager;
 import org.apache.wicket.page.IManageablePage;
 import org.apache.wicket.page.IPageManager;
-import org.apache.wicket.page.IPageManagerContext;
+import org.apache.wicket.pageStore.IPageContext;
 import org.apache.wicket.request.mapper.parameter.PageParameters;
 import org.apache.wicket.util.resource.IResourceStream;
 import org.apache.wicket.util.resource.StringResourceStream;
@@ -120,15 +120,15 @@ public class TransparentWebMarkupContainerTest extends WicketTestCase
 				return new IPageManagerProvider()
 				{
 					@Override
-					public IPageManager apply(IPageManagerContext context)
+					public IPageManager get()
 					{
 						return new MockPageManager()
 						{
 							@Override
-							public void touchPage(IManageablePage page)
+							public void addPage(IManageablePage page)
 							{
 								page = WicketObjects.cloneObject(page);
-								super.touchPage(page);
+								super.addPage(page);
 							}
 						};
 					}

http://git-wip-us.apache.org/repos/asf/wicket/blob/f6485517/wicket-core/src/test/java/org/apache/wicket/page/PageAccessSynchronizerTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/page/PageAccessSynchronizerTest.java b/wicket-core/src/test/java/org/apache/wicket/page/PageAccessSynchronizerTest.java
index c686d6a..ad697ed 100644
--- a/wicket-core/src/test/java/org/apache/wicket/page/PageAccessSynchronizerTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/page/PageAccessSynchronizerTest.java
@@ -323,7 +323,7 @@ class PageAccessSynchronizerTest
 
 		int pageId = 1;
 		IManageablePage page = new MockPage(pageId);
-		synchronizedPageManager.touchPage(page);
+		synchronizedPageManager.addPage(page);
 		synchronizedPageManager.getPage(pageId);
 		PageLock pageLock2 = locks.get(Integer.valueOf(pageId));
 		assertNotNull(pageLock2);

http://git-wip-us.apache.org/repos/asf/wicket/blob/f6485517/wicket-core/src/test/java/org/apache/wicket/page/PersistentPageManagerTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/page/PersistentPageManagerTest.java b/wicket-core/src/test/java/org/apache/wicket/page/PersistentPageManagerTest.java
index 04c4f19..046a1ec 100644
--- a/wicket-core/src/test/java/org/apache/wicket/page/PersistentPageManagerTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/page/PersistentPageManagerTest.java
@@ -20,19 +20,19 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 
-import java.io.ByteArrayInputStream;
 import java.io.IOException;
-import java.io.ObjectInputStream;
 import java.io.Serializable;
+import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.wicket.Application;
+import org.apache.wicket.MetaDataKey;
 import org.apache.wicket.ThreadContext;
-import org.apache.wicket.pageStore.DefaultPageStore;
-import org.apache.wicket.pageStore.IDataStore;
+import org.apache.wicket.pageStore.DummyPageContext;
+import org.apache.wicket.pageStore.IPageContext;
 import org.apache.wicket.pageStore.IPageStore;
-import org.apache.wicket.pageStore.memory.DummyPageManagerContext;
+import org.apache.wicket.pageStore.InSessionPageStore;
+import org.apache.wicket.pageStore.NoopPageStore;
 import org.apache.wicket.serialize.java.JavaSerializer;
-import org.apache.wicket.versioning.InMemoryPageStore;
 import org.junit.jupiter.api.Test;
 
 /**
@@ -58,42 +58,39 @@ class PersistentPageManagerTest
 		ThreadContext.detach();
 
 		// create IPageManager (with IPageStore) and store a page instance
-		IPageManager pageManager = newPersistentPageManager(APP_NAME);
+		final AtomicReference<Object> sessionData = new AtomicReference<Object>(null);
+		
+		IPageManager pageManager = createPageManager(APP_NAME, sessionData);
+
+		// add a page
 		TestPage toSerializePage = new TestPage();
-		pageManager.touchPage(toSerializePage);
-		pageManager.commitRequest();
+		pageManager.addPage(toSerializePage);
+		pageManager.detach();
 
 		// get the stored SessionEntry
-		Serializable sessionEntry = pageManager.getContext().getSessionAttribute(null);
+		assertNotNull(sessionData.get());
 
 		// destroy the manager and the store
 		pageManager.destroy();
 
 		// simulate persisting of the http sessions initiated by the web container
-		byte[] serializedSessionEntry = new JavaSerializer(APP_NAME).serialize(sessionEntry);
-		assertNotNull(serializedSessionEntry,
-			"Wicket needs to be able to serialize the session entry");
-
-		// simulate loading of the persisted http session initiated by the web container
-		// when starting an application
-		ObjectInputStream in = new ObjectInputStream(
-			new ByteArrayInputStream(serializedSessionEntry));
+		byte[] serializedSessionData = new JavaSerializer(APP_NAME).serialize(sessionData.get());
+		assertNotNull(serializedSessionData, "Wicket needs to be able to serialize the session entry");
 
 		// WicketFilter is not initialized so there is no Application available yet
 		assertFalse(Application.exists(), "Worker thread should be unaware of Wicket application");
 
-		assertEquals(APP_NAME, in.readObject());
+		// simulate loading of the persisted http session initiated by the web container
+		// when starting an application
+		sessionData.set(new JavaSerializer(APP_NAME).deserialize(serializedSessionData));
 
 		// without available IPageStore the read SessionEntry holds
 		// the IManageablePage itself, not SerializedPage
-		Serializable loadedSessionEntry = (Serializable)in.readObject();
-		assertNotNull(loadedSessionEntry,
-			"Wicket needs to be able to deserialize the session entry regardless the application availability");
+		assertNotNull(sessionData.get(), "Wicket needs to be able to deserialize the session entry regardless the application availability");
 
 		// provide new IPageStore which will read IManageablePage's or SerializedPage's
 		// from the SessionEntry's
-		IPageManager newPageManager = newPersistentPageManager(APP_NAME);
-		newPageManager.getContext().setSessionAttribute(null, loadedSessionEntry);
+		IPageManager newPageManager = createPageManager(APP_NAME, sessionData);
 
 		TestPage deserializedPage = (TestPage)newPageManager.getPage(toSerializePage.getPageId());
 		assertNotNull(deserializedPage);
@@ -102,12 +99,36 @@ class PersistentPageManagerTest
 		newPageManager.destroy();
 	}
 
-	private PageStoreManager newPersistentPageManager(String appName)
+	/**
+	 * Create a manager that stores session data in the given atomic reference.
+	 */
+	private IPageManager createPageManager(String appName, AtomicReference<Object> sessionData)
 	{
-		IDataStore dataStore = new InMemoryPageStore();
-		IPageStore pageStore = new DefaultPageStore(new JavaSerializer(appName), dataStore, 4);
-		IPageManagerContext pageManagerContext = new DummyPageManagerContext();
-		return new PageStoreManager(appName, pageStore, pageManagerContext);
+		IPageStore store = new InSessionPageStore(new NoopPageStore(), Integer.MAX_VALUE, new JavaSerializer(APP_NAME));
+		
+		return new PageManager(store) {
+			@Override
+			protected IPageContext createPageContext()
+			{
+				return new DummyPageContext() {
+					@Override
+					public <T extends Serializable> T setSessionData(MetaDataKey<T> key, T value)
+					{
+						super.setSessionData(key, value);
+						
+						sessionData.set(value);
+						
+						return value;
+					}
+					
+					@Override
+					public <T extends Serializable> T getSessionData(MetaDataKey<T> key)
+					{
+						return (T)sessionData.get();
+					}
+				};
+			}
+		};
 	}
 
 	private static class TestPage implements IManageablePage

http://git-wip-us.apache.org/repos/asf/wicket/blob/f6485517/wicket-core/src/test/java/org/apache/wicket/page/persistent/disk/PageWindowManagerTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/page/persistent/disk/PageWindowManagerTest.java b/wicket-core/src/test/java/org/apache/wicket/page/persistent/disk/PageWindowManagerTest.java
deleted file mode 100644
index c4ae2fa..0000000
--- a/wicket-core/src/test/java/org/apache/wicket/page/persistent/disk/PageWindowManagerTest.java
+++ /dev/null
@@ -1,305 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.wicket.page.persistent.disk;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-import java.security.SecureRandom;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-import org.apache.wicket.pageStore.PageWindowManager;
-import org.apache.wicket.pageStore.PageWindowManager.PageWindow;
-import org.junit.jupiter.api.Test;
-
-/**
- * @author Matej Knopp
- */
-public class PageWindowManagerTest
-{
-	/**
-	 * https://issues.apache.org/jira/browse/WICKET-4572
-	 */
-	@Test
-	void removeObsoleteIndices()
-	{
-		int page0id = 0,
-			page1id = 1,
-			page2id = 2;
-		int maxSize = 10;
-
-		PageWindowManager manager = new PageWindowManager(maxSize);
-
-		// Add few pages.
-		// All of them fully occupy the max space in the pageWindowManager.
-		// So adding N+1st page removes the Nth page.
-		manager.createPageWindow(page0id, maxSize);
-		PageWindow page0Window = manager.getPageWindow(page0id);
-		assertWindow(page0Window, page0id, page0Window.getFilePartOffset(), page0Window.getFilePartSize());
-
-		manager.createPageWindow(page1id, maxSize);
-		PageWindow page1Window = manager.getPageWindow(page1id);
-		assertWindow(page1Window, page1id, page1Window.getFilePartOffset(), page1Window.getFilePartSize());
-
-		// Try to get a page which has been lost with the adding of page1
-		assertNull(manager.getPageWindow(page0id), "Page0 must be lost when Page1 has been added.");
-
-		manager.createPageWindow(page2id, maxSize);
-		PageWindow page2Window = manager.getPageWindow(page2id);
-		assertWindow(page2Window, page2id, page2Window.getFilePartOffset(), page2Window.getFilePartSize());
-
-		// Try to get a page which has been lost with the adding of page2
-		assertNull(manager.getPageWindow(page1id), "Page1 must be lost when Page2 has been added.");
-	}
-
-	/**
-	 * 
-	 */
-	@Test
-	void addRemove()
-	{
-		PageWindowManager manager = new PageWindowManager(300);
-		PageWindow window;
-
-		window = manager.createPageWindow(1, 50);
-		assertWindow(window, 1, 0, 50);
-
-		window = manager.createPageWindow(2, 40);
-		assertWindow(window, 2, 50, 40);
-
-		assertEquals(manager.getTotalSize(), 90);
-
-		window = manager.createPageWindow(2, 30);
-		assertWindow(window, 2, 50, 30);
-		assertEquals(manager.getTotalSize(), 80);
-
-		manager.removePage(2);
-		assertEquals(manager.getTotalSize(), 50);
-
-		window = manager.createPageWindow(3, 30);
-		assertWindow(window, 3, 50, 30);
-		assertEquals(manager.getTotalSize(), 80);
-	}
-
-	/**
-	 * 
-	 */
-	@Test
-	void pageWindowCycle()
-	{
-		PageWindowManager manager = new PageWindowManager(100);
-		PageWindow window;
-
-		window = manager.createPageWindow(1, 30);
-
-		window = manager.createPageWindow(2, 30);
-
-		window = manager.createPageWindow(3, 30);
-
-		assertWindow(window, 3, 60, 30);
-
-		window = manager.createPageWindow(4, 30);
-
-		assertWindow(window, 4, 90, 30);
-
-		// should start at the beginging
-
-		window = manager.createPageWindow(5, 20);
-
-		assertWindow(window, 5, 0, 20);
-
-		assertNull(manager.getPageWindow(1));
-
-		window = manager.getPageWindow(2);
-		assertWindow(window, 2, 30, 30);
-
-		window = manager.createPageWindow(6, 10);
-
-		assertWindow(window, 6, 20, 10);
-
-		window = manager.getPageWindow(2);
-		assertWindow(window, 2, 30, 30);
-
-		window = manager.createPageWindow(6, 30);
-		assertWindow(window, 6, 20, 30);
-
-		assertNull(manager.getPageWindow(2));
-		assertNotNull(manager.getPageWindow(3));
-
-		window = manager.createPageWindow(6, 60);
-		assertWindow(window, 6, 20, 60);
-
-		assertNull(manager.getPageWindow(3));
-
-		window = manager.createPageWindow(7, 20);
-		assertWindow(window, 7, 80, 20);
-
-		assertNotNull(manager.getPageWindow(7));
-
-		// should start at the beginning again
-
-		window = manager.createPageWindow(8, 10);
-		assertWindow(window, 8, 0, 10);
-
-		assertNull(manager.getPageWindow(5));
-		assertNotNull(manager.getPageWindow(6));
-
-		window = manager.createPageWindow(9, 20);
-		assertWindow(window, 9, 10, 20);
-
-		assertNull(manager.getPageWindow(6));
-		assertNotNull(manager.getPageWindow(7));
-
-		window = manager.createPageWindow(10, 20);
-		assertWindow(window, 10, 30, 20);
-
-		assertNull(manager.getPageWindow(6));
-		assertNotNull(manager.getPageWindow(7));
-
-		// make sure when replacing a page that's not last the old "instance" is
-		// not valid anymore
-
-		manager.createPageWindow(8, 10);
-
-		window = manager.getPageWindow(8);
-		assertWindow(window, 8, 50, 10);
-	}
-
-
-	private void assertWindow(PageWindow window, int pageId, int filePartOffset, int filePartSize)
-	{
-		assertTrue(window.getPageId() == pageId && window.getFilePartOffset() == filePartOffset &&
-			window.getFilePartSize() == filePartSize);
-	}
-
-	/** how many operations to execute */
-	private static final int EXECUTIONS = 10000;
-
-	/** used to wait the executions */
-	private static final CountDownLatch LATCH = new CountDownLatch(EXECUTIONS);
-
-	private final PageWindowManager pageWindowManager = new PageWindowManager(1000L);
-
-	/** the execution types */
-	private final Runnable[] TASKS = new Runnable[]
-	{
-		new CreatePageWindowTask(pageWindowManager),
-		new GetPageWindowTask(pageWindowManager),
-		new RemovePageInSessionTask(pageWindowManager)
-	};
-
-	private static final SecureRandom RND = new SecureRandom();
-
-	/**
-	 * Executes random mutator and accessor operations on {@link org.apache.wicket.pageStore.AsynchronousDataStore} validating
-	 * that the used data structures can be used simultaneously.
-	 *
-	 * @throws Exception
-	 */
-	@Test
-	void randomOperations() throws Exception
-	{
-		ExecutorService executorService = Executors.newFixedThreadPool(50);
-
-		for (int i = 0; i < EXECUTIONS; i++)
-		{
-			Runnable task = TASKS[RND.nextInt(TASKS.length)];
-			executorService.submit(task);
-		}
-		LATCH.await();
-		executorService.shutdown();
-	}
-
-	private static abstract class AbstractTask implements Runnable
-	{
-		/** the ids for the stored/removed pages */
-		private static final int[] PAGE_IDS = new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
-
-		final PageWindowManager pageWindowManager;
-
-		private AbstractTask(PageWindowManager pageWindowManager)
-		{
-			this.pageWindowManager = pageWindowManager;
-		}
-
-		protected abstract void r();
-
-		@Override
-		public void run()
-		{
-			try
-			{
-				r();
-			}
-			finally
-			{
-				LATCH.countDown();
-			}
-		}
-
-		int getPageId()
-		{
-			return PAGE_IDS[RND.nextInt(PAGE_IDS.length)];
-		}
-	}
-
-	private static class CreatePageWindowTask extends AbstractTask
-	{
-		private CreatePageWindowTask(PageWindowManager pageWindowManager)
-		{
-			super(pageWindowManager);
-		}
-
-		@Override
-		public void r()
-		{
-			pageWindowManager.createPageWindow(getPageId(), 1000);
-		}
-	}
-
-	private static class GetPageWindowTask extends AbstractTask
-	{
-		private GetPageWindowTask(PageWindowManager pageWindowManager)
-		{
-			super(pageWindowManager);
-		}
-
-		@Override
-		public void r()
-		{
-			pageWindowManager.getPageWindow(getPageId());
-		}
-	}
-
-	private static class RemovePageInSessionTask extends AbstractTask
-	{
-		private RemovePageInSessionTask(PageWindowManager pageWindowManager)
-		{
-			super(pageWindowManager);
-		}
-
-		@Override
-		public void r()
-		{
-			pageWindowManager.removePage(getPageId());
-		}
-	}
-}

http://git-wip-us.apache.org/repos/asf/wicket/blob/f6485517/wicket-core/src/test/java/org/apache/wicket/pageStore/AbstractConcurrentPageStoreTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/pageStore/AbstractConcurrentPageStoreTest.java b/wicket-core/src/test/java/org/apache/wicket/pageStore/AbstractConcurrentPageStoreTest.java
new file mode 100644
index 0000000..3006313
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/pageStore/AbstractConcurrentPageStoreTest.java
@@ -0,0 +1,375 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.pageStore;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Random;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.wicket.page.IManageablePage;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Concurrency tests for stores.
+ */
+public abstract class AbstractConcurrentPageStoreTest
+{
+	/** Log for reporting. */
+	private static final Logger log = LoggerFactory
+		.getLogger(AbstractConcurrentPageStoreTest.class);
+
+	private static final Random random = new Random();
+	private static final int FILE_SIZE_MIN = 1024 * 200;
+	private static final int FILE_SIZE_MAX = 1024 * 300;
+	private static final int SESSION_COUNT = 50;
+	private static final int FILES_COUNT = 1000;
+	private static final int SLEEP_MAX = 10;
+	private static final int THREAD_COUNT = 20;
+	private static final int READ_MODULO = 100;
+
+	private static final ConcurrentHashMap<String, IPageContext> contexts = new ConcurrentHashMap<>();
+
+	private static IPageContext getContext(String sessionId)
+	{
+		IPageContext context = new DummyPageContext(sessionId);
+
+		IPageContext existing = contexts.putIfAbsent(sessionId, context);
+		return existing != null ? existing : context;
+	}
+
+	private static class TaskPage implements IManageablePage
+	{
+		private final String sessionId;
+
+		private int id;
+
+		private byte[] data;
+
+		public TaskPage(String sessionId, int id)
+		{
+			this.sessionId = sessionId;
+
+			this.id = id;
+
+			int length = FILE_SIZE_MIN + random.nextInt(FILE_SIZE_MAX - FILE_SIZE_MIN);
+			data = new byte[length];
+			random.nextBytes(data);
+		}
+
+		public String getSessionId()
+		{
+			return sessionId;
+		}
+
+		public boolean check(TaskPage other)
+		{
+			if (other.data.length != other.data.length)
+			{
+				log.error("data.length != length");
+				return false;
+			}
+			if (other.id != other.id)
+			{
+				log.error("data.id != id");
+				return false;
+			}
+			if (other.sessionId != other.sessionId)
+			{
+				log.error("data.sessionId != sessionId");
+				return false;
+			}
+			return true;
+		}
+
+		@Override
+		public boolean isPageStateless()
+		{
+			return false;
+		}
+
+		@Override
+		public int getPageId()
+		{
+			return id;
+		}
+
+		@Override
+		public void detach()
+		{
+		}
+
+		@Override
+		public boolean setFreezePageId(boolean freeze)
+		{
+			return false;
+		}
+	}
+
+	private final Map<String, AtomicInteger> sessionCounter = new ConcurrentHashMap<String, AtomicInteger>();
+	private final ConcurrentLinkedQueue<TaskPage> pagesToSave = new ConcurrentLinkedQueue<TaskPage>();
+	private final ConcurrentLinkedQueue<TaskPage> filesToRead1 = new ConcurrentLinkedQueue<TaskPage>();
+	private final ConcurrentLinkedQueue<TaskPage> filesToRead2 = new ConcurrentLinkedQueue<TaskPage>();
+
+	private final AtomicInteger read1Count = new AtomicInteger(0);
+	private final AtomicInteger read2Count = new AtomicInteger(0);
+	private final AtomicInteger saveCount = new AtomicInteger(0);
+
+	private final AtomicBoolean saveDone = new AtomicBoolean(false);
+	private final AtomicBoolean read1Done = new AtomicBoolean(false);
+	private final AtomicBoolean read2Done = new AtomicBoolean(false);
+
+	private final AtomicInteger failures = new AtomicInteger();
+
+	private final AtomicInteger bytesWritten = new AtomicInteger(0);
+	private final AtomicInteger bytesRead = new AtomicInteger(0);
+
+	private final AtomicInteger saveTime = new AtomicInteger(0);
+
+	private RuntimeException exceptionThrownByThread;
+
+	private String randomSessionId()
+	{
+		List<String> s = new ArrayList<String>(sessionCounter.keySet());
+		return s.get(random.nextInt(s.size()));
+	}
+
+	private int nextSessionId(String sessionId)
+	{
+		AtomicInteger i = sessionCounter.get(sessionId);
+		return i.incrementAndGet();
+	}
+
+	private void generateSessionsAndPages()
+	{
+		for (int i = 0; i < SESSION_COUNT; ++i)
+		{
+			sessionCounter.put(UUID.randomUUID().toString(), new AtomicInteger(0));
+		}
+		for (int i = 0; i < FILES_COUNT; ++i)
+		{
+			String session = randomSessionId();
+			TaskPage file = new TaskPage(session, nextSessionId(session));
+			long now = System.nanoTime();
+			pagesToSave.add(file);
+			long duration = System.nanoTime() - now;
+			saveTime.addAndGet((int)duration);
+		}
+	}
+
+	private IPageStore pageStore;
+
+	/**
+	 * Stores RuntimeException into a field.
+	 */
+	private abstract class ExceptionCapturingRunnable implements Runnable
+	{
+		@Override
+		public final void run()
+		{
+			try
+			{
+				doRun();
+			}
+			catch (RuntimeException e)
+			{
+				exceptionThrownByThread = e;
+			}
+		}
+
+		/**
+		 * Called by {@link #run()}. Thrown RuntimeExceptions are stores into a field for later
+		 * check.
+		 */
+		protected abstract void doRun();
+	}
+
+	// Store/Save data in store
+	private class SaveRunnable extends ExceptionCapturingRunnable
+	{
+		@Override
+		protected void doRun()
+		{
+			TaskPage page;
+
+			while ((page = pagesToSave.poll()) != null || saveCount.get() < FILES_COUNT)
+			{
+				if (page != null)
+				{
+					pageStore.addPage(getContext(page.getSessionId()), page);
+
+					if (saveCount.get() % READ_MODULO == 0)
+					{
+						filesToRead1.add(page);
+					}
+					saveCount.incrementAndGet();
+					bytesWritten.addAndGet(page.data.length);
+				}
+
+				try
+				{
+					Thread.sleep(random.nextInt(SLEEP_MAX));
+				}
+				catch (InterruptedException e)
+				{
+					log.error(e.getMessage(), e);
+				}
+			}
+
+			saveDone.set(true);
+		}
+	};
+
+	// Read data from store
+	private class Read1Runnable extends ExceptionCapturingRunnable
+	{
+		@Override
+		protected void doRun()
+		{
+			TaskPage page;
+			while ((page = filesToRead1.poll()) != null || !saveDone.get())
+			{
+				if (page != null)
+				{
+					TaskPage other = (TaskPage)pageStore.getPage(getContext(page.getSessionId()),
+						page.getPageId());
+					if (page.check(other) == false)
+					{
+						failures.incrementAndGet();
+						log.error("Detected error number: " + failures.get());
+					}
+					filesToRead2.add(page);
+					read1Count.incrementAndGet();
+					bytesRead.addAndGet(other.data.length);
+				}
+
+				try
+				{
+					Thread.sleep(random.nextInt(SLEEP_MAX));
+				}
+				catch (InterruptedException e)
+				{
+					log.error(e.getMessage(), e);
+				}
+			}
+
+			read1Done.set(true);
+		}
+	};
+
+	private class Read2Runnable extends ExceptionCapturingRunnable
+	{
+		@Override
+		protected void doRun()
+		{
+			TaskPage page;
+			while ((page = filesToRead2.poll()) != null || !read1Done.get())
+			{
+				if (page != null)
+				{
+					TaskPage other = (TaskPage)pageStore.getPage(getContext(page.getSessionId()),
+						page.getPageId());
+					if (page.check(other) == false)
+					{
+						failures.incrementAndGet();
+						log.error("Detected error number: " + failures.get());
+					}
+					read2Count.incrementAndGet();
+					bytesRead.addAndGet(other.data.length);
+				}
+
+				try
+				{
+					Thread.sleep(random.nextInt(SLEEP_MAX));
+				}
+				catch (InterruptedException e)
+				{
+					log.error(e.getMessage(), e);
+				}
+			}
+
+			read2Done.set(true);
+		}
+	}
+
+	protected void doTestStore(IPageStore pageStore)
+	{
+		this.pageStore = new AsynchronousPageStore(pageStore, 100);
+
+		generateSessionsAndPages();
+		
+		log.info("Starting...");
+		long start = System.currentTimeMillis();
+
+		for (int i = 0; i < THREAD_COUNT; ++i)
+		{
+			new Thread(new Read1Runnable()).start();
+		}
+
+		for (int i = 0; i < THREAD_COUNT; ++i)
+		{
+			new Thread(new Read2Runnable()).start();
+		}
+
+		for (int i = 0; i < THREAD_COUNT; ++i)
+		{
+			new Thread(new SaveRunnable()).start();
+		}
+
+		while (!(read1Done.get() && read2Done.get() && saveDone.get()))
+		{
+			try
+			{
+				Thread.sleep(50);
+			}
+			catch (InterruptedException e)
+			{
+				log.error(e.getMessage(), e);
+			}
+		}
+
+		if (exceptionThrownByThread != null)
+		{
+			throw new RuntimeException("One of the worker threads failed.",
+				exceptionThrownByThread);
+		}
+
+		long duration = System.currentTimeMillis() - start;
+
+		log.info("Took: " + duration + " ms");
+		log.info("Save: " + saveCount.intValue() + " files, " + bytesWritten.get() + " bytes");
+		log.info("Read: " + (read1Count.get() + read2Count.get()) + " files, " + bytesRead.get()
+			+ " bytes");
+
+		log.info("Average save time (ns): " + (double)saveTime.get() / (double)saveCount.get());
+
+		assertEquals(0, failures.get());
+
+		for (String s : sessionCounter.keySet())
+		{
+			pageStore.removeAllPages(getContext(s));
+		}
+	}
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/wicket/blob/f6485517/wicket-core/src/test/java/org/apache/wicket/pageStore/AbstractPageStoreTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/pageStore/AbstractPageStoreTest.java b/wicket-core/src/test/java/org/apache/wicket/pageStore/AbstractPageStoreTest.java
index 17dd2c3..3fd83d3 100644
--- a/wicket-core/src/test/java/org/apache/wicket/pageStore/AbstractPageStoreTest.java
+++ b/wicket-core/src/test/java/org/apache/wicket/pageStore/AbstractPageStoreTest.java
@@ -26,25 +26,24 @@ import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 
-abstract class AbstractPageStoreTest
+public abstract class AbstractPageStoreTest
 {
-	final String sessionId = "1234567890";
-	final int pageId = 123;
-	private final ISerializer serializer = new JavaSerializer(getClass().getName());
-	private final IDataStore dataStore = new NoopDataStore();
-	private int maxEntries = 1;
-	IPageStore pageStore = null;
+	protected final String sessionId = "1234567890";
+	protected final int pageId = 123;
+	protected final ISerializer serializer = new JavaSerializer(getClass().getName());
+	protected int maxEntries = 1;
+	protected IPageStore pageStore = null;
 
 	@BeforeEach
-	void before()
+	public void before()
 	{
-		pageStore = createPageStore(serializer, dataStore, maxEntries);
+		pageStore = createPageStore(serializer, maxEntries);
 	}
 
-	abstract IPageStore createPageStore(ISerializer serializer, IDataStore dataStore, int maxEntries);
+	protected abstract IPageStore createPageStore(ISerializer serializer, int maxEntries);
 
 	@AfterEach
-	void after()
+	public void after()
 	{
 		if (pageStore != null)
 		{
@@ -59,9 +58,11 @@ abstract class AbstractPageStoreTest
 	@Test
 	void storePage()
 	{
-		pageStore.storePage(sessionId, new MockPage(pageId));
+		IPageContext context = new DummyPageContext(sessionId);
+		
+		pageStore.addPage(context, new MockPage(pageId));
 
-		assertNotNull(pageStore.getPage(sessionId, pageId));
+		assertNotNull(pageStore.getPage(context, pageId));
 	}
 
 	/**
@@ -70,46 +71,65 @@ abstract class AbstractPageStoreTest
 	@Test
 	void storePage2()
 	{
+		IPageContext context = new DummyPageContext(sessionId);
 		int maxEntries = 10;
 
-		pageStore = createPageStore(serializer, dataStore, maxEntries);
+		pageStore = createPageStore(serializer, maxEntries);
 
-		pageStore.storePage(sessionId, new MockPage(pageId));
-		pageStore.storePage(sessionId, new MockPage(pageId));
+		pageStore.addPage(context, new MockPage(pageId));
+		pageStore.addPage(context, new MockPage(pageId));
 
-		assertNotNull(pageStore.getPage(sessionId, pageId));
+		assertNotNull(pageStore.getPage(context, pageId));
 
-		pageStore.removePage(sessionId, pageId);
+		pageStore.removePage(context, new MockPage(pageId));
 
-		assertNull(pageStore.getPage(sessionId, pageId));
+		assertNull(pageStore.getPage(context, pageId));
 	}
 
 	@Test
 	void removePage()
 	{
-		pageStore.storePage(sessionId, new MockPage(pageId));
+		IPageContext context = new DummyPageContext(sessionId);
+		
+		pageStore.addPage(context, new MockPage(pageId));
 
-		assertNotNull(pageStore.getPage(sessionId, pageId));
+		assertNotNull(pageStore.getPage(context, pageId));
 
-		pageStore.removePage(sessionId, pageId);
+		pageStore.removePage(context, new MockPage(pageId));
 
-		assertNull(pageStore.getPage(sessionId, pageId));
+		assertNull(pageStore.getPage(context, pageId));
+	}
+
+	@Test
+	void removeAllPages()
+	{
+		IPageContext context = new DummyPageContext(sessionId);
+		
+		pageStore.addPage(context, new MockPage(pageId));
+
+		assertNotNull(pageStore.getPage(context, pageId));
+
+		pageStore.removeAllPages(context);
+
+		assertNull(pageStore.getPage(context, pageId));
 	}
 
 	/**
-	 * Verify that at most {@code maxEntries} per session can be put in the cache
+	 * Verify that at most {@code maxEntries} per session can be put in the store
 	 */
 	@Test
 	void maxSizeSameSession()
 	{
-		pageStore.storePage(sessionId, new MockPage(pageId));
+		IPageContext context = new DummyPageContext(sessionId);
+		
+		pageStore.addPage(context, new MockPage(pageId));
 
-		assertNotNull(pageStore.getPage(sessionId, pageId));
+		assertNotNull(pageStore.getPage(context, pageId));
 
 		int pageId2 = 234;
-		pageStore.storePage(sessionId, new MockPage(pageId2));
-		assertNull(pageStore.getPage(sessionId, pageId));
-		assertNotNull(pageStore.getPage(sessionId, pageId2));
+		pageStore.addPage(context, new MockPage(pageId2));
+		assertNull(pageStore.getPage(context, pageId));
+		assertNotNull(pageStore.getPage(context, pageId2));
 	}
 
 	/**
@@ -119,15 +139,16 @@ abstract class AbstractPageStoreTest
 	@Test
 	void maxSizeDifferentSessions()
 	{
-		String sessionId2 = "0987654321";
+		IPageContext context = new DummyPageContext(sessionId);
+		IPageContext context2 = new DummyPageContext("0987654321");
 
-		pageStore.storePage(sessionId, new MockPage(pageId));
+		pageStore.addPage(context, new MockPage(pageId));
 
-		assertNotNull(pageStore.getPage(sessionId, pageId));
+		assertNotNull(pageStore.getPage(context, pageId));
 
-		pageStore.storePage(sessionId2, new MockPage(pageId));
+		pageStore.addPage(context2, new MockPage(pageId));
 
-		assertNull(pageStore.getPage(sessionId, pageId));
-		assertNotNull(pageStore.getPage(sessionId2, pageId));
+		assertNotNull(pageStore.getPage(context, pageId));
+		assertNotNull(pageStore.getPage(context2, pageId));
 	}
 }