8207d81115dac376def9bfc089819b0bbebb6da9
[netconf.git] / plugins / netconf-client-mdsal / src / main / java / org / opendaylight / netconf / client / mdsal / 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.client.mdsal;
9
10 import static java.util.Objects.requireNonNull;
11
12 import com.google.common.util.concurrent.ListeningExecutorService;
13 import org.opendaylight.netconf.client.mdsal.NetconfDevice.SchemaResourcesDTO;
14 import org.opendaylight.netconf.client.mdsal.api.BaseNetconfSchemas;
15 import org.opendaylight.netconf.client.mdsal.api.DeviceActionFactory;
16 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceHandler;
17 import org.opendaylight.netconf.client.mdsal.api.RemoteDeviceId;
18
19 public class NetconfDeviceBuilder {
20     private boolean reconnectOnSchemasChange;
21     private SchemaResourcesDTO schemaResourcesDTO;
22     private RemoteDeviceId id;
23     private RemoteDeviceHandler salFacade;
24     private ListeningExecutorService globalProcessingExecutor;
25     private DeviceActionFactory deviceActionFactory;
26     private BaseNetconfSchemas baseSchemas;
27
28     public NetconfDeviceBuilder() {
29     }
30
31     public NetconfDeviceBuilder setReconnectOnSchemasChange(final boolean reconnectOnSchemasChange) {
32         this.reconnectOnSchemasChange = reconnectOnSchemasChange;
33         return this;
34     }
35
36     public NetconfDeviceBuilder setId(final RemoteDeviceId id) {
37         this.id = id;
38         return this;
39     }
40
41     public NetconfDeviceBuilder setSchemaResourcesDTO(final SchemaResourcesDTO schemaResourcesDTO) {
42         this.schemaResourcesDTO = schemaResourcesDTO;
43         return this;
44     }
45
46     public NetconfDeviceBuilder setSalFacade(final RemoteDeviceHandler salFacade) {
47         this.salFacade = salFacade;
48         return this;
49     }
50
51     public NetconfDeviceBuilder setGlobalProcessingExecutor(final ListeningExecutorService globalProcessingExecutor) {
52         this.globalProcessingExecutor = globalProcessingExecutor;
53         return this;
54     }
55
56     public NetconfDeviceBuilder setDeviceActionFactory(final DeviceActionFactory deviceActionFactory) {
57         this.deviceActionFactory = deviceActionFactory;
58         return this;
59     }
60
61     public NetconfDeviceBuilder setBaseSchemas(final BaseNetconfSchemas baseSchemas) {
62         this.baseSchemas = requireNonNull(baseSchemas);
63         return this;
64     }
65
66     public NetconfDevice build() {
67         validation();
68         return new NetconfDevice(schemaResourcesDTO, baseSchemas, id, salFacade,
69             globalProcessingExecutor, reconnectOnSchemasChange, deviceActionFactory);
70     }
71
72     private void validation() {
73         requireNonNull(baseSchemas, "BaseSchemas is not initialized");
74         requireNonNull(id, "RemoteDeviceId is not initialized");
75         requireNonNull(salFacade, "RemoteDeviceHandler is not initialized");
76         requireNonNull(globalProcessingExecutor, "ExecutorService is not initialized");
77         requireNonNull(schemaResourcesDTO, "SchemaResourceDTO is not initialized");
78     }
79 }