Switch to MD-SAL APIs
[openflowplugin.git] / test-provider / src / main / java / org / opendaylight / openflowplugin / test / OpenflowpluginMeterTestServiceProvider.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.DataBroker;
13 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
14 import org.opendaylight.mdsal.binding.api.RpcProviderService;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterOutput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInput;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterOutput;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput;
26 import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
27 import org.opendaylight.yangtools.concepts.ObjectRegistration;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 import org.opendaylight.yangtools.yang.common.RpcResult;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 public class OpenflowpluginMeterTestServiceProvider implements AutoCloseable,
34         SalMeterService {
35     private static final Logger LOG = LoggerFactory
36             .getLogger(OpenflowpluginMeterTestServiceProvider.class);
37     private DataBroker dataService;
38     private ObjectRegistration<SalMeterService> meterRegistration;
39     private NotificationPublishService notificationService;
40
41     /**
42      * Gets the data service.
43      *
44      * @return {@link #dataService}
45      */
46     public DataBroker getDataService() {
47         return this.dataService;
48     }
49
50     /**
51      * Sets the {@link #dataService}.
52      */
53     public void setDataService(final DataBroker dataService) {
54         this.dataService = dataService;
55     }
56
57     /**
58      * Gets the meter registration.
59      *
60      * @return {@link #meterRegistration}
61      */
62     public ObjectRegistration<SalMeterService> getMeterRegistration() {
63         return this.meterRegistration;
64     }
65
66     /**
67      * Sets the {@link #meterRegistration}.
68      */
69     public void setMeterRegistration(final ObjectRegistration<SalMeterService> meterRegistration) {
70         this.meterRegistration = meterRegistration;
71     }
72
73     /**
74      * Gets the notification service.
75      *
76      * @return {@link #notificationService}
77      */
78     public NotificationPublishService getNotificationService() {
79         return this.notificationService;
80     }
81
82     /**
83      * Sets the {@link #notificationService}.
84      */
85     public void setNotificationService(final NotificationPublishService notificationService) {
86         this.notificationService = notificationService;
87     }
88
89     public void start() {
90         OpenflowpluginMeterTestServiceProvider.LOG
91                 .info("SalMeterServiceProvider Started.");
92     }
93
94     /*
95      * (non-Javadoc)
96      *
97      * @see java.lang.AutoCloseable#close()
98      */
99     @Override
100     public void close() {
101         OpenflowpluginMeterTestServiceProvider.LOG
102                 .info("SalMeterServiceProvide stopped.");
103         meterRegistration.close();
104     }
105
106     /*
107      * (non-Javadoc)
108      *
109      * @see
110      * org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918
111      * .SalMeterService
112      * #addMeter(org.opendaylight.yang.gen.v1.urn.opendaylight.meter
113      * .service.rev130918.AddMeterInput)
114      */
115     @Override
116     public ListenableFuture<RpcResult<AddMeterOutput>> addMeter(final AddMeterInput input) {
117         OpenflowpluginMeterTestServiceProvider.LOG.info("addMeter - {}", input);
118         return null;
119     }
120
121     /*
122      * (non-Javadoc)
123      *
124      * @see
125      * org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918
126      * .SalMeterService
127      * #removeMeter(org.opendaylight.yang.gen.v1.urn.opendaylight
128      * .meter.service.rev130918.RemoveMeterInput)
129      */
130     @Override
131     public ListenableFuture<RpcResult<RemoveMeterOutput>> removeMeter(
132             final RemoveMeterInput input) {
133         OpenflowpluginMeterTestServiceProvider.LOG.info("removeMeter - {}", input);
134         return null;
135     }
136
137     /*
138      * (non-Javadoc)
139      *
140      * @see
141      * org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918
142      * .SalMeterService
143      * #updateMeter(org.opendaylight.yang.gen.v1.urn.opendaylight
144      * .meter.service.rev130918.UpdateMeterInput)
145      */
146     @Override
147     public ListenableFuture<RpcResult<UpdateMeterOutput>> updateMeter(
148             final UpdateMeterInput input) {
149         OpenflowpluginMeterTestServiceProvider.LOG.info("updateMeter - {}", input);
150         return null;
151     }
152
153     public ObjectRegistration<OpenflowpluginMeterTestServiceProvider> register(final RpcProviderService rpcRegistry) {
154         setMeterRegistration(rpcRegistry.registerRpcImplementation(SalMeterService.class, this, ImmutableSet.of(
155             InstanceIdentifier.create(Nodes.class)
156             .child(Node.class, new NodeKey(new NodeId(OpenflowpluginTestActivator.NODE_ID))))));
157
158         return new AbstractObjectRegistration<OpenflowpluginMeterTestServiceProvider>(this) {
159
160             @Override
161             protected void removeRegistration() {
162                 meterRegistration.close();
163             }
164         };
165     }
166 }