Fix warnings in test-provider
[openflowplugin.git] / test-provider / src / main / java / org / opendaylight / openflowplugin / test / OpenflowpluginMeterTestServiceProvider.java
index c2feaf23d431423546f152e343f0ae428be3d893..3a54042e9c22a2619687838b3fbecf6762f8744f 100644 (file)
@@ -1,20 +1,17 @@
-/**
+/*
  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
- * 
+ *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.openflowplugin.test;
 
-import java.util.concurrent.Future;
-
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.ProviderContext;
-import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RoutedRpcRegistration;
-import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeContext;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.util.concurrent.ListenableFuture;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.NotificationPublishService;
+import org.opendaylight.mdsal.binding.api.RpcProviderService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
@@ -26,25 +23,24 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.Rem
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput;
-import org.opendaylight.yangtools.concepts.CompositeObjectRegistration;
-import org.opendaylight.yangtools.concepts.CompositeObjectRegistration.CompositeObjectRegistrationBuilder;
+import org.opendaylight.yangtools.concepts.AbstractObjectRegistration;
+import org.opendaylight.yangtools.concepts.ObjectRegistration;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public class OpenflowpluginMeterTestServiceProvider implements AutoCloseable,
         SalMeterService {
-    private final static Logger LOG = LoggerFactory
+    private static final Logger LOG = LoggerFactory
             .getLogger(OpenflowpluginMeterTestServiceProvider.class);
     private DataBroker dataService;
-    private RoutedRpcRegistration<SalMeterService> meterRegistration;
-    private NotificationProviderService notificationService;
+    private ObjectRegistration<SalMeterService> meterRegistration;
+    private NotificationPublishService notificationService;
 
     /**
-     * get data service
-     * 
+     * Gets the data service.
+     *
      * @return {@link #dataService}
      */
     public DataBroker getDataService() {
@@ -52,49 +48,41 @@ public class OpenflowpluginMeterTestServiceProvider implements AutoCloseable,
     }
 
     /**
-     * set {@link #dataService}
-     * 
-     * @param dataService
+     * Sets the {@link #dataService}.
      */
     public void setDataService(final DataBroker dataService) {
         this.dataService = dataService;
     }
 
     /**
-     * get meter registration
-     * 
+     * Gets the meter registration.
+     *
      * @return {@link #meterRegistration}
      */
