50a1e9ade98a7ae9a7c74861f25fd636692b3fff
[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 org.opendaylight.netconf.sal.connect.api.DeviceActionFactory;
14 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
15 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
16 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
17
18 public class NetconfDeviceBuilder {
19
20     private boolean reconnectOnSchemasChange;
21     private NetconfDevice.SchemaResourcesDTO schemaResourcesDTO;
22     private RemoteDeviceId id;
23     private RemoteDeviceHandler<NetconfSessionPreferences> salFacade;
24     private ListeningExecutorService globalProcessingExecutor;
25     private DeviceActionFactory deviceActionFactory;
26
27     public NetconfDeviceBuilder() {
28     }
29
30     public NetconfDeviceBuilder setReconnectOnSchemasChange(final boolean reconnectOnSchemasChange) {
31         this.reconnectOnSchemasChange = reconnectOnSchemasChange;
32         return this;
33     }
34
35     public NetconfDeviceBuilder setId(final RemoteDeviceId id) {
36         this.id = id;
37         return this;
38     }
39
40     public NetconfDeviceBuilder setSchemaResourcesDTO(final NetconfDevice.SchemaResourcesDTO schemaResourcesDTO) {
41         this.schemaResourcesDTO = schemaResourcesDTO;
42         return this;
43     }
44
45     public NetconfDeviceBuilder setSalFacade(final RemoteDeviceHandler<NetconfSessionPreferences> salFacade) {
46         this.salFacade = salFacade;
47         return this;
48     }
49
50     public NetconfDeviceBuilder setGlobalProcessingExecutor(final ListeningExecutorService globalProcessingExecutor) {
51         this.globalProcessingExecutor = globalProcessingExecutor;
52         return this;
53     }
54
55     public NetconfDeviceBuilder setDeviceActionFactory(final DeviceActionFactory deviceActionFactory) {
56         this.deviceActionFactory = deviceActionFactory;
57         return this;
58     }
59
60     public NetconfDevice build() {
61         validation();
62         return new NetconfDevice(this.schemaResourcesDTO, this.id, this.salFacade, this.globalProcessingExecutor,
63                 this.reconnectOnSchemasChange, this.deviceActionFactory);
64     }
65
66     private void validation() {
67         Preconditions.checkNotNull(this.id, "RemoteDeviceId is not initialized");
68         Preconditions.checkNotNull(this.salFacade, "RemoteDeviceHandler is not initialized");
69         Preconditions.checkNotNull(this.globalProcessingExecutor, "ExecutorService is not initialized");
70         Preconditions.checkNotNull(this.schemaResourcesDTO, "SchemaResourceDTO is not initialized");
71     }
72 }