Author: simonetripodi
Date: Mon Oct 1 13:47:41 2012
New Revision: 1392328
URL: http://svn.apache.org/viewvc?rev=1392328&view=rev
Log:
[DIRECTMEMORY-103] Add Kryo serializer - patch submitted by Min Zhou
Added:
directmemory/trunk/serializers/kryo/
directmemory/trunk/serializers/kryo/pom.xml (with props)
directmemory/trunk/serializers/kryo/src/
directmemory/trunk/serializers/kryo/src/main/
directmemory/trunk/serializers/kryo/src/main/java/
directmemory/trunk/serializers/kryo/src/main/java/org/
directmemory/trunk/serializers/kryo/src/main/java/org/apache/
directmemory/trunk/serializers/kryo/src/main/java/org/apache/directmemory/
directmemory/trunk/serializers/kryo/src/main/java/org/apache/directmemory/serialization/
directmemory/trunk/serializers/kryo/src/main/java/org/apache/directmemory/serialization/kryo/
directmemory/trunk/serializers/kryo/src/main/java/org/apache/directmemory/serialization/kryo/KryoSerializer.java
(with props)
directmemory/trunk/serializers/kryo/src/main/java/org/apache/directmemory/serialization/kryo/package-info.java
(with props)
directmemory/trunk/serializers/kryo/src/main/resources/
directmemory/trunk/serializers/kryo/src/main/resources/META-INF/
directmemory/trunk/serializers/kryo/src/main/resources/META-INF/services/
directmemory/trunk/serializers/kryo/src/main/resources/META-INF/services/org.apache.directmemory.serialization.Serializer
directmemory/trunk/serializers/kryo/src/test/
directmemory/trunk/serializers/kryo/src/test/java/
directmemory/trunk/serializers/kryo/src/test/java/org/
directmemory/trunk/serializers/kryo/src/test/java/org/apache/
directmemory/trunk/serializers/kryo/src/test/java/org/apache/directmemory/
directmemory/trunk/serializers/kryo/src/test/java/org/apache/directmemory/serialization/
directmemory/trunk/serializers/kryo/src/test/java/org/apache/directmemory/serialization/kryo/
directmemory/trunk/serializers/kryo/src/test/java/org/apache/directmemory/serialization/kryo/KryoSerializerTest.java
(with props)
Modified:
directmemory/trunk/pom.xml
Modified: directmemory/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/directmemory/trunk/pom.xml?rev=1392328&r1=1392327&r2=1392328&view=diff
==============================================================================
--- directmemory/trunk/pom.xml (original)
+++ directmemory/trunk/pom.xml Mon Oct 1 13:47:41 2012
@@ -158,6 +158,10 @@ under the License.
<name>Daniel Manzke</name>
<email>daniel dot manzke at googlemail dot com</email>
</contributor>
+ <contributor>
+ <name>Min Zhou</name>
+ <email>coderplay at gmail dot com</email>
+ </contributor>
</contributors>
<mailingLists>
@@ -266,6 +270,7 @@ under the License.
<slf4j.version>1.6.4</slf4j.version>
<msgpack.version>0.6.5</msgpack.version>
<protobuf.version>2.4.1</protobuf.version>
+ <kryo.version>2.20</kryo.version>
<wagon.version>2.2</wagon.version>
<snakeyaml.version>1.10</snakeyaml.version>
@@ -686,6 +691,12 @@ under the License.
</dependency>
<dependency>
+ <groupId>com.esotericsoftware.kryo</groupId>
+ <artifactId>kryo</artifactId>
+ <version>${kryo.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>${protobuf.version}</version>
Added: directmemory/trunk/serializers/kryo/pom.xml
URL:
http://svn.apache.org/viewvc/directmemory/trunk/serializers/kryo/pom.xml?rev=1392328&view=auto
==============================================================================
--- directmemory/trunk/serializers/kryo/pom.xml (added)
+++ directmemory/trunk/serializers/kryo/pom.xml Mon Oct 1 13:47:41 2012
@@ -0,0 +1,77 @@
+<?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.
+-->
+<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/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.directmemory</groupId>
+ <artifactId>directmemory-serializers</artifactId>
+ <version>0.2-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>directmemory-kryo</artifactId>
+ <name>Apache DirectMemory :: Serializers :: Kryo</name>
+ <packaging>bundle</packaging>
+ <description>Kryo serializer adapter for DirectMemory Cache</description>
+
+ <!-- TODO need the help of some OSGi expert here -->
+ <properties>
+ <osgi.import>
+ !org.apache.directmemory*,
+ com.esotericsoftware.kryo*;version=${kryo.version},
+ com.google.common.base,
+ com.google.common.collect,
+ org.aspectj.lang,
+ org.aspectj.lang.annotation,
+ org.aspectj.runtime.internal,
+ org.slf4j;resolution:=optional,
+ sun.misc.*
+ </osgi.import>
+
<osgi.export>org.apache.directmemory.serialization.kryo*;version="${project.version}</osgi.export>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>${project.parent.groupId}</groupId>
+ <artifactId>directmemory-cache</artifactId>
+ <version>${project.parent.version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.esotericsoftware.kryo</groupId>
+ <artifactId>kryo</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>${basedir}/src/main/resources</directory>
+ </resource>
+ </resources>
+ </build>
+
+</project>
Propchange: directmemory/trunk/serializers/kryo/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: directmemory/trunk/serializers/kryo/pom.xml
------------------------------------------------------------------------------
svn:keywords = Date Revision Author HeadURL Id
Propchange: directmemory/trunk/serializers/kryo/pom.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml
Added:
directmemory/trunk/serializers/kryo/src/main/java/org/apache/directmemory/serialization/kryo/KryoSerializer.java
URL:
http://svn.apache.org/viewvc/directmemory/trunk/serializers/kryo/src/main/java/org/apache/directmemory/serialization/kryo/KryoSerializer.java?rev=1392328&view=auto
==============================================================================
---
directmemory/trunk/serializers/kryo/src/main/java/org/apache/directmemory/serialization/kryo/KryoSerializer.java
(added)
+++
directmemory/trunk/serializers/kryo/src/main/java/org/apache/directmemory/serialization/kryo/KryoSerializer.java
Mon Oct 1 13:47:41 2012
@@ -0,0 +1,79 @@
+package org.apache.directmemory.serialization.kryo;
+
+/*
+ * 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.
+ */
+
+import org.apache.directmemory.serialization.Serializer;
+import com.esotericsoftware.kryo.Kryo;
+import com.esotericsoftware.kryo.io.Input;
+import com.esotericsoftware.kryo.io.Output;
+
+import java.io.IOException;
+
+public final class KryoSerializer
+ implements Serializer
+{
+ /* buffer size */
+ private static final int BUFFER_SIZE = 1024;
+
+ private final Kryo kryo;
+ private final byte[] buffer = new byte[ BUFFER_SIZE ];
+ private final Output output = new Output( buffer, -1 );
+ private final Input input = new Input( buffer );
+
+ public KryoSerializer()
+ {
+ kryo = new Kryo();
+ kryo.setReferences( false );
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public <T> byte[] serialize( T obj )
+ throws IOException
+ {
+ Class<?> clazz = obj.getClass();
+
+ checkRegiterNeeded( clazz );
+
+ output.setBuffer( buffer, -1 );
+ kryo.writeObject( output, obj );
+ return output.toBytes();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public <T> T deserialize( byte[] source, Class<T> clazz )
+ throws IOException, ClassNotFoundException, InstantiationException,
IllegalAccessException
+ {
+ checkRegiterNeeded( clazz );
+ input.setBuffer( source);
+ return kryo.readObject(input, clazz);
+ }
+
+ private void checkRegiterNeeded( Class<?> clazz )
+ {
+ kryo.register( clazz );
+ }
+
+}
Propchange:
directmemory/trunk/serializers/kryo/src/main/java/org/apache/directmemory/serialization/kryo/KryoSerializer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
directmemory/trunk/serializers/kryo/src/main/java/org/apache/directmemory/serialization/kryo/KryoSerializer.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
directmemory/trunk/serializers/kryo/src/main/java/org/apache/directmemory/serialization/kryo/KryoSerializer.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
directmemory/trunk/serializers/kryo/src/main/java/org/apache/directmemory/serialization/kryo/package-info.java
URL:
http://svn.apache.org/viewvc/directmemory/trunk/serializers/kryo/src/main/java/org/apache/directmemory/serialization/kryo/package-info.java?rev=1392328&view=auto
==============================================================================
---
directmemory/trunk/serializers/kryo/src/main/java/org/apache/directmemory/serialization/kryo/package-info.java
(added)
+++
directmemory/trunk/serializers/kryo/src/main/java/org/apache/directmemory/serialization/kryo/package-info.java
Mon Oct 1 13:47:41 2012
@@ -0,0 +1,23 @@
+/**
+ * Kryo Serializer adapter.
+ */
+package org.apache.directmemory.serialization.kryo;
+
+/*
+ * 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.
+ */
Propchange:
directmemory/trunk/serializers/kryo/src/main/java/org/apache/directmemory/serialization/kryo/package-info.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
directmemory/trunk/serializers/kryo/src/main/java/org/apache/directmemory/serialization/kryo/package-info.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
directmemory/trunk/serializers/kryo/src/main/java/org/apache/directmemory/serialization/kryo/package-info.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Added:
directmemory/trunk/serializers/kryo/src/main/resources/META-INF/services/org.apache.directmemory.serialization.Serializer
URL:
http://svn.apache.org/viewvc/directmemory/trunk/serializers/kryo/src/main/resources/META-INF/services/org.apache.directmemory.serialization.Serializer?rev=1392328&view=auto
==============================================================================
---
directmemory/trunk/serializers/kryo/src/main/resources/META-INF/services/org.apache.directmemory.serialization.Serializer
(added)
+++
directmemory/trunk/serializers/kryo/src/main/resources/META-INF/services/org.apache.directmemory.serialization.Serializer
Mon Oct 1 13:47:41 2012
@@ -0,0 +1,18 @@
+ # 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.
+
+org.apache.directmemory.serialization.kryo.KryoSerializer
Added:
directmemory/trunk/serializers/kryo/src/test/java/org/apache/directmemory/serialization/kryo/KryoSerializerTest.java
URL:
http://svn.apache.org/viewvc/directmemory/trunk/serializers/kryo/src/test/java/org/apache/directmemory/serialization/kryo/KryoSerializerTest.java?rev=1392328&view=auto
==============================================================================
---
directmemory/trunk/serializers/kryo/src/test/java/org/apache/directmemory/serialization/kryo/KryoSerializerTest.java
(added)
+++
directmemory/trunk/serializers/kryo/src/test/java/org/apache/directmemory/serialization/kryo/KryoSerializerTest.java
Mon Oct 1 13:47:41 2012
@@ -0,0 +1,36 @@
+package org.apache.directmemory.serialization.kryo;
+/*
+ * 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.
+ */
+
+import org.apache.directmemory.test.AbstractSerializerTest;
+
+/**
+ *
+ */
+public class KryoSerializerTest
+ extends AbstractSerializerTest
+{
+
+ @Override
+ public String getSerializerClassName()
+ {
+ return KryoSerializer.class.getName();
+ }
+
+}
Propchange:
directmemory/trunk/serializers/kryo/src/test/java/org/apache/directmemory/serialization/kryo/KryoSerializerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
directmemory/trunk/serializers/kryo/src/test/java/org/apache/directmemory/serialization/kryo/KryoSerializerTest.java
------------------------------------------------------------------------------
svn:keywords = Date Author Id Revision HeadURL
Propchange:
directmemory/trunk/serializers/kryo/src/test/java/org/apache/directmemory/serialization/kryo/KryoSerializerTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain