From: Stephen Kitt Date: Tue, 16 May 2017 15:51:47 +0000 (+0200) Subject: clustering-test-app: use lambdas X-Git-Tag: release/nitrogen~232 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=81b084ab4d155131a0a7f95adbdcd769d2df5728 clustering-test-app: use lambdas 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 --- diff --git a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/CarProvider.java b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/CarProvider.java index d70ac410d1..63041aba0e 100644 --- a/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/CarProvider.java +++ b/opendaylight/md-sal/samples/clustering-test-app/provider/src/main/java/org/opendaylight/controller/clustering/it/provider/CarProvider.java @@ -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(); - 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.builder(Cars.class).child(CarEntry.class, car.getKey()).build(), - car); - CheckedFuture future = tx.submit(); - Futures.addCallback(future, new FutureCallback() { - - @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.builder(Cars.class).child(CarEntry.class, car.getKey()).build(), + car); + CheckedFuture future = tx1.submit(); + Futures.addCallback(future, new FutureCallback() { + + @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.success().build());