4939cabfede90571c7897b426d6d5ee1122299a3
[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 java.util.List;
11 import org.opendaylight.netconf.client.NetconfClientSessionListener;
12 import org.opendaylight.netconf.client.mdsal.NetconfDeviceCommunicator;
13 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceHandler;
14 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceRegistration;
15
16 public final class NetconfConnectorDTO implements AutoCloseable {
17     private final List<SchemaSourceRegistration<?>> yanglibRegistrations;
18     private final NetconfDeviceCommunicator communicator;
19     private final RemoteDeviceHandler facade;
20
21     public NetconfConnectorDTO(final NetconfDeviceCommunicator communicator, final RemoteDeviceHandler facade,
22             final List<SchemaSourceRegistration<?>> yanglibRegistrations) {
23         this.communicator = communicator;
24         this.facade = facade;
25         this.yanglibRegistrations = yanglibRegistrations;
26     }
27
28     public NetconfDeviceCommunicator getCommunicator() {
29         return communicator;
30     }
31
32     public RemoteDeviceHandler getFacade() {
33         return facade;
34     }
35
36     public NetconfClientSessionListener getSessionListener() {
37         return communicator;
38     }
39
40     @Override
41     public void close() {
42         communicator.close();
43         facade.close();
44         yanglibRegistrations.forEach(SchemaSourceRegistration::close);
45     }
46 }