1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.anyflow.lannister.serialization;
18
19 import java.util.function.Supplier;
20
21 import com.hazelcast.nio.serialization.Serializer;
22
23 public class HazelcastSerializer<T, S> implements Serializer, Supplier<S> {
24 protected final Class<T> type;
25 protected final int typeId;
26 protected final ThreadLocal<S> threadLocal;
27
28 protected HazelcastSerializer(final Class<T> type, int typeId) {
29 this(type, typeId, null);
30 }
31
32 protected HazelcastSerializer(final Class<T> type, int typeId, Supplier<? extends S> supplier) {
33 this.type = type;
34 this.typeId = typeId;
35 this.threadLocal = supplier != null ? ThreadLocal.withInitial(supplier) : null;
36 }
37
38 @Override
39 public int getTypeId() {
40 return typeId;
41 }
42
43 @Override
44 public void destroy() {
45
46 }
47
48 public Class<T> getType() {
49 return this.type;
50 }
51
52 @Override
53 public S get() {
54 return threadLocal.get();
55 }
56 }