You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2011/07/06 13:38:24 UTC

svn commit: r1143355 - in /wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils: debugbar/ diskstore/ diskstore/browser/

Author: mgrigorov
Date: Wed Jul  6 11:38:24 2011
New Revision: 1143355

URL: http://svn.apache.org/viewvc?rev=1143355&view=rev
Log:
WICKET-3865 Create a debug page with which the developer can browse the disk data store

Add an extension of DiskDataStore which can extract the last N pages.
Add a page which shows the details about the extracted pages.


Added:
    wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/
    wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/DebugDiskDataStore.java
    wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/DebugPageManagerProvider.java
    wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/DiskStoreBrowserPage.html
    wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/DiskStoreBrowserPage.java
    wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/PageWindowModel.java
    wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/
    wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/BrowserPanel.html
    wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/BrowserPanel.java
    wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/BrowserTable.java
    wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/PageWindowColumn.java
    wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/PageWindowDescription.java
    wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/PageWindowProvider.java
Modified:
    wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/debugbar/DebugBarInitializer.java

Modified: wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/debugbar/DebugBarInitializer.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/debugbar/DebugBarInitializer.java?rev=1143355&r1=1143354&r2=1143355&view=diff
==============================================================================
--- wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/debugbar/DebugBarInitializer.java (original)
+++ wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/debugbar/DebugBarInitializer.java Wed Jul  6 11:38:24 2011
@@ -18,6 +18,7 @@ package org.apache.wicket.devutils.debug
 
 import org.apache.wicket.Application;
 import org.apache.wicket.IInitializer;
+import org.apache.wicket.devutils.diskstore.DebugDiskDataStore;
 
 /**
  * Debug bar module initializer
@@ -36,6 +37,7 @@ public class DebugBarInitializer impleme
 		DebugBar.registerContributor(InspectorDebugPanel.DEBUG_BAR_CONTRIB, application);
 		DebugBar.registerContributor(SessionSizeDebugPanel.DEBUG_BAR_CONTRIB, application);
 		DebugBar.registerContributor(PageSizeDebugPanel.DEBUG_BAR_CONTRIB, application);
+		DebugDiskDataStore.register(application);
 	}
 
 	@Override

Added: wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/DebugDiskDataStore.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/DebugDiskDataStore.java?rev=1143355&view=auto
==============================================================================
--- wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/DebugDiskDataStore.java (added)
+++ wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/DebugDiskDataStore.java Wed Jul  6 11:38:24 2011
@@ -0,0 +1,80 @@
+/*
+ * 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.devutils.diskstore;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.wicket.Application;
+import org.apache.wicket.pageStore.DiskDataStore;
+import org.apache.wicket.pageStore.PageWindowManager;
+import org.apache.wicket.pageStore.PageWindowManager.PageWindow;
+import org.apache.wicket.protocol.http.WebApplication;
+import org.apache.wicket.util.lang.Bytes;
+
+/**
+ * 
+ */
+public class DebugDiskDataStore extends DiskDataStore
+{
+
+	/**
+	 * Construct.
+	 * 
+	 * @param applicationName
+	 * @param fileStoreFolder
+	 * @param maxSizePerSession
+	 */
+	public DebugDiskDataStore(String applicationName, File fileStoreFolder, Bytes maxSizePerSession)
+	{
+		super(applicationName, fileStoreFolder, maxSizePerSession);
+
+	}
+
+	/**
+	 * 
+	 * @param sessionId
+	 * @param count
+	 * @return a list of the last N page windows
+	 */
+	public List<PageWindow> getLastPageWindows(String sessionId, int count)
+	{
+		List<PageWindow> pageWindows = new ArrayList<PageWindowManager.PageWindow>();
+
+		SessionEntry sessionEntry = getSessionEntry(sessionId, false);
+		if (sessionEntry != null)
+		{
+			PageWindowManager windowManager = sessionEntry.getManager();
+			pageWindows.addAll(windowManager.getLastPageWindows(count));
+		}
+		return pageWindows;
+	}
+
+	/**
+	 * 
+	 * @param application
+	 */
+	public static void register(final Application application)
+	{
+		application.setPageManagerProvider(new DebugPageManagerProvider(application));
+
+		((WebApplication)application).mountPage("wicket/internal/debug/diskDataStore",
+			DiskStoreBrowserPage.class);
+	}
+
+}

