Merge "Propagate reconnectOnSchemasChanged flag to ClusteredNetconfDevice"
[netconf.git] / netconf / sal-netconf-connector / src / main / java / org / opendaylight / netconf / sal / connect / netconf / SchemalessNetconfDevice.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 org.opendaylight.netconf.api.NetconfMessage;
11 import org.opendaylight.netconf.sal.connect.api.RemoteDevice;
12 import org.opendaylight.netconf.sal.connect.api.RemoteDeviceHandler;
13 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfDeviceCommunicator;
14 import org.opendaylight.netconf.sal.connect.netconf.listener.NetconfSessionPreferences;
15 import org.opendaylight.netconf.sal.connect.netconf.sal.SchemalessNetconfDeviceRpc;
16 import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseRpcSchemalessTransformer;
17 import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.BaseSchema;
18 import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.SchemalessMessageTransformer;
19 import org.opendaylight.netconf.sal.connect.util.MessageCounter;
20 import org.opendaylight.netconf.sal.connect.util.RemoteDeviceId;
21
22 public class SchemalessNetconfDevice implements
23         RemoteDevice<NetconfSessionPreferences, NetconfMessage, NetconfDeviceCommunicator> {
24
25     private RemoteDeviceId id;
26     private RemoteDeviceHandler<NetconfSessionPreferences> salFacade;
27     private final SchemalessMessageTransformer messageTransformer;
28     private final BaseRpcSchemalessTransformer rpcTransformer;
29
30     public SchemalessNetconfDevice(final RemoteDeviceId id,
31                                    final RemoteDeviceHandler<NetconfSessionPreferences> salFacade) {
32         this.id = id;
33         this.salFacade = salFacade;
34         final MessageCounter counter = new MessageCounter();
35         rpcTransformer = new BaseRpcSchemalessTransformer(counter);
36         messageTransformer = new SchemalessMessageTransformer(counter);
37     }
38
39     @Override public void onRemoteSessionUp(final NetconfSessionPreferences remoteSessionCapabilities,
40                                             final NetconfDeviceCommunicator netconfDeviceCommunicator) {
41         final SchemalessNetconfDeviceRpc schemalessNetconfDeviceRpc = new SchemalessNetconfDeviceRpc(id,
42                 netconfDeviceCommunicator, rpcTransformer, messageTransformer);
43
44         salFacade.onDeviceConnected(BaseSchema.BASE_NETCONF_CTX.getSchemaContext(),
45                 remoteSessionCapabilities, schemalessNetconfDeviceRpc);
46
47     }
48
49     @Override public void onRemoteSessionDown() {
50         salFacade.onDeviceDisconnected();
51     }
52
53     @Override public void onRemoteSessionFailed(final Throwable throwable) {
54         salFacade.onDeviceFailed(throwable);
55     }
56
57     @Override public void onNotification(final NetconfMessage notification) {
58         salFacade.onNotification(messageTransformer.toNotification(notification));
59     }
60 }