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.topic;
18  
19  import java.io.IOException;
20  
21  import com.fasterxml.jackson.annotation.JsonIgnore;
22  import com.fasterxml.jackson.annotation.JsonProperty;
23  import com.hazelcast.nio.ObjectDataInput;
24  import com.hazelcast.nio.ObjectDataOutput;
25  
26  import net.anyflow.lannister.serialization.SerializableFactory;
27  
28  public class TopicSubscriber implements com.hazelcast.nio.serialization.IdentifiedDataSerializable {
29  	public static final TopicSubscribers NEXUS = new TopicSubscribers();
30  	public static final int ID = 7;
31  	@JsonProperty
32  	private String clientId;
33  	@JsonProperty
34  	private String topicName;
35  
36  	public TopicSubscriber() { // just for Serialization
37  	}
38  
39  	public TopicSubscriber(String clientId, String topicName) {
40  		this.clientId = clientId;
41  		this.topicName = topicName;
42  	}
43  
44  	public String key() {
45  		return TopicSubscribers.key(topicName, clientId);
46  	}
47  
48  	public String clientId() {
49  		return clientId;
50  	}
51  
52  	public String topicName() {
53  		return topicName;
54  	}
55  
56  	@JsonIgnore
57  	@Override
58  	public int getFactoryId() {
59  		return SerializableFactory.ID;
60  	}
61  
62  	@JsonIgnore
63  	@Override
64  	public int getId() {
65  		return ID;
66  	}
67  
68  	@Override
69  	public void writeData(ObjectDataOutput out) throws IOException {
70  		out.writeUTF(topicName);
71  		out.writeUTF(clientId);
72  	}
73  
74  	@Override
75  	public void readData(ObjectDataInput in) throws IOException {
76  		topicName = in.readUTF();
77  		clientId = in.readUTF();
78  	}
79  
80  	@Override
81  	public String toString() {
82  		return new StringBuilder().append("clientId=").append(clientId).append(", topicName=").append(topicName)
83  				.toString();
84  	}
85  }