Remove javax.annotation nullness annotations
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / util / NetconfRpcFutureCallback.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netconf.sal.connect.netconf.util;
9
10 import com.google.common.util.concurrent.FutureCallback;
11 import org.opendaylight.mdsal.dom.api.DOMRpcResult;
12 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15
16 /**
17  * Simple Netconf RPC logging callback.
18  */
19 public class NetconfRpcFutureCallback implements FutureCallback<DOMRpcResult> {
20     private static final Logger LOG  = LoggerFactory.getLogger(NetconfRpcFutureCallback.class);
21
22     private final String type;
23     private final RemoteDeviceId id;
24
25     public NetconfRpcFutureCallback(final String prefix, final RemoteDeviceId id) {
26         this.type = prefix;
27         this.id = id;
28     }
29
30     @Override
31     public void onSuccess(final DOMRpcResult result) {
32         if (result.getErrors().isEmpty()) {
33             LOG.trace("{}: {} invoked successfully", id, type);
34         } else {
35             onUnsuccess(result);
36         }
37     }
38
39     protected void onUnsuccess(final DOMRpcResult result) {
40         LOG.warn("{}: {} invoked unsuccessfully: {}", id, type, result.getErrors());
41     }
42
43     @Override
44     public void onFailure(final Throwable throwable) {
45         LOG.warn("{}: {} failed.", id, type, throwable);
46     }
47 }