Added: wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/DebugPageManagerProvider.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/DebugPageManagerProvider.java?rev=1143355&view=auto
==============================================================================
--- wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/DebugPageManagerProvider.java (added)
+++ wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/DebugPageManagerProvider.java Wed Jul  6 11:38:24 2011
@@ -0,0 +1,63 @@
+/*
+ * 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.devutils.diskstore;
+
+import java.io.File;
+
+import org.apache.wicket.Application;
+import org.apache.wicket.DefaultPageManagerProvider;
+import org.apache.wicket.pageStore.DiskDataStore;
+import org.apache.wicket.pageStore.IDataStore;
+import org.apache.wicket.settings.IStoreSettings;
+import org.apache.wicket.util.lang.Bytes;
+
+/**
+ */
+public class DebugPageManagerProvider extends DefaultPageManagerProvider
+{
+
+	private DebugDiskDataStore dataStore;
+
+	/**
+	 * Construct.
+	 * 
+	 * @param application
+	 */
+	public DebugPageManagerProvider(Application application)
+	{
+		super(application);
+	}
+
+	/**
+	 * @return the extended with debug information {@link DiskDataStore}
+	 */
+	public DebugDiskDataStore getDataStore()
+	{
+		return dataStore;
+	}
+
+	@Override
+	protected IDataStore newDataStore()
+	{
+		IStoreSettings storeSettings = application.getStoreSettings();
+		File fileStoreFolder = storeSettings.getFileStoreFolder();
+		Bytes maxSizePerSession = storeSettings.getMaxSizePerSession();
+		dataStore = new DebugDiskDataStore(application.getName(), fileStoreFolder,
+			maxSizePerSession);
+		return dataStore;
+	}
+}

Added: wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/DiskStoreBrowserPage.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/DiskStoreBrowserPage.html?rev=1143355&view=auto
==============================================================================
--- wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/DiskStoreBrowserPage.html (added)
+++ wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/DiskStoreBrowserPage.html Wed Jul  6 11:38:24 2011
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   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.
+-->
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
+	
+	<head>
+		<title>Debug DiskDataStore page</title>
+	</head>
+	
+	<body>
+
+        <div wicket:id="tree">default</div>	
+ 
+	</body>
+	
+</html>
\ No newline at end of file

Added: wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/DiskStoreBrowserPage.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/DiskStoreBrowserPage.java?rev=1143355&view=auto
==============================================================================
--- wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/DiskStoreBrowserPage.java (added)
+++ wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/DiskStoreBrowserPage.java Wed Jul  6 11:38:24 2011
@@ -0,0 +1,51 @@
+/*
+ * 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.devutils.diskstore;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.devutils.diskstore.browser.BrowserPanel;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+
+/**
+ * A page that shows the attributes (id, name, size) of the pages stored in the data stores.
+ */
+public class DiskStoreBrowserPage extends WebPage
+{
+
+	/**
+	 * Construct.
+	 * 
+	 * @param parameters
+	 *            the request parameters
+	 */
+	public DiskStoreBrowserPage(final PageParameters parameters)
+	{
+		super(parameters);
+
+		Component tree;
+// tree = new LabelTree("tree", new PageWindowModel(sessionId, dataStore));
+		tree = new BrowserPanel("tree");
+		add(tree);
+	}
+
+	@Override
+	public boolean isVersioned()
+	{
+		return false;
+	}
+}