-    public RoutedRpcRegistration<SalMeterService> getMeterRegistration() {
+    public ObjectRegistration<SalMeterService> getMeterRegistration() {
         return this.meterRegistration;
     }
 
     /**
-     * set {@link #meterRegistration}
-     * 
-     * @param meterRegistration
+     * Sets the {@link #meterRegistration}.
      */
-    public void setMeterRegistration(
-            final RoutedRpcRegistration<SalMeterService> meterRegistration) {
+    public void setMeterRegistration(final ObjectRegistration<SalMeterService> meterRegistration) {
         this.meterRegistration = meterRegistration;
     }
 
     /**
-     * get notification service
-     * 
+     * Gets the notification service.
+     *
      * @return {@link #notificationService}
      */
-    public NotificationProviderService getNotificationService() {
+    public NotificationPublishService getNotificationService() {
         return this.notificationService;
     }
 
     /**
-     * set {@link #notificationService}
-     * 
-     * @param notificationService
+     * Sets the {@link #notificationService}.
      */
-    public void setNotificationService(
-            final NotificationProviderService notificationService) {
+    public void setNotificationService(final NotificationPublishService notificationService) {
         this.notificationService = notificationService;
     }
 
@@ -105,9 +93,10 @@ public class OpenflowpluginMeterTestServiceProvider implements AutoCloseable,
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see java.lang.AutoCloseable#close()
      */
+    @Override
     public void close() {
         OpenflowpluginMeterTestServiceProvider.LOG
                 .info("SalMeterServiceProvide stopped.");
@@ -116,85 +105,61 @@ public class OpenflowpluginMeterTestServiceProvider implements AutoCloseable,
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see
      * org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918
      * .SalMeterService
      * #addMeter(org.opendaylight.yang.gen.v1.urn.opendaylight.meter
      * .service.rev130918.AddMeterInput)
      */
-    public Future<RpcResult<AddMeterOutput>> addMeter(final AddMeterInput input) {
-        String plus = ("addMeter - " + input);
-        OpenflowpluginMeterTestServiceProvider.LOG.info(plus);
+    @Override
+    public ListenableFuture<RpcResult<AddMeterOutput>> addMeter(final AddMeterInput input) {
+        OpenflowpluginMeterTestServiceProvider.LOG.info("addMeter - {}", input);
         return null;
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see
      * org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918
      * .SalMeterService
      * #removeMeter(org.opendaylight.yang.gen.v1.urn.opendaylight
      * .meter.service.rev130918.RemoveMeterInput)
      */
-    public Future<RpcResult<RemoveMeterOutput>> removeMeter(
+    @Override
+    public ListenableFuture<RpcResult<RemoveMeterOutput>> removeMeter(
             final RemoveMeterInput input) {
-        String plus = ("removeMeter - " + input);
-        OpenflowpluginMeterTestServiceProvider.LOG.info(plus);
+        OpenflowpluginMeterTestServiceProvider.LOG.info("removeMeter - {}", input);
         return null;
     }
 
     /*
      * (non-Javadoc)
-     * 
+     *
      * @see
      * org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918
      * .SalMeterService
      * #updateMeter(org.opendaylight.yang.gen.v1.urn.opendaylight
      * .meter.service.rev130918.UpdateMeterInput)
      */
-    public Future<RpcResult<UpdateMeterOutput>> updateMeter(
+    @Override
+    public ListenableFuture<RpcResult<UpdateMeterOutput>> updateMeter(
             final UpdateMeterInput input) {
-        String plus = ("updateMeter - " + input);
-        OpenflowpluginMeterTestServiceProvider.LOG.info(plus);
+        OpenflowpluginMeterTestServiceProvider.LOG.info("updateMeter - {}", input);
         return null;
     }
 
-    /**
-     * @param ctx
-     * @return {@link CompositeObjectRegistrationBuilder #toInstance()}
-     */
-    public CompositeObjectRegistration<OpenflowpluginMeterTestServiceProvider> register(
-            final ProviderContext ctx) {
-        CompositeObjectRegistrationBuilder<OpenflowpluginMeterTestServiceProvider> builder = CompositeObjectRegistration
-                .<OpenflowpluginMeterTestServiceProvider> builderFor(this);
-
-        RoutedRpcRegistration<SalMeterService> addRoutedRpcImplementation = ctx
-                .<SalMeterService> addRoutedRpcImplementation(
-                        SalMeterService.class, this);
-
-        setMeterRegistration(addRoutedRpcImplementation);
-
-        InstanceIdentifierBuilder<Nodes> builder1 = InstanceIdentifier
-                .<Nodes> builder(Nodes.class);
-
-        NodeId nodeId = new NodeId(OpenflowpluginTestActivator.NODE_ID);
-        NodeKey nodeKey = new NodeKey(nodeId);
-
-        InstanceIdentifierBuilder<Node> nodeIndentifier = builder1
-                .<Node, NodeKey> child(Node.class, nodeKey);
-
-        InstanceIdentifier<Node> instance = nodeIndentifier.build();
-
-        meterRegistration.registerPath(NodeContext.class, instance);
-
-        RoutedRpcRegistration<SalMeterService> meterRegistration1 = this
-                .getMeterRegistration();
-
-        builder.add(meterRegistration1);
-
-        return builder.build();
+    public ObjectRegistration<OpenflowpluginMeterTestServiceProvider> register(final RpcProviderService rpcRegistry) {
+        setMeterRegistration(rpcRegistry.registerRpcImplementation(SalMeterService.class, this, ImmutableSet.of(
+            InstanceIdentifier.create(Nodes.class)
+            .child(Node.class, new NodeKey(new NodeId(OpenflowpluginTestActivator.NODE_ID))))));
+
+        return new AbstractObjectRegistration<>(this) {
+            @Override
+            protected void removeRegistration() {
+                meterRegistration.close();
+            }
+        };
     }
-
 }