Convert yanglib to OSGi DS
[netconf.git] / apps / netconf-topology / src / main / java / org / opendaylight / netconf / topology / spi / NetconfConnectorDTO.java
1 /*
2  * Copyright (c) 2020 PANTHEON.tech, 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.netconf.topology.spi;
9
10 import static java.util.Objects.requireNonNull;
11
12 import java.util.List;
13 import org.eclipse.jdt.annotation.NonNull;
14 import org.opendaylight.netconf.client.NetconfClientSessionListener;
15 import org.opendaylight.netconf.client.mdsal.NetconfDeviceCommunicator;
16 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceHandler;
17 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration;
18
19 final class NetconfConnectorDTO implements AutoCloseable {
20     private final @NonNull List<SchemaSourceRegistration<?>> yanglibRegistrations;
21     private final @NonNull NetconfDeviceCommunicator communicator;
22     private final @NonNull RemoteDeviceHandler facade;
23
24     NetconfConnectorDTO(final NetconfDeviceCommunicator communicator, final RemoteDeviceHandler facade,
25             final List<SchemaSourceRegistration<?>> yanglibRegistrations) {
26         this.communicator = requireNonNull(communicator);
27         this.facade = requireNonNull(facade);
28         this.yanglibRegistrations = List.copyOf(yanglibRegistrations);
29     }
30
31     NetconfDeviceCommunicator getCommunicator() {
32         return communicator;
33     }
34
35     NetconfClientSessionListener getSessionListener() {
36         return communicator;
37     }
38
39     @Override
40     public void close() {
41         communicator.close();
42         facade.close();
43         yanglibRegistrations.forEach(SchemaSourceRegistration::close);
44     }
45 }