SAMZA-1304: Handling duplicate stream processor registration.
[samza.git] / samza-core / src / main / java / org / apache / samza / zk / ProcessorData.java
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 package org.apache.samza.zk;
21
22 import java.util.Objects;
23 import org.apache.samza.SamzaException;
24
25 /**
26 * Represents processor data stored in zookeeper processors node.
27 */
28 public class ProcessorData {
29 private final String processorId;
30 private final String host;
31
32 public ProcessorData(String host, String processorId) {
33 this.processorId = processorId;
34 this.host = host;
35 }
36
37 public ProcessorData(String data) {
38 String[] splt = data.split(" ");
39 if (splt.length != 2) {
40 throw new SamzaException("incorrect processor data format = " + data);
41 }
42 host = splt[0];
43 processorId = splt[1];
44 }
45
46 public String toString() {
47 return host + " " + processorId;
48 }
49
50 public String getHost() {
51 return host;
52 }
53
54 public String getProcessorId() {
55 return processorId;
56 }
57
58 @Override
59 public int hashCode() {
60 return Objects.hash(processorId, host);
61 }
62
63 @Override
64 public boolean equals(Object obj) {
65 if (obj == null) return false;
66 if (getClass() != obj.getClass()) return false;
67 final ProcessorData other = (ProcessorData) obj;
68 return Objects.equals(processorId, other.processorId) && Objects.equals(host, other.host);
69 }
70 }