Added: wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/PageWindowModel.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/PageWindowModel.java?rev=1143355&view=auto
==============================================================================
--- wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/PageWindowModel.java (added)
+++ wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/PageWindowModel.java Wed Jul  6 11:38:24 2011
@@ -0,0 +1,69 @@
+/*
+ * 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.devutils.diskstore;
+
+import java.util.List;
+
+import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.DefaultTreeModel;
+
+import org.apache.wicket.Application;
+import org.apache.wicket.model.AbstractReadOnlyModel;
+import org.apache.wicket.pageStore.PageWindowManager.PageWindow;
+import org.apache.wicket.serialize.ISerializer;
+
+class PageWindowModel extends AbstractReadOnlyModel<DefaultTreeModel>
+{
+	private final DefaultTreeModel treeModel;
+
+	public PageWindowModel(String sessionId, DebugDiskDataStore dataStore)
+	{
+		List<PageWindow> pageWindows = dataStore.getLastPageWindows(sessionId, 50);
+		DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode();
+		initialize(rootNode, pageWindows, dataStore, sessionId);
+		treeModel = new DefaultTreeModel(rootNode);
+	}
+
+	@Override
+	public DefaultTreeModel getObject()
+	{
+		return treeModel;
+	}
+
+	private void initialize(final DefaultMutableTreeNode root, final List<PageWindow> pageWindows,
+		DebugDiskDataStore dataStore, String sessionId)
+	{
+		ISerializer serializer = Application.get().getFrameworkSettings().getSerializer();
+
+		for (PageWindow pageWindow : pageWindows)
+		{
+			int pageId = pageWindow.getPageId();
+			DefaultMutableTreeNode pageIdNode = new DefaultMutableTreeNode(pageId);
+			root.add(pageIdNode);
+
+			byte[] data = dataStore.getData(sessionId, pageId);
+			Object page = serializer.deserialize(data);
+			DefaultMutableTreeNode pageNameNode = new DefaultMutableTreeNode(page.getClass()
+				.getName());
+			pageIdNode.add(pageNameNode);
+
+			DefaultMutableTreeNode pageSizeNode = new DefaultMutableTreeNode("Size: " +
+				data.length + " bytes");
+			pageIdNode.add(pageSizeNode);
+		}
+	}
+}

Added: wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/BrowserPanel.html
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/BrowserPanel.html?rev=1143355&view=auto
==============================================================================
--- wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/BrowserPanel.html (added)
+++ wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/BrowserPanel.html Wed Jul  6 11:38:24 2011
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   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.
+-->
+<html xmlns="http://www.w3.org/1999/xhtml" xmlns:wicket="http://wicket.apache.org">
+<wicket:panel>
+
+	<table wicket:id="table" border="1"></table>
+
+</wicket:panel>
+</html>
\ No newline at end of file

Added: wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/BrowserPanel.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/BrowserPanel.java?rev=1143355&view=auto
==============================================================================
--- wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/BrowserPanel.java (added)
+++ wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/BrowserPanel.java Wed Jul  6 11:38:24 2011
@@ -0,0 +1,64 @@
+/*
+ * 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.devutils.diskstore.browser;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.model.Model;
+
+/**
+ * A panel that shows the data about pages in the data store
+ */
+public class BrowserPanel extends Panel
+{
+
+	/**
+	 * Construct.
+	 * 
+	 * @param id
+	 *            the component id
+	 */
+	public BrowserPanel(String id)
+	{
+		super(id);
+
+		BrowserTable table = createTable("table");
+		add(table);
+	}
+
+	private BrowserTable createTable(String id)
+	{
+		PageWindowProvider provider = new PageWindowProvider();
+
+		List<IColumn<PageWindowDescription>> columns = new ArrayList<IColumn<PageWindowDescription>>();
+
+		PageWindowColumn pageIdColumn = new PageWindowColumn(Model.of("Id"), "id");
+		columns.add(pageIdColumn);
+
+		PageWindowColumn pageNameColumn = new PageWindowColumn(Model.of("Name"), "name");
+		columns.add(pageNameColumn);
+
+		PageWindowColumn pageSizeColumn = new PageWindowColumn(Model.of("Size"), "size");
+		columns.add(pageSizeColumn);
+
+		return new BrowserTable(id, columns, provider);
+	}
+
+}

