|
1 | 1 | package org.rocstreaming.roctoolkit; |
2 | 2 |
|
| 3 | +import lombok.Builder; |
| 4 | +import lombok.EqualsAndHashCode; |
| 5 | +import lombok.Getter; |
| 6 | + |
3 | 7 | /** |
4 | 8 | * Network endpoint. |
5 | 9 | * <p> |
|
45 | 49 | * <p> |
46 | 50 | * Can't be used concurrently |
47 | 51 | */ |
| 52 | +@Getter |
| 53 | +@Builder(builderClassName = "Builder", toBuilder = true) |
| 54 | +@EqualsAndHashCode |
48 | 55 | public class Endpoint { |
49 | 56 |
|
50 | 57 | static { |
51 | 58 | RocLibrary.loadLibrary(); |
52 | 59 | } |
53 | 60 |
|
| 61 | + /** |
| 62 | + * Protocol |
| 63 | + */ |
54 | 64 | private Protocol protocol; |
55 | 65 |
|
| 66 | + /** |
| 67 | + * Host specifies FQDN, IPv4 address, or IPv6 address |
| 68 | + */ |
56 | 69 | private String host; |
57 | 70 |
|
| 71 | + /** |
| 72 | + * Port specifies UDP or TCP port in range [0; 65535] |
| 73 | + * <p> |
| 74 | + * When binding an endpoint, the port may be set to zero to select a random port. |
| 75 | + * The selected port will be then written back to the endpoint. When connecting |
| 76 | + * an endpoint, the port should be positive. |
| 77 | + * <p> |
| 78 | + * If port is set to -1, the standard port for endpoint protocol is used. This is |
| 79 | + * allowed only if the protocol defines its standard port. |
| 80 | + */ |
58 | 81 | private int port; |
59 | 82 |
|
| 83 | + /** |
| 84 | + * Resource nullable. Specifies percent-encoded path and query |
| 85 | + */ |
60 | 86 | private String resource; |
61 | 87 |
|
62 | 88 | /** |
@@ -109,81 +135,6 @@ public Endpoint(Protocol protocol, String host, int port) { |
109 | 135 | this(protocol, host, port, null); |
110 | 136 | } |
111 | 137 |
|
112 | | - /** |
113 | | - * Builder class for {@link Endpoint} |
114 | | - */ |
115 | | - public static class Builder { |
116 | | - |
117 | | - private Protocol protocol; |
118 | | - |
119 | | - private String host; |
120 | | - |
121 | | - private int port; |
122 | | - |
123 | | - private String resource; |
124 | | - |
125 | | - /** |
126 | | - * Set protocol |
127 | | - * @param protocol protocol |
128 | | - * @return this Builder |
129 | | - */ |
130 | | - public Builder setProtocol(Protocol protocol) { |
131 | | - this.protocol = protocol; |
132 | | - return this; |
133 | | - } |
134 | | - |
135 | | - |
136 | | - /** |
137 | | - * Set host |
138 | | - * @param host host |
139 | | - * @return this Builder |
140 | | - */ |
141 | | - public Builder setHost(String host) { |
142 | | - this.host = host; |
143 | | - return this; |
144 | | - } |
145 | | - |
146 | | - /** |
147 | | - * Set port |
148 | | - * @param port port |
149 | | - * @return this Builder |
150 | | - */ |
151 | | - public Builder setPort(int port) { |
152 | | - this.port = port; |
153 | | - return this; |
154 | | - } |
155 | | - |
156 | | - /** |
157 | | - * Set resource |
158 | | - * @param resource resource |
159 | | - * @return this Builder |
160 | | - */ |
161 | | - public Builder setResource(String resource) { |
162 | | - this.resource = resource; |
163 | | - return this; |
164 | | - } |
165 | | - |
166 | | - public Endpoint build() { |
167 | | - return new Endpoint(this.protocol, this.host, this.port, this.resource); |
168 | | - } |
169 | | - } |
170 | | - |
171 | | - public Protocol getProtocol() { |
172 | | - return protocol; |
173 | | - } |
174 | | - |
175 | | - public String getHost() { |
176 | | - return host; |
177 | | - } |
178 | | - |
179 | | - public int getPort() { |
180 | | - return port; |
181 | | - } |
182 | | - |
183 | | - public String getResource() { |
184 | | - return resource; |
185 | | - } |
186 | | - |
187 | 138 | @Override |
188 | 139 | public String toString() { |
189 | 140 | return getUri(); |
|
0 commit comments