+ StopStressTestOutputBuilder stopStressTestOutput;
+ stopStressTestOutput = new StopStressTestOutputBuilder()
+ .setSuccessCount(succcessCounter.longValue())
+ .setFailureCount(failureCounter.longValue());
+
+ final StopStressTestOutput result = stopStressTestOutput.build();
+ LOG_PURCHASE_CAR.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(final 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(final UnregisterOwnershipInput input) {
+ return RpcResultBuilder.<Void>success().buildFuture();
+ }
+
+ private static class CarEntityOwnershipListener implements EntityOwnershipListener {
+ @Override
+ public void ownershipChanged(final EntityOwnershipChange ownershipChange) {
+ LOG_CAR_PROVIDER.info("ownershipChanged: {}", ownershipChange);
+ }
+ }
+
+ @Override
+ public Future<RpcResult<java.lang.Void>> registerLoggingDtcl() {
+ LOG_CAR_PROVIDER.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>> unregisterLoggingDtcls() {
+ LOG_CAR_PROVIDER.info("Unregistering the CarDataTreeChangeListener(s)");
+ synchronized (carsDtclRegistrations) {
+ int numListeners = 0;
+ for (ListenerRegistration<CarDataTreeChangeListener> carsDtclRegistration : carsDtclRegistrations) {
+ carsDtclRegistration.close();
+ numListeners++;
+ }
+ carsDtclRegistrations.clear();
+ LOG_CAR_PROVIDER.info("Unregistered {} CaraDataTreeChangeListener(s)", numListeners);
+ }
+ return RpcResultBuilder.<Void>success().buildFuture();