dlmarion commented on code in PR #3482:
URL: https://github.com/apache/accumulo/pull/3482#discussion_r1227249615
##########
core/src/main/java/org/apache/accumulo/core/metadata/TServerInstance.java:
##########
@@ -34,56 +36,74 @@
*/
public class TServerInstance implements Comparable<TServerInstance> {
+ private static final String FORMAT = "%s#%s#%s";
+
private final HostAndPort hostAndPort;
private final String hostPort;
private final String session;
- private final String hostPortSession;
+ private final String hostPortSessionGroup;
+ private final String group;
+
+ public static TServerInstance fromString(String val) {
+ Objects.requireNonNull(val, "String value for TServerInstance cannot be
null");
+ String[] parts = val.split("#");
+ if (parts.length != 3) {
+ // could throw IllegalArgumentException, but IllegalStateException is
something
+ // that is already expected in a large portion of the codebase.
+ throw new IllegalStateException(
+ "Supplied TServerInstance string: " + val + " does not follow
format: " + FORMAT);
+ }
+ return new TServerInstance(parts[0], parts[1], parts[2]);
+ }
- public TServerInstance(HostAndPort address, String session) {
+ public TServerInstance(HostAndPort address, String session, String group) {
this.hostAndPort = address;
this.session = session;
this.hostPort = hostAndPort.toString();
- this.hostPortSession = hostPort + "[" + session + "]";
+ this.group = group;
+ this.hostPortSessionGroup = String.format(FORMAT, hostPort, session,
group);
}
- public TServerInstance(String formattedString) {
- int pos = formattedString.indexOf("[");
- if (pos < 0 || !formattedString.endsWith("]")) {
- throw new IllegalArgumentException(formattedString);
- }
- this.hostAndPort = HostAndPort.fromString(formattedString.substring(0,
pos));
- this.session = formattedString.substring(pos + 1, formattedString.length()
- 1);
- this.hostPort = hostAndPort.toString();
- this.hostPortSession = hostPort + "[" + session + "]";
+ public TServerInstance(String address, String session, String group) {
+ this(AddressUtil.parseAddress(address, false), session, group);
}
- public TServerInstance(HostAndPort address, long session) {
- this(address, Long.toHexString(session));
+ public TServerInstance(HostAndPort address, long session, String group) {
+ this(address, Long.toHexString(session), group);
}
- public TServerInstance(String address, long session) {
- this(AddressUtil.parseAddress(address, false), Long.toHexString(session));
+ public TServerInstance(String address, long session, String group) {
+ this(AddressUtil.parseAddress(address, false), Long.toHexString(session),
group);
}
- public TServerInstance(Value address, Text session) {
- this(AddressUtil.parseAddress(new String(address.get(), UTF_8), false),
session.toString());
+ public TServerInstance(Value address, Text session, String group) {
+ this(AddressUtil.parseAddress(new String(address.get(), UTF_8), false),
session.toString(),
+ group);
}
@Override
public int compareTo(TServerInstance other) {
if (this == other) {
return 0;
}
- return this.getHostPortSession().compareTo(other.getHostPortSession());
+ return
this.getHostPortSessionGroup().compareTo(other.getHostPortSessionGroup());
}
@Override
public int hashCode() {
- return getHostPortSession().hashCode();
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((group == null) ? 0 : group.hashCode());
+ result =
+ prime * result + ((hostPortSessionGroup == null) ? 0 :
hostPortSessionGroup.hashCode());
+ return result;
}
@Override
public boolean equals(Object obj) {
+ if (obj == null) {
+ return false;
+ }
Review Comment:
Resolved in eeb38b5
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]