Specialize RemoteDeviceHandler to NetconfSessionPreferences
[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 package org.opendaylight.netconf.sal.connect.netconf;
9
10 import static java.util.Objects.requireNonNull;
11
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.schema.mapping.BaseNetconfSchemas;
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 salFacade;
27     private ListeningExecutorService globalProcessingExecutor;
28     private DeviceActionFactory deviceActionFactory;
29     private NetconfNode node;
30     private EventExecutor eventExecutor;
31     private NetconfNodeAugmentedOptional nodeOptional;
32     private BaseNetconfSchemas baseSchemas;
33
34     public NetconfDeviceBuilder() {
35     }
36
37     public NetconfDeviceBuilder setReconnectOnSchemasChange(final boolean reconnectOnSchemasChange) {
38         this.reconnectOnSchemasChange = reconnectOnSchemasChange;
39         return this;
40     }
41
42     public NetconfDeviceBuilder setId(final RemoteDeviceId id) {
43         this.id = id;
44         return this;
45     }
46
47     public NetconfDeviceBuilder setSchemaResourcesDTO(final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO) {
48         this.schemaResourcesDTO = schemaResourcesDTO;
49         return this;
50     }
51
52     public NetconfDeviceBuilder setSalFacade(final RemoteDeviceHandler salFacade) {
53         this.salFacade = salFacade;
54         return this;
55     }
56
57     public NetconfDeviceBuilder setGlobalProcessingExecutor(final ListeningExecutorService globalProcessingExecutor) {
58         this.globalProcessingExecutor = globalProcessingExecutor;
59         return this;
60     }
61
62     public NetconfDeviceBuilder setDeviceActionFactory(final DeviceActionFactory deviceActionFactory) {
63         this.deviceActionFactory = deviceActionFactory;
64         return this;
65     }
66
67     public NetconfDeviceBuilder setNode(final NetconfNode node) {
68         this.node = node;
69         return this;
70     }
71
72     public NetconfDeviceBuilder setEventExecutor(final EventExecutor eventExecutor) {
73         this.eventExecutor = eventExecutor;
74         return this;
75     }
76
77     public NetconfDeviceBuilder setNodeOptional(final NetconfNodeAugmentedOptional nodeOptional) {
78         this.nodeOptional = nodeOptional;
79         return this;
80     }
81
82     public NetconfDeviceBuilder setBaseSchemas(final BaseNetconfSchemas baseSchemas) {
83         this.baseSchemas = requireNonNull(baseSchemas);
84         return this;
85     }
86
87     public NetconfDevice build() {
88         validation();
89         return new NetconfDevice(schemaResourcesDTO, baseSchemas, id, salFacade,
90             globalProcessingExecutor, reconnectOnSchemasChange, deviceActionFactory, node,
91             eventExecutor, nodeOptional);
92     }
93
94     private void validation() {
95         requireNonNull(baseSchemas, "BaseSchemas is not initialized");
96         requireNonNull(id, "RemoteDeviceId is not initialized");
97         requireNonNull(salFacade, "RemoteDeviceHandler is not initialized");
98         requireNonNull(globalProcessingExecutor, "ExecutorService is not initialized");
99         requireNonNull(schemaResourcesDTO, "SchemaResourceDTO is not initialized");
100     }
101 }