| 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 pubsub.models; |
| 21 |
|
| 22 |
import java.util.Objects; |
| 23 |
import java.util.UUID; |
| 24 |
import org.apache.curator.x.async.modeled.NodeName; |
| 25 |
|
| 26 |
public class Instance implements NodeName { |
| 27 |
private final String id; |
| 28 |
private final InstanceType type; |
| 29 |
private final String hostname; |
| 30 |
private final int port; |
| 31 |
|
| 32 |
public Instance() { |
| 33 |
this(UUID.randomUUID().toString(), InstanceType.proxy, "", 0); |
| 34 |
} |
| 35 |
|
| 36 |
public Instance(String id, InstanceType type, String hostname, int port) { |
| 37 |
this.id = Objects.requireNonNull(id, "id cannot be null"); |
| 38 |
this.type = Objects.requireNonNull(type, "type cannot be null"); |
| 39 |
this.hostname = Objects.requireNonNull(hostname, "hostname cannot be null"); |
| 40 |
this.port = port; |
| 41 |
} |
| 42 |
|
| 43 |
public String getId() { |
| 44 |
return id; |
| 45 |
} |
| 46 |
|
| 47 |
public InstanceType getType() { |
| 48 |
return type; |
| 49 |
} |
| 50 |
|
| 51 |
public String getHostname() { |
| 52 |
return hostname; |
| 53 |
} |
| 54 |
|
| 55 |
public int getPort() { |
| 56 |
return port; |
| 57 |
} |
| 58 |
|
| 59 |
@Override |
| 60 |
public String nodeName() { |
| 61 |
return id; |
| 62 |
} |
| 63 |
|
| 64 |
@Override |
| 65 |
public String toString() { |
| 66 |
return "Instance{" + "id='" + id + '\'' + ", type=" + type + ", hostname='" + hostname + '\'' + ", port=" + port |
| 67 |
+ '}'; |
| 68 |
} |
| 69 |
} |