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