1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.api.integration.dns;
import java.time.Duration;
import java.util.Comparator;
import java.util.Objects;
/**
* A basic representation of a DNS resource record, containing the record type, name and data.
*
* @author mpolden
*/
public record Record(Type type,
Duration ttl,
RecordName name,
RecordData data) implements Comparable<Record> {
private static final Comparator<Record> comparator = Comparator.comparing(Record::type)
.thenComparing(Record::name)
.thenComparing(Record::data);
public Record {
Objects.requireNonNull(type, "type cannot be null");
Objects.requireNonNull(ttl, "ttl cannot be null");
Objects.requireNonNull(name, "name cannot be null");
Objects.requireNonNull(data, "data cannot be null");
}
public Record(Type type, RecordName name, RecordData data) {
this(type, Duration.ofMinutes(5), name, data);
}
/** DNS type of this */
public Type type() {
return type;
}
/** The TTL value of this */
public Duration ttl() {
return ttl;
}
/** Data in this, e.g. IP address for records of type A */
public RecordData data() {
return data;
}
/** Name of this, e.g. a FQDN for records of type A */
public RecordName name() {
return name;
}
public enum Type {
A,
AAAA,
ALIAS,
CNAME,
DIRECT,
MX,
NS,
PTR,
SOA,
SRV,
TXT,
SPF,
NAPTR,
CAA,
}
@Override
public String toString() {
return String.format("%s %s -> %s [TTL: %s]", type, name, data, ttl);
}
@Override
public int compareTo(Record that) {
return comparator.compare(this, that);
}
}
|