Attempt netconf remount regardless of error-type
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / NetconfDeviceBuilder.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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
9 package org.opendaylight.netconf.sal.connect.netconf;
10
11 import com.google.common.base.Preconditions;
12 import com.google.common.util.concurrent.ListeningExecutorService;
13 import io.netty.util.concurrent.EventExecutor;
14 import org.opendaylight.netconf.sal.connect.api.DeviceActionFactory;
15 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
16 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
17 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.optional.rev190614.NetconfNodeAugmentedOptional;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
20
21 public class NetconfDeviceBuilder {
22
23     private boolean reconnectOnSchemasChange;
24     private NetconfDevice.SchemaResourcesDTO schemaResourcesDTO;
25     private RemoteDeviceId id;
26     private RemoteDeviceHandler<NetconfSessionPreferences> salFacade;
27     private ListeningExecutorService globalProcessingExecutor;
28     private DeviceActionFactory deviceActionFactory;
29     private NetconfNode node;
30     private EventExecutor eventExecutor;
31     private NetconfNodeAugmentedOptional nodeOptional;
32
33     public NetconfDeviceBuilder() {
34     }
35
36     public NetconfDeviceBuilder setReconnectOnSchemasChange(final boolean reconnectOnSchemasChange) {
37         this.reconnectOnSchemasChange = reconnectOnSchemasChange;
38         return this;
39     }
40
41     public NetconfDeviceBuilder setId(final RemoteDeviceId id) {
42         this.id = id;
43         return this;
44     }
45
46     public NetconfDeviceBuilder setSchemaResourcesDTO(final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO) {
47         this.schemaResourcesDTO = schemaResourcesDTO;
48         return this;
49     }
50
51     public NetconfDeviceBuilder setSalFacade(final RemoteDeviceHandler<NetconfSessionPreferences> salFacade) {
52         this.salFacade = salFacade;
53         return this;
54     }
55
56     public NetconfDeviceBuilder setGlobalProcessingExecutor(final ListeningExecutorService globalProcessingExecutor) {
57         this.globalProcessingExecutor = globalProcessingExecutor;
58         return this;
59     }
60
61     public NetconfDeviceBuilder setDeviceActionFactory(final DeviceActionFactory deviceActionFactory) {
62         this.deviceActionFactory = deviceActionFactory;
63         return this;
64     }
65
66     public NetconfDeviceBuilder setNode(final NetconfNode node) {
67         this.node = node;
68         return this;
69     }
70
71     public NetconfDeviceBuilder setEventExecutor(final EventExecutor eventExecutor) {
72         this.eventExecutor = eventExecutor;
73         return this;
74     }
75
76     public NetconfDeviceBuilder setNodeOptional(final NetconfNodeAugmentedOptional nodeOptional) {
77         this.nodeOptional = nodeOptional;
78         return this;
79     }
80
81     public NetconfDevice build() {
82         validation();
83         return new NetconfDevice(this.schemaResourcesDTO, this.id, this.salFacade, this.globalProcessingExecutor,
84                 this.reconnectOnSchemasChange, this.deviceActionFactory, this.node, this.eventExecutor,
85                 this.nodeOptional);
86     }
87
88     private void validation() {
89         Preconditions.checkNotNull(this.id, "RemoteDeviceId is not initialized");
90         Preconditions.checkNotNull(this.salFacade, "RemoteDeviceHandler is not initialized");
91         Preconditions.checkNotNull(this.globalProcessingExecutor, "ExecutorService is not initialized");
92         Preconditions.checkNotNull(this.schemaResourcesDTO, "SchemaResourceDTO is not initialized");
93     }
94 }