Reduce use of deprecated methods
[controller.git] / benchmark / dsbenchmark / src / main / java / org / opendaylight / dsbenchmark / simpletx / SimpletxBaWrite.java
index 5357311e40a8704906f3aa33c10ef9a9458dab64..ed4d0a4bf3cc12e5e1b50a78e1b63016fcdba702 100644 (file)
@@ -9,11 +9,10 @@
 package org.opendaylight.dsbenchmark.simpletx;
 
 import java.util.List;
-
+import java.util.concurrent.ExecutionException;
 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 org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
 import org.opendaylight.dsbenchmark.BaListBuilder;
 import org.opendaylight.dsbenchmark.DatastoreAbstractWriter;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.dsbenchmark.rev150105.StartTestInput;
@@ -29,52 +28,55 @@ public class SimpletxBaWrite extends DatastoreAbstractWriter {
     private final DataBroker dataBroker;
     private List<OuterList> list;
 
-    public SimpletxBaWrite(DataBroker dataBroker, StartTestInput.Operation oper,
-            int outerListElem, int innerListElem, long writesPerTx, DataStore dataStore) {
+    public SimpletxBaWrite(final DataBroker dataBroker, final StartTestInput.Operation oper,
+            final int outerListElem, final int innerListElem, final long writesPerTx, final DataStore dataStore) {
         super(oper, outerListElem, innerListElem, writesPerTx, dataStore);
         this.dataBroker = dataBroker;
-        LOG.info("Created SimpletxBaWrite");
+        LOG.debug("Created SimpletxBaWrite");
     }
 
-     @Override
-     public void createList() {
-         list = BaListBuilder.buildOuterList(this.outerListElem, this.innerListElem);
-     }
+    @Override
+    public void createList() {
+        list = BaListBuilder.buildOuterList(this.outerListElem, this.innerListElem);
+    }
 
     @Override
     public void executeList() {
+        final LogicalDatastoreType dsType = getDataStoreType();
+
         WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
         long writeCnt = 0;
 
         for (OuterList element : this.list) {
             InstanceIdentifier<OuterList> iid = InstanceIdentifier.create(TestExec.class)
-                                                    .child(OuterList.class, element.getKey());
+                                                    .child(OuterList.class, element.key());
             if (oper == StartTestInput.Operation.PUT) {
-                tx.put(LogicalDatastoreType.CONFIGURATION, iid, element);
+                tx.put(dsType, iid, element);
             } else {
-                tx.merge(LogicalDatastoreType.CONFIGURATION, iid, element);
+                tx.merge(dsType, iid, element);
             }
 
             writeCnt++;
 
             if (writeCnt == writesPerTx) {
                 try {
-                    tx.submit().checkedGet();
+                    tx.commit().get();
                     txOk++;
-                } catch (TransactionCommitFailedException e) {
-                    LOG.error("Transaction failed: {}", e.toString());
+                } catch (final InterruptedException | ExecutionException e) {
+                    LOG.error("Transaction failed: {}", e);
                     txError++;
                 }
                 tx = dataBroker.newWriteOnlyTransaction();
+
                 writeCnt = 0;
             }
         }
 
         if (writeCnt != 0) {
             try {
-                tx.submit().checkedGet();
-            } catch (TransactionCommitFailedException e) {
-                LOG.error("Transaction failed: {}", e.toString());
+                tx.commit().get();
+            } catch (final InterruptedException | ExecutionException e) {
+                LOG.error("Transaction failed: {}", e);
             }
         }
     }