Added: wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/BrowserTable.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/BrowserTable.java?rev=1143355&view=auto
==============================================================================
--- wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/BrowserTable.java (added)
+++ wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/BrowserTable.java Wed Jul  6 11:38:24 2011
@@ -0,0 +1,47 @@
+/*
+ * 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.devutils.diskstore.browser;
+
+import java.util.List;
+
+import org.apache.wicket.extensions.markup.html.repeater.data.table.DefaultDataTable;
+import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
+
+/**
+ * A data table that shows the attributes of the recently stored pages in the data store. The last
+ * used pages are rendered first.
+ */
+public class BrowserTable extends DefaultDataTable<PageWindowDescription>
+{
+
+	/**
+	 * Construct.
+	 * 
+	 * @param id
+	 *            the component id
+	 * @param columns
+	 *            the columns that show the page attributes
+	 * @param provider
+	 *            the provider of page descriptions
+	 */
+	public BrowserTable(String id, List<IColumn<PageWindowDescription>> columns,
+		PageWindowProvider provider)
+	{
+		super(id, columns, provider, 20);
+	}
+
+}

Added: wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/PageWindowColumn.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/PageWindowColumn.java?rev=1143355&view=auto
==============================================================================
--- wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/PageWindowColumn.java (added)
+++ wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/PageWindowColumn.java Wed Jul  6 11:38:24 2011
@@ -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.devutils.diskstore.browser;
+
+import org.apache.wicket.Application;
+import org.apache.wicket.Session;
+import org.apache.wicket.devutils.diskstore.DebugDiskDataStore;
+import org.apache.wicket.devutils.diskstore.DebugPageManagerProvider;
+import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
+import org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.repeater.Item;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.serialize.ISerializer;
+
+/**
+ * A column that shows the page attributes (id, name, size)
+ */
+public class PageWindowColumn extends PropertyColumn<PageWindowDescription>
+{
+	/**
+	 * Construct.
+	 * 
+	 * @param displayModel
+	 *            the header
+	 * @param propertyExpression
+	 *            the page attribute
+	 */
+	public PageWindowColumn(IModel<String> displayModel, String propertyExpression)
+	{
+		super(displayModel, propertyExpression);
+	}
+
+	@Override
+	public void populateItem(Item<ICellPopulator<PageWindowDescription>> cellItem,
+		String componentId, IModel<PageWindowDescription> rowModel)
+	{
+		String label;
+		PageWindowDescription windowDescription = rowModel.getObject();
+		if ("name".equals(getPropertyExpression()))
+		{
+			int pageId = windowDescription.getId();
+			DebugPageManagerProvider pageManagerProvider = (DebugPageManagerProvider)Application.get()
+				.getPageManagerProvider();
+			DebugDiskDataStore dataStore = pageManagerProvider.getDataStore();
+			String sessionId = Session.get().getId();
+			byte[] data = dataStore.getData(sessionId, pageId);
+			ISerializer serializer = Application.get().getFrameworkSettings().getSerializer();
+			Object page = serializer.deserialize(data);
+			label = page.getClass().getName();
+		}
+		else if ("id".equals(getPropertyExpression()))
+		{
+			label = Integer.toString(windowDescription.getId());
+		}
+		else if ("size".equals(getPropertyExpression()))
+		{
+			label = Integer.toString(windowDescription.getSize());
+		}
+		else
+		{
+			label = "unknown: " + getPropertyExpression();
+		}
+
+		cellItem.add(new Label(componentId, label));
+	}
+}

