Open Kilda Java Documentation
EndpointAddress.java
Go to the documentation of this file.
1 /* Copyright 2018 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.testing.service.traffexam.model;
17 
18 import com.fasterxml.jackson.annotation.JsonCreator;
19 import com.fasterxml.jackson.annotation.JsonProperty;
20 
21 import java.io.Serializable;
22 import java.net.Inet4Address;
23 import java.net.UnknownHostException;
24 import java.util.InputMismatchException;
25 
26 public final class EndpointAddress implements Serializable {
27  public final Inet4Address address;
28  public final int port;
29 
30  public EndpointAddress(Inet4Address address, int port) {
31  this.address = address;
32  this.port = port;
33  }
34 
35  @JsonCreator
37  @JsonProperty("address") String address,
38  @JsonProperty("port") int port) {
39  try {
40  this.address = (Inet4Address) Inet4Address.getByName(address);
41  } catch (UnknownHostException e) {
42  throw new InputMismatchException(String.format("Invalid value for \"address\" property: %s", address));
43  }
44  this.port = port;
45  }
46 }
EndpointAddress( @JsonProperty("address") String address, @JsonProperty("port") int port)