Remove deprecated MD-SAL APIs
[controller.git] / opendaylight / md-sal / samples / clustering-test-app / provider / src / main / java / org / opendaylight / controller / clustering / it / listener / PeopleCarListener.java
index a01a858e2a8000f4d515bda3f4002a497c0c07b0..cc8540f77e331f6fcf04603fe3649bbca7824fab 100644 (file)
@@ -5,14 +5,14 @@
  * 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.controller.clustering.it.listener;
 
 import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import com.google.common.util.concurrent.MoreExecutors;
+import org.opendaylight.mdsal.binding.api.DataBroker;
+import org.opendaylight.mdsal.binding.api.WriteTransaction;
+import org.opendaylight.mdsal.common.api.CommitInfo;
+import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.people.rev140818.CarPeople;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.people.rev140818.car.people.CarPerson;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.people.rev140818.car.people.CarPersonBuilder;
@@ -23,49 +23,44 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
 public class PeopleCarListener implements CarPurchaseListener {
+    private static final Logger LOG = LoggerFactory.getLogger(PeopleCarListener.class);
 
-  private static final Logger log = LoggerFactory.getLogger(PeopleCarListener.class);
-
-  private DataBroker dataProvider;
-
-
-
-  public void setDataProvider(final DataBroker salDataProvider) {
-    this.dataProvider = salDataProvider;
-  }
+    private DataBroker dataProvider;
 
-  @Override
-  public void onCarBought(CarBought notification) {
+    public void setDataProvider(final DataBroker salDataProvider) {
+        this.dataProvider = salDataProvider;
+    }
 
-    final CarPersonBuilder carPersonBuilder = new CarPersonBuilder();
-    carPersonBuilder.setCarId(notification.getCarId());
-    carPersonBuilder.setPersonId(notification.getPersonId());
-    CarPersonKey key = new CarPersonKey(notification.getCarId(), notification.getPersonId());
-    carPersonBuilder.setKey(key);
-    final CarPerson carPerson = carPersonBuilder.build();
+    @Override
+    public void onCarBought(final CarBought notification) {
 
-    log.info("Car bought, adding car-person entry: [{}]", carPerson);
+        final CarPersonBuilder carPersonBuilder = new CarPersonBuilder();
+        carPersonBuilder.setCarId(notification.getCarId());
+        carPersonBuilder.setPersonId(notification.getPersonId());
+        CarPersonKey key = new CarPersonKey(notification.getCarId(), notification.getPersonId());
+        carPersonBuilder.withKey(key);
+        final CarPerson carPerson = carPersonBuilder.build();
 
-    InstanceIdentifier<CarPerson> carPersonIId =
-        InstanceIdentifier.<CarPeople>builder(CarPeople.class).child(CarPerson.class, carPerson.getKey()).build();
+        LOG.info("Car bought, adding car-person entry: [{}]", carPerson);
 
+        InstanceIdentifier<CarPerson> carPersonIId = InstanceIdentifier.builder(CarPeople.class)
+                .child(CarPerson.class, carPerson.key()).build();
 
-    WriteTransaction tx = dataProvider.newWriteOnlyTransaction();
-    tx.put(LogicalDatastoreType.CONFIGURATION, carPersonIId, carPerson, true);
 
-    Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
-      @Override
-      public void onSuccess(final Void result) {
-        log.info("Successfully added car-person entry: [{}]", carPerson);
-      }
+        WriteTransaction tx = dataProvider.newWriteOnlyTransaction();
+        tx.put(LogicalDatastoreType.CONFIGURATION, carPersonIId, carPerson, true);
 
-      @Override
-      public void onFailure(final Throwable t) {
-        log.error(String.format("Failed to add car-person entry: [%s]", carPerson), t);
-      }
-    });
+        tx.commit().addCallback(new FutureCallback<CommitInfo>() {
+            @Override
+            public void onSuccess(final CommitInfo result) {
+                LOG.info("Successfully added car-person entry: [{}]", carPerson);
+            }
 
-  }
+            @Override
+            public void onFailure(final Throwable ex) {
+                LOG.error("Failed to add car-person entry: [{}]", carPerson, ex);
+            }
+        }, MoreExecutors.directExecutor());
+    }
 }