+ StopStressTestOutputBuilder stopStressTestOutput;
+ stopStressTestOutput = new StopStressTestOutputBuilder()
+ .setSuccessCount(succcessCounter.longValue())
+ .setFailureCount(failureCounter.longValue());
+
+ StopStressTestOutput result = stopStressTestOutput.build();
+ log.info("Executed Stop Stress test; No. of cars created {}; " +
+ "No. of cars failed {}; ", succcessCounter, failureCounter);
+ // clear counters
+ succcessCounter.set(0);
+ failureCounter.set(0);
+ return Futures.immediateFuture(RpcResultBuilder.<StopStressTestOutput>success(result).build());
+ }
+
+
+ @Override
+ public Future<RpcResult<Void>> registerOwnership(RegisterOwnershipInput input) {
+ if(registeredListener.compareAndSet(false, true)) {
+ ownershipService.registerListener(ENTITY_TYPE, ownershipListener);
+ }
+
+ Entity entity = new Entity(ENTITY_TYPE, input.getCarId());
+ try {
+ ownershipService.registerCandidate(entity);
+ } catch (CandidateAlreadyRegisteredException e) {
+ return RpcResultBuilder.<Void>failed().withError(ErrorType.APPLICATION,
+ "Could not register for car " + input.getCarId(), e).buildFuture();
+ }
+
+ return RpcResultBuilder.<Void>success().buildFuture();
+ }
+
+ @Override
+ public Future<RpcResult<Void>> unregisterOwnership(UnregisterOwnershipInput input) {
+ return RpcResultBuilder.<Void>success().buildFuture();
+ }
+
+ private static class CarEntityOwnershipListener implements EntityOwnershipListener {
+ @Override
+ public void ownershipChanged(EntityOwnershipChange ownershipChange) {
+ LOG.info("ownershipChanged: {}", ownershipChange);
+ }
+ }
+
+ @Override
+ public Future<RpcResult<java.lang.Void>> registerLoggingDcl() {
+ LOG.info("Registering a new CarDataChangeListener");
+ final ListenerRegistration carsDclRegistration = dataProvider.registerDataChangeListener(
+ LogicalDatastoreType.CONFIGURATION, CARS_IID, new CarDataChangeListener(),
+ AsyncDataBroker.DataChangeScope.SUBTREE);
+
+ if (carsDclRegistration != null) {
+ carsDclRegistrations.add(carsDclRegistration);
+ return RpcResultBuilder.<Void>success().buildFuture();
+ }
+ return RpcResultBuilder.<Void>failed().buildFuture();
+ }
+
+ @Override
+ public Future<RpcResult<java.lang.Void>> registerLoggingDtcl() {
+ LOG.info("Registering a new CarDataTreeChangeListener");
+ final ListenerRegistration<CarDataTreeChangeListener> carsDtclRegistration =
+ dataProvider.registerDataTreeChangeListener(CARS_DTID, new CarDataTreeChangeListener());
+
+ if (carsDtclRegistration != null) {
+ carsDtclRegistrations.add(carsDtclRegistration);
+ return RpcResultBuilder.<Void>success().buildFuture();
+ }
+ return RpcResultBuilder.<Void>failed().buildFuture();
+ }
+
+ @Override
+ public Future<RpcResult<java.lang.Void>> unregisterLoggingDcls() {
+ LOG.info("Unregistering the CarDataChangeListener(s)");
+ synchronized (carsDclRegistrations) {
+ int numListeners = 0;
+ for (ListenerRegistration<DataChangeListener> carsDclRegistration : carsDclRegistrations) {
+ carsDclRegistration.close();
+ numListeners++;
+ }
+ carsDclRegistrations.clear();
+ LOG.info("Unregistered {} CarDataChangeListener(s)", numListeners);
+ }
+ return RpcResultBuilder.<Void>success().buildFuture();
+ }
+
+ @Override
+ public Future<RpcResult<java.lang.Void>> unregisterLoggingDtcls() {
+ LOG.info("Unregistering the CarDataTreeChangeListener(s)");
+ synchronized (carsDtclRegistrations) {
+ int numListeners = 0;
+ for (ListenerRegistration<CarDataTreeChangeListener> carsDtclRegistration : carsDtclRegistrations) {
+ carsDtclRegistration.close();
+ numListeners++;
+ }
+ carsDtclRegistrations.clear();
+ LOG.info("Unregistered {} CaraDataTreeChangeListener(s)", numListeners);
+ }
+ return RpcResultBuilder.<Void>success().buildFuture();