Decompose RPC implementation classes
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / sal / RemoveMeterImpl.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  * Copyright (c) 2024 PANTHEON.tech, s.r.o.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9 package org.opendaylight.openflowplugin.impl.services.sal;
10
11 import com.google.common.util.concurrent.FutureCallback;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import com.google.common.util.concurrent.MoreExecutors;
15 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
16 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
17 import org.opendaylight.openflowplugin.impl.util.ErrorUtil;
18 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeter;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutput;
22 import org.opendaylight.yangtools.yang.common.RpcResult;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25
26 public final class RemoveMeterImpl extends AbstractMeterRpc<RemoveMeterInput, RemoveMeterOutput>
27         implements RemoveMeter {
28     private static final Logger LOG = LoggerFactory.getLogger(RemoveMeterImpl.class);
29
30     public RemoveMeterImpl(final RequestContextStack requestContextStack, final DeviceContext deviceContext,
31             final ConvertorExecutor convertorExecutor) {
32         super(requestContextStack, deviceContext, convertorExecutor, RemoveMeterOutput.class);
33     }
34
35     @Override
36     public ListenableFuture<RpcResult<RemoveMeterOutput>> invoke(final RemoveMeterInput input) {
37         final var resultFuture = single.canUseSingleLayerSerialization() ? single.handleServiceCall(input)
38             : multi.handleServiceCall(input);
39
40         Futures.addCallback(resultFuture, new FutureCallback<>() {
41             @Override
42             public void onSuccess(final RpcResult<RemoveMeterOutput> result) {
43                 if (result.isSuccessful()) {
44                     if (LOG.isDebugEnabled()) {
45                         LOG.debug("Meter remove with id={} finished without error", input.getMeterId());
46                     }
47                 } else {
48                     LOG.warn("Meter remove with id={} failed, errors={}", input.getMeterId(),
49                         ErrorUtil.errorsToString(result.getErrors()));
50                     LOG.debug("Meter input={}", input);
51                 }
52             }
53
54             @Override
55             public void onFailure(final Throwable throwable) {
56                 LOG.warn("Service call for removing meter={} failed", input.getMeterId(), throwable);
57             }
58         }, MoreExecutors.directExecutor());
59         return resultFuture;
60     }
61 }