Added: wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/PageWindowDescription.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/PageWindowDescription.java?rev=1143355&view=auto
==============================================================================
--- wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/PageWindowDescription.java (added)
+++ wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/PageWindowDescription.java Wed Jul  6 11:38:24 2011
@@ -0,0 +1,52 @@
+/*
+ * 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.devutils.diskstore.browser;
+
+import org.apache.wicket.IClusterable;
+import org.apache.wicket.pageStore.PageWindowManager.PageWindow;
+
+/**
+ * 
+ */
+public class PageWindowDescription implements IClusterable
+{
+	private final int id;
+
+	private final int size;
+
+	PageWindowDescription(PageWindow pageWindow)
+	{
+		id = pageWindow.getPageId();
+		size = pageWindow.getFilePartSize();
+	}
+
+	/**
+	 * @return
+	 */
+	public int getId()
+	{
+		return id;
+	}
+
+	/**
+	 * @return
+	 */
+	public int getSize()
+	{
+		return size;
+	}
+}

Added: wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/PageWindowProvider.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/PageWindowProvider.java?rev=1143355&view=auto
==============================================================================
--- wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/PageWindowProvider.java (added)
+++ wicket/trunk/wicket-devutils/src/main/java/org/apache/wicket/devutils/diskstore/browser/PageWindowProvider.java Wed Jul  6 11:38:24 2011
@@ -0,0 +1,96 @@
+/*
+ * 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.devutils.diskstore.browser;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.wicket.Application;
+import org.apache.wicket.Session;
+import org.apache.wicket.devutils.diskstore.DebugDiskDataStore;
+import org.apache.wicket.devutils.diskstore.DebugPageManagerProvider;
+import org.apache.wicket.extensions.markup.html.repeater.data.sort.ISortState;
+import org.apache.wicket.extensions.markup.html.repeater.data.table.ISortableDataProvider;
+import org.apache.wicket.markup.repeater.data.IDataProvider;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.pageStore.PageWindowManager.PageWindow;
+
+/**
+ * An {@link IDataProvider} that extracts the information about the stored pages
+ */
+public class PageWindowProvider implements ISortableDataProvider<PageWindowDescription>
+{
+	private static final int MAX_PAGES_TO_READ = 1000;
+
+	public Iterator<? extends PageWindowDescription> iterator(int first, int count)
+	{
+		List<PageWindow> lastPageWindows = getPageWindows();
+		List<PageWindow> subList = lastPageWindows.subList(first, first + count);
+		List<PageWindowDescription> pageDescriptions = new ArrayList<PageWindowDescription>();
+		for (PageWindow pw : subList)
+		{
+			pageDescriptions.add(new PageWindowDescription(pw));
+		}
+
+		return pageDescriptions.iterator();
+	}
+
+	private List<PageWindow> getPageWindows()
+	{
+		List<PageWindow> lastPageWindows = new ArrayList<PageWindow>();
+		if (Session.exists() && Session.get().isTemporary() == false)
+		{
+			String sessionId = Session.get().getId();
+			DebugPageManagerProvider pageManagerProvider = (DebugPageManagerProvider)Application.get()
+				.getPageManagerProvider();
+			DebugDiskDataStore dataStore = pageManagerProvider.getDataStore();
+			lastPageWindows.addAll(dataStore.getLastPageWindows(sessionId, MAX_PAGES_TO_READ));
+		}
+		return lastPageWindows;
+	}
+
+	public int size()
+	{
+		return getPageWindows().size();
+	}
+
+	/**
+	 * @param description
+	 * 
+	 *            {@inheritDoc}
+	 */
+	public IModel<PageWindowDescription> model(PageWindowDescription description)
+	{
+		return new Model<PageWindowDescription>(description);
+	}
+
+	public void detach()
+	{
+	}
+
+	/*
+	 * No sort state for now. The provider is ISortableDataProvider just because we use
+	 * DefaultDataTable
+	 */
+	public ISortState getSortState()
+	{
+		return null;
+	}
+
+}