d5d472a57bb0df441d9275fe6eaa529428032849
[controller.git] / opendaylight / md-sal / sal-dom-compat / src / main / java / org / opendaylight / controller / sal / core / compat / RpcAvailabilityListenerAdapter.java
1 /*
2  * Copyright (c) 2018 Pantheon Technologies, s.r.o. 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 package org.opendaylight.controller.sal.core.compat;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.collect.ForwardingObject;
13 import java.util.Collection;
14 import java.util.stream.Collectors;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.opendaylight.controller.md.sal.dom.api.DOMRpcAvailabilityListener;
17 import org.opendaylight.controller.md.sal.dom.api.DOMRpcIdentifier;
18
19 @Deprecated
20 public class RpcAvailabilityListenerAdapter<T extends DOMRpcAvailabilityListener> extends ForwardingObject
21         implements org.opendaylight.mdsal.dom.api.DOMRpcAvailabilityListener {
22     private final @NonNull T delegate;
23
24     public RpcAvailabilityListenerAdapter(final T delegate) {
25         this.delegate = requireNonNull(delegate);
26     }
27
28     @Override
29     public void onRpcAvailable(final Collection<org.opendaylight.mdsal.dom.api.DOMRpcIdentifier> rpcs) {
30         delegate.onRpcAvailable(convert(rpcs));
31     }
32
33     @Override
34     public void onRpcUnavailable(final Collection<org.opendaylight.mdsal.dom.api.DOMRpcIdentifier> rpcs) {
35         delegate.onRpcUnavailable(convert(rpcs));
36     }
37
38     @Override
39     protected T delegate() {
40         return delegate;
41     }
42
43     private static @NonNull Collection<DOMRpcIdentifier> convert(
44             final Collection<org.opendaylight.mdsal.dom.api.DOMRpcIdentifier> from) {
45         return from.stream().map(RpcAvailabilityListenerAdapter::convert).collect(Collectors.toList());
46     }
47
48     private static @NonNull DOMRpcIdentifier convert(final org.opendaylight.mdsal.dom.api.DOMRpcIdentifier from) {
49         return DOMRpcIdentifier.create(from.getType(), from.getContextReference());
50     }
51 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.