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