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