Switch to MD-SAL APIs
[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 package org.opendaylight.openflowplugin.test;
9
10 import com.google.common.collect.ImmutableSet;
11 import com.google.common.util.concurrent.ListenableFuture;
12 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
13 import org.opendaylight.mdsal.binding.api.RpcProviderService;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.SalTableService;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput;
21 import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
22 import org.opendaylight.yangtools.concepts.ObjectRegistration;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 import org.opendaylight.yangtools.yang.common.RpcResult;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 public class OpenflowpluginTableFeaturesTestServiceProvider implements
29         AutoCloseable, SalTableService {
30
31     private static final Logger LOG = LoggerFactory
32             .getLogger(OpenflowpluginTableFeaturesTestServiceProvider.class);
33     private ObjectRegistration<SalTableService> tableRegistration;
34     private NotificationPublishService notificationService;
35
36     /**
37      * Get table registration.
38      *
39      * @return {@link #tableRegistration}
40      */
41     public ObjectRegistration<SalTableService> getTableRegistration() {
42         return this.tableRegistration;
43     }
44
45     /**
46      * Set {@link #tableRegistration}.
47      */
48     public void setTableRegistration(final ObjectRegistration<SalTableService> tableRegistration) {
49         this.tableRegistration = tableRegistration;
50     }
51
52     /**
53      * Get notification service.
54      *
55      * @return {@link #notificationService}
56      */
57     public NotificationPublishService getNotificationService() {
58         return this.notificationService;
59     }
60
61     /**
62      * Set {@link #notificationService}.
63      */
64     public void setNotificationService(final NotificationPublishService notificationService) {
65         this.notificationService = notificationService;
66     }
67
68     public void start() {
69         OpenflowpluginTableFeaturesTestServiceProvider.LOG
70                 .info("SalTableServiceProvider Started.");
71     }
72
73     /*
74      * (non-Javadoc)
75      *
76      * @see java.lang.AutoCloseable#close()
77      */
78     @Override
79     public void close() throws Exception {
80         OpenflowpluginTableFeaturesTestServiceProvider.LOG
81                 .info("SalTableServiceProvider stopped.");
82         tableRegistration.close();
83     }
84
85     /*
86      * (non-Javadoc)
87      *
88      * @see
89      * org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026
90      * .SalTableService
91      * #updateTable(org.opendaylight.yang.gen.v1.urn.opendaylight
92      * .table.service.rev131026.UpdateTableInput)
93      */
94     @Override
95     public ListenableFuture<RpcResult<UpdateTableOutput>> updateTable(
96             UpdateTableInput input) {
97         OpenflowpluginTableFeaturesTestServiceProvider.LOG.info("updateTable - {}", input);
98         return null;
99     }
100
101     public ObjectRegistration<OpenflowpluginTableFeaturesTestServiceProvider> register(
102             final RpcProviderService rpcRegistry) {
103         setTableRegistration(rpcRegistry.registerRpcImplementation(SalTableService.class, this, ImmutableSet.of(
104             InstanceIdentifier.create(Nodes.class)
105             .child(Node.class, new NodeKey(new NodeId(OpenflowpluginTestActivator.NODE_ID))))));
106
107         return new AbstractObjectRegistration<OpenflowpluginTableFeaturesTestServiceProvider>(this) {
108             @Override
109             protected void removeRegistration() {
110                 tableRegistration.close();
111             }
112         };
113     }
114 }