Remove redundant code constructs
[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
9 package org.opendaylight.netconf.sal.connect.netconf.util;
10
11 import com.google.common.util.concurrent.FutureCallback;
12 import javax.annotation.Nonnull;
13 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
14 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
17
18 /**
19  * Simple Netconf RPC logging callback.
20  */
21 public class NetconfRpcFutureCallback implements FutureCallback<DOMRpcResult> {
22     private static final Logger LOG  = LoggerFactory.getLogger(NetconfRpcFutureCallback.class);
23
24     private final String type;
25     private final RemoteDeviceId id;
26
27     public NetconfRpcFutureCallback(final String prefix, final RemoteDeviceId id) {
28         this.type = prefix;
29         this.id = id;
30     }
31
32     @Override
33     public void onSuccess(@Nonnull final DOMRpcResult result) {
34         if (result.getErrors().isEmpty()) {
35             LOG.trace("{}: {} invoked successfully", id, type);
36         } else {
37             onUnsuccess(result);
38         }
39     }
40
41     protected void onUnsuccess(final DOMRpcResult result) {
42         LOG.warn("{}: {} invoked unsuccessfully: {}", id, type, result.getErrors());
43     }
44
45     @Override
46     public void onFailure(final Throwable throwable) {
47         LOG.warn("{}: {} failed.", id, type, throwable);
48     }
49 }