Remove redundant type specifiers
[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 javax.annotation.Nullable;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
17 import org.opendaylight.yangtools.yang.common.RpcError;
18 import org.opendaylight.yangtools.yang.common.RpcResult;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
21
22 /**
23  * Util methods for {@link com.google.common.util.concurrent.ListenableFuture} chaining.
24  */
25 public final class FxChainUtil {
26
27     private static final Logger LOG = LoggerFactory.getLogger(FxChainUtil.class);
28
29     private FxChainUtil() {
30         throw new IllegalStateException("This class should not be instantiated.");
31     }
32
33
34     public static FutureCallback<RpcResult<Void>> logResultCallback(final NodeId nodeId, final String prefix) {
35         return new FutureCallback<RpcResult<Void>>() {
36             @Override
37             public void onSuccess(@Nullable final RpcResult<Void> result) {
38                 if (result != null) {
39                     if (result.isSuccessful()) {
40                         LOG.debug("{} finished successfully: {}", prefix, nodeId.getValue());
41                     } else {
42                         final Collection<RpcError> errors = MoreObjects.firstNonNull(result.getErrors(),
43                                 ImmutableList.of());
44                         LOG.debug("{} failed: {} -> {}", prefix, nodeId.getValue(), errors);
45                     }
46                 } else {
47                     LOG.debug("{} reconciliation failed: {} -> null result", prefix, nodeId.getValue());
48                 }
49             }
50
51             @Override
52             public void onFailure(final Throwable failure) {
53                 LOG.debug("{} reconciliation failed seriously: {}", prefix, nodeId.getValue(), failure);
54             }
55         };
56     }
57 }