View Javadoc
1   /*
2    * Copyright 2016 The Lannister Project
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package net.anyflow.lannister.serialization;
18  
19  import com.hazelcast.nio.serialization.DataSerializableFactory;
20  import com.hazelcast.nio.serialization.IdentifiedDataSerializable;
21  
22  import net.anyflow.lannister.cluster.SerializableIntegerSet;
23  import net.anyflow.lannister.cluster.SerializableStringSet;
24  import net.anyflow.lannister.message.InboundMessageStatus;
25  import net.anyflow.lannister.message.Message;
26  import net.anyflow.lannister.message.OutboundMessageStatus;
27  import net.anyflow.lannister.session.Session;
28  import net.anyflow.lannister.topic.Notification;
29  import net.anyflow.lannister.topic.Topic;
30  import net.anyflow.lannister.topic.TopicSubscriber;
31  import net.anyflow.lannister.topic.TopicSubscription;
32  
33  public class SerializableFactory implements DataSerializableFactory {
34  	public static final int ID = 1;
35  
36  	@Override
37  	public IdentifiedDataSerializable create(int classId) {
38  		switch (classId) {
39  		case Message.ID:
40  			return new Message();
41  
42  		case InboundMessageStatus.ID:
43  			return new InboundMessageStatus();
44  
45  		case OutboundMessageStatus.ID:
46  			return new OutboundMessageStatus();
47  
48  		case Session.ID:
49  			return new Session();
50  
51  		case Notification.ID:
52  			return new Notification();
53  
54  		case Topic.ID:
55  			return new Topic();
56  
57  		case TopicSubscriber.ID:
58  			return new TopicSubscriber();
59  
60  		case TopicSubscription.ID:
61  			return new TopicSubscription();
62  
63  		case SerializableStringSet.ID:
64  			return new SerializableStringSet();
65  
66  		case SerializableIntegerSet.ID:
67  			return new SerializableIntegerSet();
68  
69  		default:
70  			throw new Error("Invalid class ID of Hazelcast Serialization [ID=" + classId + "]");
71  		}
72  	}
73  }