Factor out common RPC version downgrade code
@@ -376,10 +376,7 @@ abstract public class NodeInfo implements Comparable<NodeInfo> {
public boolean notifyNoSuchMethodError(String methodName, Timer timer) {
if (methodName.equals("getnodestate3")) {
if (version > 1) {
- log.log(LogLevel.DEBUG, "Node " + toString() + " does not support " + methodName + " call. Setting version to 1.");
- version = 1;
- nextAttemptTime = 0;
- adjustedVersionTime = timer.getCurrentTimeInMillis();
+ downgradeToRpcVersion(1, methodName, timer);
return true;
} else if (timer.getCurrentTimeInMillis() - 2000 < adjustedVersionTime) {
log.log(LogLevel.DEBUG, "Node " + toString() + " does not support " + methodName + " call. Version already at 1 and was recently adjusted, so ignoring it.");
@@ -387,10 +384,7 @@ abstract public class NodeInfo implements Comparable<NodeInfo> {
}
} else if (methodName.equals(RPCCommunicator.SET_DISTRIBUTION_STATES_RPC_METHOD_NAME)) {
if (version == RPCCommunicator.SET_DISTRIBUTION_STATES_RPC_VERSION) {
- log.log(LogLevel.DEBUG, () -> "Node " + toString() + " does not support " + methodName + " call. Downgrading version to 2 (setsystemstate2).");
- version = RPCCommunicator.LEGACY_SET_SYSTEM_STATE2_RPC_VERSION;
- nextAttemptTime = 0;
- adjustedVersionTime = timer.getCurrentTimeInMillis();
+ downgradeToRpcVersion(RPCCommunicator.LEGACY_SET_SYSTEM_STATE2_RPC_VERSION, methodName, timer);
return true;
} else if (timer.getCurrentTimeInMillis() - 2000 < adjustedVersionTime) {
log.log(LogLevel.DEBUG, () -> "Node " + toString() + " does not support " + methodName + " call. Version already downgraded, so ignoring it.");
@@ -398,10 +392,7 @@ abstract public class NodeInfo implements Comparable<NodeInfo> {
}
} else if (methodName.equals("getnodestate2") || methodName.equals(RPCCommunicator.LEGACY_SET_SYSTEM_STATE2_RPC_METHOD_NAME)) {
if (version > 0) {
- log.log(LogLevel.DEBUG, "Node " + toString() + " does not support " + methodName + " call. Setting version to 0.");
- version = 0;
- nextAttemptTime = 0;
- adjustedVersionTime = timer.getCurrentTimeInMillis();
+ downgradeToRpcVersion(0, methodName, timer);
return true;
} else if (timer.getCurrentTimeInMillis() - 2000 < adjustedVersionTime) {
log.log(LogLevel.DEBUG, "Node " + toString() + " does not support " + methodName + " call. Version already at 0 and was recently adjusted, so ignoring it.");
@@ -412,6 +403,14 @@ abstract public class NodeInfo implements Comparable<NodeInfo> {
return false;
}
+ private void downgradeToRpcVersion(int newVersion, String methodName, Timer timer) {
+ log.log(LogLevel.DEBUG, () -> String.format("Node %s does not support %s call. Downgrading to version %d.",
+ toString(), methodName, newVersion));
+ version = newVersion;
+ nextAttemptTime = 0;
+ adjustedVersionTime = timer.getCurrentTimeInMillis();
+ }
+
public Target getConnection() {
return connection;
}
