Permalink
Browse files

initial version of wicket fast serializer

  • Loading branch information...
1 parent 53860cd commit 6d12340534c9f6da9579496d46bf3f19ded40e2f @michaelmosmann michaelmosmann committed Oct 12, 2013
Showing with 1,166 additions and 1 deletion.
  1. +2 −1 .gitignore
  2. +4 −0 jdk-1.6-parent/serializer-fast/README.md
  3. +18 −0 jdk-1.6-parent/serializer-fast/lic/header.txt
  4. +56 −0 jdk-1.6-parent/serializer-fast/pom.xml
  5. +22 −0 jdk-1.6-parent/serializer-fast/refreshLicense.sh
  6. +10 −0 .../serializer-fast/src/main/java/org/wicketstuff/pageserializer/fast/FastWicketSerialException.java
  7. +70 −0 ...arent/serializer-fast/src/main/java/org/wicketstuff/pageserializer/fast/FastWicketSerializer.java
  8. +51 −0 jdk-1.6-parent/serializer-fast/src/test/java/org/wicketstuff/pageserializer/fast/HomePage.java
  9. +129 −0 ...-parent/serializer-fast/src/test/java/org/wicketstuff/pageserializer/fast/KryoSerializerTest.java
  10. +73 −0 jdk-1.6-parent/serializer-fast/src/test/java/org/wicketstuff/pageserializer/fast/Start.java
  11. +63 −0 ...6-parent/serializer-fast/src/test/java/org/wicketstuff/pageserializer/fast/WicketApplication.java
  12. +23 −0 ...lizer-fast/src/test/java/org/wicketstuff/pageserializer/fast/components/NotSerializablePanel.html
  13. +38 −0 ...lizer-fast/src/test/java/org/wicketstuff/pageserializer/fast/components/NotSerializablePanel.java
  14. +34 −0 ...ent/serializer-fast/src/test/java/org/wicketstuff/pageserializer/fast/components/SamplePanel.html
  15. +57 −0 ...ent/serializer-fast/src/test/java/org/wicketstuff/pageserializer/fast/components/SamplePanel.java
  16. +34 −0 ...parent/serializer-fast/src/test/java/org/wicketstuff/pageserializer/fast/examples/SamplePage.html
  17. +44 −0 ...parent/serializer-fast/src/test/java/org/wicketstuff/pageserializer/fast/examples/SamplePage.java
  18. +37 −0 ...-parent/serializer-fast/src/test/java/org/wicketstuff/pageserializer/fast/pages/ListViewPage.html
  19. +53 −0 ...-parent/serializer-fast/src/test/java/org/wicketstuff/pageserializer/fast/pages/ListViewPage.java
  20. +25 −0 .../serializer-fast/src/test/java/org/wicketstuff/pageserializer/fast/pages/NotSerializablePage.html
  21. +35 −0 .../serializer-fast/src/test/java/org/wicketstuff/pageserializer/fast/pages/NotSerializablePage.java
  22. +33 −0 ....6-parent/serializer-fast/src/test/java/org/wicketstuff/pageserializer/fast/pages/SamplePage.html
  23. +36 −0 ....6-parent/serializer-fast/src/test/java/org/wicketstuff/pageserializer/fast/pages/SamplePage.java
  24. +29 −0 jdk-1.6-parent/serializer-fast/src/test/resources/log4j.properties
  25. +48 −0 jdk-1.6-parent/serializer-fast/src/test/resources/org/wicketstuff/pageserializer/fast/HomePage.html
  26. +54 −0 jdk-1.6-parent/serializer-fast/src/test/webapp/WEB-INF/web.xml
  27. BIN jdk-1.6-parent/serializer-fast/src/test/webapp/logo.png
  28. +88 −0 jdk-1.6-parent/serializer-fast/src/test/webapp/style.css
