Bump odlparent to 5.0.0
[openflowplugin.git] / applications / forwardingrules-sync / src / main / java / org / opendaylight / openflowplugin / applications / frsync / util / FxChainUtil.java
1 /*
2  * Copyright (c) 2016 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.openflowplugin.applications.frsync.util;
10
11 import com.google.common.base.MoreObjects;
12 import com.google.common.collect.ImmutableList;
13 import com.google.common.util.concurrent.FutureCallback;
14 import java.util.Collection;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
16 import org.opendaylight.yangtools.yang.common.RpcError;
17 import org.opendaylight.yangtools.yang.common.RpcResult;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 /**
22  * Util methods for {@link com.google.common.util.concurrent.ListenableFuture} chaining.
23  */
24 public final class FxChainUtil {
25
26     private static final Logger LOG = LoggerFactory.getLogger(FxChainUtil.class);
27
28     private FxChainUtil() {
29         throw new IllegalStateException("This class should not be instantiated.");
30     }
31
32
33     public static FutureCallback<RpcResult<Void>> logResultCallback(final NodeId nodeId, final String prefix) {
34         return new FutureCallback<RpcResult<Void>>() {
35             @Override
36             public void onSuccess(final RpcResult<Void> result) {
37                 if (result != null) {
38                     if (result.isSuccessful()) {
39                         LOG.debug("{} finished successfully: {}", prefix, nodeId.getValue());
40                     } else {
41                         final Collection<RpcError> errors = MoreObjects.firstNonNull(result.getErrors(),
42                                 ImmutableList.of());
43                         LOG.debug("{} failed: {} -> {}", prefix, nodeId.getValue(), errors);
44                     }
45                 } else {
46                     LOG.debug("{} reconciliation failed: {} -> null result", prefix, nodeId.getValue());
47                 }
48             }
49
50             @Override
51             public void onFailure(final Throwable failure) {
52                 LOG.debug("{} reconciliation failed seriously: {}", prefix, nodeId.getValue(), failure);
53             }
54         };
55     }
56 }