bug 2493 - eliminate the use of xtend and remove dependecies
[openflowplugin.git] / test-provider / src / main / java / org / opendaylight / openflowplugin / test / OpenflowpluginTableFeaturesTestServiceProvider.java
1 /**
2  * Copyright (c) 2013 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.openflowplugin.test;
10
11 import java.util.concurrent.Future;
12
13 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
14 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
15 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.SalTableService;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput;
24 import org.opendaylight.yangtools.concepts.CompositeObjectRegistration;
25 import org.opendaylight.yangtools.concepts.CompositeObjectRegistration.CompositeObjectRegistrationBuilder;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
28 import org.opendaylight.yangtools.yang.common.RpcResult;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 public class OpenflowpluginTableFeaturesTestServiceProvider implements
33         AutoCloseable, SalTableService {
34
35     private final static Logger LOG = LoggerFactory
36             .getLogger(OpenflowpluginTableFeaturesTestServiceProvider.class);
37     private RoutedRpcRegistration<SalTableService> tableRegistration;
38     private NotificationProviderService notificationService;
39
40     /**
41      * get table registration
42      * 
43      * @return {@link #tableRegistration}
44      */
45     public RoutedRpcRegistration<SalTableService> getTableRegistration() {
46         return this.tableRegistration;
47     }
48
49     /**
50      * set {@link #tableRegistration}
51      * 
52      * @param tableRegistration
53      */
54     public void setTableRegistration(
55             final RoutedRpcRegistration<SalTableService> tableRegistration) {
56         this.tableRegistration = tableRegistration;
57     }
58
59     /**
60      * get notification service
61      * 
62      * @return {@link #notificationService}
63      */
64     public NotificationProviderService getNotificationService() {
65         return this.notificationService;
66     }
67
68     /**
69      * set {@link #notificationService}
70      * 
71      * @param notificationService
72      */
73     public void setNotificationService(
74             final NotificationProviderService notificationService) {
75         this.notificationService = notificationService;
76     }
77
78     public void start() {
79         OpenflowpluginTableFeaturesTestServiceProvider.LOG
80                 .info("SalTableServiceProvider Started.");
81     }
82
83     /*
84      * (non-Javadoc)
85      * 
86      * @see java.lang.AutoCloseable#close()
87      */
88     @Override
89     public void close() throws Exception {
90         OpenflowpluginTableFeaturesTestServiceProvider.LOG
91                 .info("SalTableServiceProvider stopped.");
92         tableRegistration.close();
93     }
94
95     /*
96      * (non-Javadoc)
97      * 
98      * @see
99      * org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026
100      * .SalTableService
101      * #updateTable(org.opendaylight.yang.gen.v1.urn.opendaylight
102      * .table.service.rev131026.UpdateTableInput)
103      */
104     @Override
105     public Future<RpcResult<UpdateTableOutput>> updateTable(
106             UpdateTableInput input) {
107         String plus = ("updateTable - " + input);
108         OpenflowpluginTableFeaturesTestServiceProvider.LOG.info(plus);
109         return null;
110     }
111
112     /**
113      * @param ctx
114      * @return {@link CompositeObjectRegistrationBuilder #toInstance()}
115      */
116     public CompositeObjectRegistration<OpenflowpluginTableFeaturesTestServiceProvider> register(
117             final ProviderContext ctx) {
118         CompositeObjectRegistrationBuilder<OpenflowpluginTableFeaturesTestServiceProvider> builder = CompositeObjectRegistration
119                 .<OpenflowpluginTableFeaturesTestServiceProvider> builderFor(this);
120
121         RoutedRpcRegistration<SalTableService> addRoutedRpcImplementation = ctx
122                 .<SalTableService> addRoutedRpcImplementation(
123                         SalTableService.class, this);
124
125         setTableRegistration(addRoutedRpcImplementation);
126
127         InstanceIdentifierBuilder<Nodes> builder1 = InstanceIdentifier
128                 .<Nodes> builder(Nodes.class);
129
130         NodeId nodeId = new NodeId(OpenflowpluginTestActivator.NODE_ID);
131         NodeKey nodeKey = new NodeKey(nodeId);
132
133         InstanceIdentifierBuilder<Node> nodeIndentifier = builder1
134                 .<Node, NodeKey> child(Node.class, nodeKey);
135
136         InstanceIdentifier<Node> instance = nodeIndentifier.build();
137
138         tableRegistration.registerPath(NodeContext.class, instance);
139
140         RoutedRpcRegistration<SalTableService> tableRegistration1 = this
141                 .getTableRegistration();
142
143         builder.add(tableRegistration1);
144
145         return builder.build();
146     }
147
148 }