-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from alparslanavci/custom-serialization-support
Added support for all serialization methods in Hazelcast
- Loading branch information
Showing
12 changed files
with
159 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
tomcat-core/src/test/java/com/hazelcast/session/CustomAttribute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) 2008-2019, Hazelcast, Inc. All Rights Reserved. | ||
*/ | ||
|
||
package com.hazelcast.session; | ||
|
||
public class CustomAttribute { | ||
private String value; | ||
|
||
//Needed for Kryo | ||
public CustomAttribute() { | ||
} | ||
|
||
public CustomAttribute(String value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "CustomAttribute{" + "value='" + value + '\'' + '}'; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
tomcat-core/src/test/java/com/hazelcast/session/HazelcastGlobalKryoSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.hazelcast.session; | ||
|
||
import com.esotericsoftware.kryo.Kryo; | ||
import com.esotericsoftware.kryo.io.InputChunked; | ||
import com.esotericsoftware.kryo.io.OutputChunked; | ||
import com.hazelcast.nio.ObjectDataInput; | ||
import com.hazelcast.nio.ObjectDataOutput; | ||
import com.hazelcast.nio.serialization.StreamSerializer; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
public class HazelcastGlobalKryoSerializer | ||
implements StreamSerializer { | ||
|
||
private final ThreadLocal<Kryo> kryoThreadLocal = new ThreadLocal<Kryo>() { | ||
@Override | ||
protected Kryo initialValue() { | ||
Kryo kryo = new Kryo(); | ||
kryo.register(CustomAttribute.class); | ||
return kryo; | ||
} | ||
}; | ||
|
||
@Override | ||
public int getTypeId() { | ||
return 123; | ||
} | ||
|
||
@Override | ||
public void write(ObjectDataOutput objectDataOutput, Object object) | ||
throws IOException { | ||
OutputChunked output = new OutputChunked((OutputStream) objectDataOutput, 4096); | ||
kryoThreadLocal.get().writeClassAndObject(output, object); | ||
output.endChunk(); | ||
output.flush(); | ||
} | ||
|
||
@Override | ||
public Object read(ObjectDataInput objectDataInput) | ||
throws IOException { | ||
InputStream in = (InputStream) objectDataInput; | ||
InputChunked input = new InputChunked(in, 4096); | ||
return kryoThreadLocal.get().readClassAndObject(input); | ||
} | ||
|
||
@Override | ||
public void destroy() { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
tomcat-core/src/test/resources/hazelcast-client-default.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Copyright (c) 2008-2019, Hazelcast, Inc. All Rights Reserved. | ||
~ | ||
~ Licensed 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. | ||
--> | ||
|
||
<!--suppress XmlDefaultAttributeValue --> | ||
<hazelcast-client xmlns="http://www.hazelcast.com/schema/client-config" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.hazelcast.com/schema/client-config | ||
http://www.hazelcast.com/schema/client-config/hazelcast-client-config-3.11.xsd"> | ||
|
||
<serialization> | ||
<serializers> | ||
<global-serializer>com.hazelcast.session.HazelcastGlobalKryoSerializer</global-serializer> | ||
</serializers> | ||
</serialization> | ||
|
||
</hazelcast-client> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters