clustering-test-app: use lambdas 74/57174/2
authorStephen Kitt <skitt@redhat.com>
Tue, 16 May 2017 15:51:47 +0000 (17:51 +0200)
committerRobert Varga <nite@hq.sk>
Tue, 16 May 2017 23:18:12 +0000 (23:18 +0000)
This series of patches uses lambdas instead of anonymous classes for
functional interfaces when possible. Lambdas are replaced with method
references when appropriate.

Change-Id: I32a6ac8e58d3f4b2820c3ee52eedb9e108c1a632
Signed-off-by: Stephen Kitt <skitt@redhat.com>
opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/CarProvider.java

index d70ac410d1535cfaba967e7b063dc8a7f6962df9..63041aba0ed86282c1fb75251f0dad4f417472fa 100644 (file)
@@ -150,53 +150,50 @@ public class CarProvider implements CarService {
         stopThread = false;
         final long sleep = TimeUnit.NANOSECONDS.convert(1000,TimeUnit.MILLISECONDS) / inputRate;
         final Stopwatch sw = Stopwatch.createUnstarted();
         stopThread = false;
         final long sleep = TimeUnit.NANOSECONDS.convert(1000,TimeUnit.MILLISECONDS) / inputRate;
         final Stopwatch sw = Stopwatch.createUnstarted();
-        testThread = new Thread() {
-            @Override
-            public void run() {
-                sw.start();
-                AtomicLong count = new AtomicLong();
-                while(!stopThread) {
-                    long id = count.incrementAndGet();
-                    WriteTransaction tx = dataProvider.newWriteOnlyTransaction();
-                    CarEntry car = new CarEntryBuilder().setId(new CarId("car"+id)).build();
-                    tx.put(LogicalDatastoreType.CONFIGURATION,
-                            InstanceIdentifier.<Cars>builder(Cars.class).child(CarEntry.class, car.getKey()).build(),
-                            car);
-                    CheckedFuture<Void, TransactionCommitFailedException> future =  tx.submit();
-                    Futures.addCallback(future, new FutureCallback<Void>() {
-
-                        @Override
-                        public void onSuccess(final Void result) {
-                            // Transaction succeeded
-                            succcessCounter.getAndIncrement();
-                        }
-
-                        @Override
-                        public void onFailure(final Throwable t) {
-                            // Transaction failed
-                            failureCounter.getAndIncrement();
-                            LOG.error("Put Cars failed", t);
-                        }
-                    });
-                    try {
-                        TimeUnit.NANOSECONDS.sleep(sleep);
-                    } catch (InterruptedException e) {
-                        break;
+        testThread = new Thread(() -> {
+            sw.start();
+            AtomicLong count = new AtomicLong();
+            while(!stopThread) {
+                long id = count.incrementAndGet();
+                WriteTransaction tx1 = dataProvider.newWriteOnlyTransaction();
+                CarEntry car = new CarEntryBuilder().setId(new CarId("car"+id)).build();
+                tx1.put(LogicalDatastoreType.CONFIGURATION,
+                        InstanceIdentifier.<Cars>builder(Cars.class).child(CarEntry.class, car.getKey()).build(),
+                        car);
+                CheckedFuture<Void, TransactionCommitFailedException> future = tx1.submit();
+                Futures.addCallback(future, new FutureCallback<Void>() {
+
+                    @Override
+                    public void onSuccess(final Void result) {
+                        // Transaction succeeded
+                        succcessCounter.getAndIncrement();
                     }
 
                     }
 
-                    if(count.get() % 1000 == 0) {
-                        log.info("Cars created {}, time: {}",count.get(),sw.elapsed(TimeUnit.SECONDS));
+                    @Override
+                    public void onFailure(final Throwable t) {
+                        // Transaction failed
+                        failureCounter.getAndIncrement();
+                        LOG.error("Put Cars failed", t);
                     }
                     }
+                });
+                try {
+                    TimeUnit.NANOSECONDS.sleep(sleep);
+                } catch (InterruptedException e) {
+                    break;
+                }
 
 
-                    // Check if a count is specified in input and we have created that many cars.
-                    if (inputCount != 0 && count.get() >= inputCount) {
-                        stopThread = true;
-                    }
+                if(count.get() % 1000 == 0) {
+                    log.info("Cars created {}, time: {}",count.get(),sw.elapsed(TimeUnit.SECONDS));
                 }
 
                 }
 
-                log.info("Stress test thread stopping after creating {} cars.", count.get());
+                // Check if a count is specified in input and we have created that many cars.
+                if (inputCount != 0 && count.get() >= inputCount) {
+                    stopThread = true;
+                }
             }
             }
-        };
+
+            log.info("Stress test thread stopping after creating {} cars.", count.get());
+        });
         testThread.start();
 
         return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
         testThread.start();
 
         return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());