View
@@ -8,4 +8,5 @@ velocity.log
META-INF
.scala_dependencies
.externalToolBuilders
-*~
+*~
+
@@ -0,0 +1,4 @@
+Fast Wicket Serializer Project
+===
+
+
@@ -0,0 +1,18 @@
+Copyright (C)
+ 2008 Jeremy Thomerson <jeremy@thomersonfamily.com>
+ 2012 Michael Mosmann <michael@mosmann.de>
+
+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.
@@ -0,0 +1,56 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.wicketstuff</groupId>
+ <artifactId>jdk-1.6-parent</artifactId>
+ <version>6.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>wicketstuff-serializer-fast</artifactId>
+
+ <name>WicketStuff Fast Serializer</name>
+ <description>ISerializer based on https://code.google.com/p/fast-serialization/</description>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>de.ruedigermoeller</groupId>
+ <artifactId>fst</artifactId>
+ <version>1.27</version>
+ </dependency>
+ <dependency>
+ <groupId>org.eclipse.jetty.aggregate</groupId>
+ <artifactId>jetty-all-server</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <!-- USAGE: mvn license:check OR mvn license:format -->
+ <groupId>com.mycila.maven-license-plugin</groupId>
+ <artifactId>maven-license-plugin</artifactId>
+ <configuration>
+ <header>${header.location}</header>
+ <excludes>
+ <exclude>src/test/java/**.tree</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <properties>
+ <header.location>lic/header.txt</header.location>
+ </properties>
+</project>
@@ -0,0 +1,22 @@
+#!/bin/sh
+#
+# Copyright (C) 2008 Jeremy Thomerson <jeremy@thomersonfamily.com>
+#
+# 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.
+#
+
+mvn license:format
+
@@ -0,0 +1,10 @@
+package org.wicketstuff.pageserializer.fast;
+
+
+public class FastWicketSerialException extends RuntimeException {
+
+ public FastWicketSerialException(String message, Exception cause) {
+ super(message, cause);
+ }
+
+}
@@ -0,0 +1,70 @@
+package org.wicketstuff.pageserializer.fast;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import org.apache.wicket.serialize.ISerializer;
+import org.apache.wicket.util.io.ByteArrayOutputStream;
+import org.apache.wicket.util.lang.Args;
+import org.apache.wicket.util.lang.Bytes;
+
+import de.ruedigermoeller.serialization.FSTConfiguration;
+import de.ruedigermoeller.serialization.FSTObjectInput;
+import de.ruedigermoeller.serialization.FSTObjectOutput;
+
+
+public class FastWicketSerializer implements ISerializer{
+
+ /**
+ * The size of the {@link ByteBuffer} that is used to hold the serialized page
+ */
+ private static final Bytes DEFAULT_BUFFER_SIZE = Bytes.megabytes(10L);
+
+ private final Bytes bufferSize;
+
+ static final FSTConfiguration fastSerialConfig = FSTConfiguration.createDefaultConfiguration();
+
+ public FastWicketSerializer(Bytes bufferSize) {
+ this.bufferSize = Args.notNull(bufferSize, "bufferSize");
+ }
+
+
+
+ @Override
+ public byte[] serialize(Object object) {
+
+ try {
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream((int) this.bufferSize.bytes());
+ FSTObjectOutput out = fastSerialConfig.getObjectOutput(buffer);
+ out.writeObject(object);
+ // DON'T out.close() when using factory method;
+ out.flush();
+ buffer.close();
+ return buffer.toByteArray();
+ } catch (RuntimeException e) {
+ throw new FastWicketSerialException("serialize",e);
+ } catch (IOException e) {
+ throw new FastWicketSerialException("serialize",e);
+ }
+ }
+
+ @Override
+ public Object deserialize(byte[] data) {
+ try {
+ ByteArrayInputStream buffer=new ByteArrayInputStream(data);
+
+ FSTObjectInput in = fastSerialConfig.getObjectInput(buffer);
+ Object result = in.readObject();
+ // DON'T: in.close(); here prevents reuse and will result in an exception
+ buffer.close();
+ return result;
+
+ } catch (IOException e) {
+ throw new FastWicketSerialException("deserialize", e);
+ } catch (ClassNotFoundException e) {
+ throw new FastWicketSerialException("deserialize", e);
+ }
+ }
+
+}
@@ -0,0 +1,51 @@
+/**
+ * Copyright (C)
+ * 2008 Jeremy Thomerson <jeremy@thomersonfamily.com>
+ * 2012 Michael Mosmann <michael@mosmann.de>
+ *
+ * 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.wicketstuff.pageserializer.fast;
+
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.markup.html.AjaxLink;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+
+public class HomePage extends WebPage
+{
+ private static final long serialVersionUID = 1L;
+
+ public HomePage(final PageParameters parameters)
+ {
+ super(parameters);
+
+ add(new Label("label", "Kryo Rocks!"));
+
+ add(new AjaxLink<Void>("link")
+ {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ public void onClick(AjaxRequestTarget target)
+ {
+ System.err.println("click");
+ }
+ });
+
+ }
+}
@@ -0,0 +1,129 @@
+/**
+ * Copyright (C)
+ * 2008 Jeremy Thomerson <jeremy@thomersonfamily.com>
+ * 2012 Michael Mosmann <michael@mosmann.de>
+ *
+ * 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.wicketstuff.pageserializer.fast;
+
+import org.apache.wicket.request.mapper.parameter.PageParameters;
+import org.apache.wicket.serialize.ISerializer;
+import org.apache.wicket.util.tester.WicketTester;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.wicketstuff.pageserializer.fast.FastWicketSerialException;
+import org.wicketstuff.pageserializer.fast.FastWicketSerializer;
+import org.wicketstuff.pageserializer.fast.pages.NotSerializablePage;
+import org.wicketstuff.pageserializer.fast.pages.SamplePage;
+
+/**
+ * Simple test using the WicketTester
+ */
+public class KryoSerializerTest
+{
+ private WicketTester tester;
+
+ @Before
+ public void setUp()
+ {
+ tester = new WicketTester(new WicketApplication());
+ }
+
+ @After
+ public void tearDown()
+ {
+ tester.destroy();
+ }
+
+ @Test
+ public void homepageRendersSuccessfully()
+ {
+ // start and render the test page
+ HomePage page = tester.startPage(HomePage.class);
+
+ // assert rendered page class
+ tester.assertRenderedPage(HomePage.class);
+
+ ISerializer pageSerializer = getAndCheckSerializer();
+
+ byte[] data = pageSerializer.serialize(page);
+ Assert.assertNotNull("The produced data should not be null!", data);
+
+ // data length can fluctuate based on the object field values
+ Assert.assertEquals("The produced data length is not correct!", 444, data.length);
+
+ Object object = pageSerializer.deserialize(data);
+ Assert.assertTrue(
+ "The deserialized page must be of type HomePage. Type: " + object.getClass(),
+ object instanceof HomePage);
+
+ }
+
+ @Test
+ public void samplepageRendersSuccessfully()
+ {
+ // start and render the test page
+ SamplePage page = tester.startPage(SamplePage.class,
+ new PageParameters().add("Test", "asString"));
+
+ // assert rendered page class
+ tester.assertRenderedPage(SamplePage.class);
+
+ ISerializer pageSerializer = getAndCheckSerializer();
+
+ byte[] data = pageSerializer.serialize(page);
+ Assert.assertNotNull("The produced data should not be null!", data);
+
+ Object object = pageSerializer.deserialize(data);
+ Assert.assertTrue(
+ "The deserialized page must be of type HomePage. Type: " + object.getClass(),
+ object instanceof SamplePage);
+
+ SamplePage samplePage = (SamplePage)object;
+
+ tester.startPage(samplePage);
+
+ // assert rendered page class
+ tester.assertRenderedPage(SamplePage.class);
+ }
+
+ @Test(expected=FastWicketSerialException.class)
+ public void notSerializableCompontentThrowsException()
+ {
+
+ NotSerializablePage page = tester.startPage(NotSerializablePage.class,
+ new PageParameters().add("Test", "asString"));
+
+ // assert rendered page class
+ tester.assertRenderedPage(NotSerializablePage.class);
+
+ ISerializer pageSerializer = getAndCheckSerializer();
+
+ byte[] data = pageSerializer.serialize(page);
+ }
+
+ private ISerializer getAndCheckSerializer()
+ {
+ ISerializer pageSerializer = tester.getApplication().getFrameworkSettings().getSerializer();
+ Assert.assertTrue(
+ "The configured IObjectSerializer is not instance of KryoSerializer! Type: " +
+ pageSerializer.getClass(), pageSerializer instanceof FastWicketSerializer);
+ return pageSerializer;
+ }
+}
Oops, something went wrong.

0 comments on commit 6d12340

Please sign in to comment.