import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
* <p>
* Then schedule next keepalive.
*/
- private void resetKeepalive() {
+ void resetKeepalive() {
LOG.trace("{}: Resetting netconf keepalive timer", id);
if (currentKeepalive != null) {
currentKeepalive.cancel(false);
currentDeviceRpc = null;
}
- private void reconnect() {
+ void reconnect() {
Preconditions.checkState(listener != null, "%s: Unable to reconnect, session listener is missing", id);
stopKeepalives();
LOG.info("{}: Reconnecting inactive netconf session", id);
if (previousKeepalive != null && !previousKeepalive.isDone()) {
onFailure(new IllegalStateException("Previous keepalive timed out"));
} else {
- Futures.addCallback(currentDeviceRpc.invokeRpc(PATH, KEEPALIVE_PAYLOAD), this);
+ Futures.addCallback(currentDeviceRpc.invokeRpc(PATH, KEEPALIVE_PAYLOAD), this,
+ MoreExecutors.directExecutor());
}
} catch (NullPointerException e) {
LOG.debug("{}: Skipping keepalive while reconnecting", id);
}
}
+ @SuppressFBWarnings(value = "RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE",
+ justification = "Unrecognised NullableDecl")
@Override
public void onSuccess(final DOMRpcResult result) {
+ // No matter what response we got, rpc-reply or rpc-error,
+ // we got it from device so the netconf session is OK
if (result != null && result.getResult() != null) {
LOG.debug("{}: Keepalive RPC successful with response: {}", id, result.getResult());
scheduleKeepalive();
+ } else if (result != null && !result.getErrors().isEmpty()) {
+ LOG.warn("{}: Keepalive RPC failed with error: {}", id, result.getErrors());
+ scheduleKeepalive();
} else {
- LOG.warn("{} Keepalive RPC returned null with response: {}. Reconnecting netconf session", id, result);
+ LOG.warn("{} Keepalive RPC returned null with response. Reconnecting netconf session", id);
reconnect();
}
}
public static final class KeepaliveDOMRpcService implements DOMRpcService {
private final DOMRpcService deviceRpc;
- private ResetKeepalive resetKeepaliveTask;
+ private final ResetKeepalive resetKeepaliveTask;
private final long defaultRequestTimeoutMillis;
private final ScheduledExecutorService executor;
final NormalizedNode<?, ?> input) {
final CheckedFuture<DOMRpcResult, DOMRpcException> domRpcResultDOMRpcExceptionCheckedFuture =
deviceRpc.invokeRpc(type, input);
- Futures.addCallback(domRpcResultDOMRpcExceptionCheckedFuture, resetKeepaliveTask);
+ Futures.addCallback(domRpcResultDOMRpcExceptionCheckedFuture, resetKeepaliveTask,
+ MoreExecutors.directExecutor());
final RequestTimeoutTask timeoutTask = new RequestTimeoutTask(domRpcResultDOMRpcExceptionCheckedFuture);
executor.schedule(timeoutTask, defaultRequestTimeoutMillis, TimeUnit.MILLISECONDS);