import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
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;
public class PeopleCarListener implements CarPurchaseListener {
- private static final Logger LOG = LoggerFactory.getLogger(PeopleCarListener.class);
+ private static final Logger LOG = LoggerFactory.getLogger(PeopleCarListener.class);
- private DataBroker dataProvider;
+ private DataBroker dataProvider;
- public void setDataProvider(final DataBroker salDataProvider) {
- this.dataProvider = salDataProvider;
- }
+ public void setDataProvider(final DataBroker salDataProvider) {
+ this.dataProvider = salDataProvider;
+ }
- @Override
- public void onCarBought(CarBought notification) {
+ @Override
+ public void onCarBought(CarBought notification) {
- final CarPersonBuilder carPersonBuilder = new CarPersonBuilder();
- carPersonBuilder.setCarId(notification.getCarId());
- carPersonBuilder.setPersonId(notification.getPersonId());
- CarPersonKey key = new CarPersonKey(notification.getCarId(), notification.getPersonId());
- carPersonBuilder.setKey(key);
- final CarPerson carPerson = carPersonBuilder.build();
+ final CarPersonBuilder carPersonBuilder = new CarPersonBuilder();
+ carPersonBuilder.setCarId(notification.getCarId());
+ carPersonBuilder.setPersonId(notification.getPersonId());
+ CarPersonKey key = new CarPersonKey(notification.getCarId(), notification.getPersonId());
+ carPersonBuilder.setKey(key);
+ final CarPerson carPerson = carPersonBuilder.build();
- LOG.info("Car bought, adding car-person entry: [{}]", carPerson);
+ LOG.info("Car bought, adding car-person entry: [{}]", carPerson);
- InstanceIdentifier<CarPerson> carPersonIId =
- InstanceIdentifier.<CarPeople>builder(CarPeople.class).child(CarPerson.class, carPerson.getKey()).build();
+ InstanceIdentifier<CarPerson> carPersonIId = InstanceIdentifier.<CarPeople>builder(CarPeople.class)
+ .child(CarPerson.class, carPerson.getKey()).build();
- WriteTransaction tx = dataProvider.newWriteOnlyTransaction();
- tx.put(LogicalDatastoreType.CONFIGURATION, carPersonIId, carPerson, true);
+ WriteTransaction tx = dataProvider.newWriteOnlyTransaction();
+ tx.put(LogicalDatastoreType.CONFIGURATION, carPersonIId, carPerson, true);
- Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
- @Override
- public void onSuccess(final Void result) {
- LOG.info("Successfully added car-person entry: [{}]", carPerson);
- }
+ Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
+ @Override
+ public void onSuccess(final Void result) {
+ LOG.info("Successfully added car-person entry: [{}]", carPerson);
+ }
- @Override
- public void onFailure(final Throwable t) {
- LOG.error(String.format("Failed to add car-person entry: [%s]", carPerson), t);
- }
- });
-
- }
+ @Override
+ public void onFailure(final Throwable ex) {
+ LOG.error(String.format("Failed to add car-person entry: [%s]", carPerson), ex);
+ }
+ }, MoreExecutors.directExecutor());
+ }
}
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
import java.util.Collection;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.slf4j.LoggerFactory;
/**
+ * Implementation of CarService.
+ *
* @author Thomas Pantelis
*/
public class CarProvider implements CarService {
}
private void stopThread() {
- if(testThread != null) {
+ if (testThread != null) {
stopThread = true;
testThread.interrupt();
try {
testThread.join();
- } catch (InterruptedException e) {}
+ } catch (InterruptedException e) {
+ // don't care
+ }
testThread = null;
}
}
testThread = new Thread(() -> {
sw.start();
AtomicLong count = new AtomicLong();
- while(!stopThread) {
+ while (!stopThread) {
long id = count.incrementAndGet();
WriteTransaction tx1 = dataProvider.newWriteOnlyTransaction();
- CarEntry car = new CarEntryBuilder().setId(new CarId("car"+id)).build();
+ 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);
}
@Override
- public void onFailure(final Throwable t) {
+ public void onFailure(final Throwable ex) {
// Transaction failed
failureCounter.getAndIncrement();
- LOG_CAR_PROVIDER.error("Put Cars failed", t);
+ LOG_CAR_PROVIDER.error("Put Cars failed", ex);
}
- });
+ }, MoreExecutors.directExecutor());
try {
TimeUnit.NANOSECONDS.sleep(sleep);
} catch (InterruptedException e) {
break;
}
- if(count.get() % 1000 == 0) {
+ if (count.get() % 1000 == 0) {
LOG_PURCHASE_CAR.info("Cars created {}, time: {}",count.get(),sw.elapsed(TimeUnit.SECONDS));
}
.setSuccessCount(succcessCounter.longValue())
.setFailureCount(failureCounter.longValue());
- StopStressTestOutput result = stopStressTestOutput.build();
- LOG_PURCHASE_CAR.info("Executed Stop Stress test; No. of cars created {}; " +
- "No. of cars failed {}; ", succcessCounter, failureCounter);
+ 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);
@Override
public Future<RpcResult<Void>> registerOwnership(final RegisterOwnershipInput input) {
- if(registeredListener.compareAndSet(false, true)) {
+ if (registeredListener.compareAndSet(false, true)) {
ownershipService.registerListener(ENTITY_TYPE, ownershipListener);
}
private final DOMDataTreeChangeService domDataTreeChangeService;
private final ActorSystem actorSystem;
- private final Map<InstanceIdentifier<?>, DOMRpcImplementationRegistration<RoutedGetConstantService>> routedRegistrations =
- new HashMap<>();
+ private final Map<InstanceIdentifier<?>, DOMRpcImplementationRegistration<RoutedGetConstantService>>
+ routedRegistrations = new HashMap<>();
private final Map<String, ListenerRegistration<YnlListener>> ynlRegistrations = new HashMap<>();
}
@Override
+ @SuppressWarnings("checkstyle:IllegalCatch")
public Future<RpcResult<Void>> unregisterSingletonConstant() {
LOG.debug("unregister-singleton-constant");
if (getSingletonConstantRegistration == null) {
LOG.debug("No get-singleton-constant registration present.");
- final RpcError rpcError = RpcResultBuilder
- .newError(ErrorType.APPLICATION, "missing-registration", "No get-singleton-constant rpc registration present.");
+ final RpcError rpcError = RpcResultBuilder.newError(ErrorType.APPLICATION, "missing-registration",
+ "No get-singleton-constant rpc registration present.");
final RpcResult<Void> result = RpcResultBuilder.<Void>failed().withRpcError(rpcError).build();
return Futures.immediateFuture(result);
}
getSingletonConstantRegistration = null;
return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
- } catch (final Exception e) {
+ } catch (Exception e) {
LOG.debug("There was a problem closing the singleton constant service", e);
- final RpcError rpcError = RpcResultBuilder
- .newError(ErrorType.APPLICATION, "error-closing", "There was a problem closing get-singleton-constant");
+ final RpcError rpcError = RpcResultBuilder.newError(ErrorType.APPLICATION, "error-closing",
+ "There was a problem closing get-singleton-constant");
final RpcResult<Void> result = RpcResultBuilder.<Void>failed().withRpcError(rpcError).build();
return Futures.immediateFuture(result);
}
public Future<RpcResult<Void>> unregisterBoundConstant(final UnregisterBoundConstantInput input) {
LOG.debug("unregister-bound-constant, {}", input);
- final DOMRpcImplementationRegistration<RoutedGetConstantService> registration =
+ final DOMRpcImplementationRegistration<RoutedGetConstantService> rpcRegistration =
routedRegistrations.remove(input.getContext());
- if (registration == null) {
+ if (rpcRegistration == null) {
LOG.debug("No get-contexted-constant registration for context: {}", input.getContext());
- final RpcError rpcError = RpcResultBuilder
- .newError(ErrorType.APPLICATION, "missing-registration", "No get-constant rpc registration present.");
+ final RpcError rpcError = RpcResultBuilder.newError(ErrorType.APPLICATION, "missing-registration",
+ "No get-constant rpc registration present.");
final RpcResult<Void> result = RpcResultBuilder.<Void>failed().withRpcError(rpcError).build();
return Futures.immediateFuture(result);
}
- registration.close();
+ rpcRegistration.close();
return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
}
public Future<RpcResult<Void>> unregisterConstant() {
if (globalGetConstantRegistration == null) {
- final RpcError rpcError = RpcResultBuilder
- .newError(ErrorType.APPLICATION, "missing-registration", "No get-constant rpc registration present.");
+ final RpcError rpcError = RpcResultBuilder.newError(ErrorType.APPLICATION, "missing-registration",
+ "No get-constant rpc registration present.");
final RpcResult<Void> result = RpcResultBuilder.<Void>failed().withRpcError(rpcError).build();
return Futures.immediateFuture(result);
}
LOG.debug("unregister-flapping-singleton received.");
if (flappingSingletonService == null) {
- final RpcError rpcError = RpcResultBuilder
- .newError(ErrorType.APPLICATION, "missing-registration", "No flapping-singleton registration present.");
+ final RpcError rpcError = RpcResultBuilder.newError(ErrorType.APPLICATION, "missing-registration",
+ "No flapping-singleton registration present.");
final RpcResult<UnregisterFlappingSingletonOutput> result =
RpcResultBuilder.<UnregisterFlappingSingletonOutput>failed().withRpcError(rpcError).build();
return Futures.immediateFuture(result);
idIntsDdtl = new IdIntsDOMDataTreeLIstener();
try {
- ddtlReg =
- domDataTreeService.registerListener(idIntsDdtl,
- Collections.singleton(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION,
- ProduceTransactionsHandler.ID_INT_YID))
- , true, Collections.emptyList());
+ ddtlReg = domDataTreeService.registerListener(idIntsDdtl,
+ Collections.singleton(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION,
+ ProduceTransactionsHandler.ID_INT_YID)),
+ true, Collections.emptyList());
} catch (DOMDataTreeLoopException e) {
LOG.error("Failed to register DOMDataTreeListener.", e);
return Futures.immediateFuture(RpcResultBuilder.<Void>failed().withRpcError(error).build());
}
- final DOMRpcImplementationRegistration<RoutedGetConstantService> registration =
+ final DOMRpcImplementationRegistration<RoutedGetConstantService> rpcRegistration =
RoutedGetConstantService.registerNew(bindingNormalizedNodeSerializer, domRpcService,
input.getConstant(), input.getContext());
- routedRegistrations.put(input.getContext(), registration);
+ routedRegistrations.put(input.getContext(), rpcRegistration);
return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
}
if (idIntsListener == null || dtclReg == null) {
final RpcError error = RpcResultBuilder.newError(
ErrorType.RPC, "Dtcl missing.", "No DataTreeChangeListener registered.");
- return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDtclOutput>failed().withRpcError(error).build());
+ return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDtclOutput>failed()
+ .withRpcError(error).build());
}
try {
idIntsListener.tryFinishProcessing().get(120, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
- final RpcError error = RpcResultBuilder.newError(
- ErrorType.RPC, "resource-denied-transport", "Unable to finish notification processing in 120 seconds.",
- "clustering-it", "clustering-it", e);
+ final RpcError error = RpcResultBuilder.newError(ErrorType.RPC, "resource-denied-transport",
+ "Unable to finish notification processing in 120 seconds.", "clustering-it", "clustering-it", e);
return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDtclOutput>failed()
.withRpcError(error).build());
}
if (!idIntsListener.hasTriggered()) {
final RpcError error = RpcResultBuilder.newError(
- ErrorType.APPLICATION, "No notification received.", "id-ints listener has not received" +
- "any notifications.");
+ ErrorType.APPLICATION, "No notification received.", "id-ints listener has not received"
+ + "any notifications.");
return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDtclOutput>failed()
.withRpcError(error).build());
}
LOG.debug("Received unsubscribe-ynl, input: {}", input);
if (!ynlRegistrations.containsKey(input.getId())) {
- final RpcError rpcError = RpcResultBuilder
- .newError(ErrorType.APPLICATION, "missing-registration", "No ynl listener with this id registered.");
+ final RpcError rpcError = RpcResultBuilder.newError(ErrorType.APPLICATION, "missing-registration",
+ "No ynl listener with this id registered.");
final RpcResult<UnsubscribeYnlOutput> result =
RpcResultBuilder.<UnsubscribeYnlOutput>failed().withRpcError(rpcError).build();
return Futures.immediateFuture(result);
}
- final ListenerRegistration<YnlListener> registration = ynlRegistrations.remove(input.getId());
- final UnsubscribeYnlOutput output = registration.getInstance().getOutput();
+ final ListenerRegistration<YnlListener> reg = ynlRegistrations.remove(input.getId());
+ final UnsubscribeYnlOutput output = reg.getInstance().getOutput();
- registration.close();
+ reg.close();
return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeYnlOutput>success().withResult(output).build());
}
if (task.getLastError() != null) {
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw);
- task.getLastError().printStackTrace(pw);
+ LOG.error("Last error for {}", task, task.getLastError());
checkPublishNotificationsOutputBuilder.setLastError(task.getLastError().toString() + sw.toString());
}
}
@Override
+ @SuppressWarnings("checkstyle:IllegalCatch")
public Future<RpcResult<UnsubscribeDdtlOutput>> unsubscribeDdtl() {
LOG.debug("Received unsubscribe-ddtl.");
if (idIntsDdtl == null || ddtlReg == null) {
final RpcError error = RpcResultBuilder.newError(
ErrorType.RPC, "Ddtl missing.", "No DOMDataTreeListener registered.");
- return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDdtlOutput>failed().withRpcError(error).build());
+ return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDdtlOutput>failed()
+ .withRpcError(error).build());
}
try {
idIntsDdtl.tryFinishProcessing().get(120, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
- final RpcError error = RpcResultBuilder.newError(
- ErrorType.RPC, "resource-denied-transport", "Unable to finish notification processing in 120 seconds.",
- "clustering-it", "clustering-it", e);
+ final RpcError error = RpcResultBuilder.newError(ErrorType.RPC, "resource-denied-transport",
+ "Unable to finish notification processing in 120 seconds.", "clustering-it", "clustering-it", e);
return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDdtlOutput>failed()
.withRpcError(error).build());
}
if (!idIntsDdtl.hasTriggered()) {
final RpcError error = RpcResultBuilder.newError(
- ErrorType.APPLICATION, "No notification received.", "id-ints listener has not received" +
- "any notifications.");
+ ErrorType.APPLICATION, "No notification received.", "id-ints listener has not received"
+ + "any notifications.");
return Futures.immediateFuture(RpcResultBuilder.<UnsubscribeDdtlOutput>failed()
.withRpcError(error).build());
}
try {
distributedDataStoreClient = SimpleDataStoreClientActor
.getDistributedDataStoreClient(clientActor, 30, TimeUnit.SECONDS);
- } catch (final Exception e) {
+ } catch (RuntimeException e) {
LOG.error("Failed to get actor for {}", distributedDataStoreClientProps, e);
clientActor.tell(PoisonPill.getInstance(), noSender());
final RpcError error = RpcResultBuilder.newError(
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import java.util.concurrent.Future;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
public class PeopleProvider implements PeopleService, AutoCloseable {
- private static final Logger LOG = LoggerFactory.getLogger(PeopleProvider.class);
-
- private DataBroker dataProvider;
-
- private BindingAwareBroker.RoutedRpcRegistration<CarPurchaseService> rpcRegistration;
-
- public void setDataProvider(final DataBroker salDataProvider) {
- this.dataProvider = salDataProvider;
- }
-
-
- public void setRpcRegistration(final BindingAwareBroker.RoutedRpcRegistration<CarPurchaseService> rpcRegistration) {
- this.rpcRegistration = rpcRegistration;
- }
-
- @Override
- public Future<RpcResult<Void>> addPerson(final AddPersonInput input) {
- LOG.info("RPC addPerson : adding person [{}]", input);
-
- PersonBuilder builder = new PersonBuilder(input);
- final Person person = builder.build();
- final SettableFuture<RpcResult<Void>> futureResult = SettableFuture.create();
-
- // Each entry will be identifiable by a unique key, we have to create that identifier
- final InstanceIdentifier.InstanceIdentifierBuilder<Person> personIdBuilder =
- InstanceIdentifier.<People>builder(People.class)
- .child(Person.class, person.getKey());
- final InstanceIdentifier<Person> personId = personIdBuilder.build();
- // Place entry in data store tree
- WriteTransaction tx = dataProvider.newWriteOnlyTransaction();
- tx.put(LogicalDatastoreType.CONFIGURATION, personId, person, true);
-
- Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
- @Override
- public void onSuccess(final Void result) {
- LOG.info("RPC addPerson : person added successfully [{}]", person);
- rpcRegistration.registerPath(PersonContext.class, personId);
- LOG.info("RPC addPerson : routed rpc registered for instance ID [{}]", personId);
- futureResult.set(RpcResultBuilder.<Void>success().build());
- }
-
- @Override
- public void onFailure(final Throwable t) {
- LOG.error(String.format("RPC addPerson : person addition failed [%s]", person), t);
- futureResult.set(RpcResultBuilder.<Void>failed()
- .withError(RpcError.ErrorType.APPLICATION, t.getMessage()).build());
- }
- });
- return futureResult;
- }
-
- @Override
- public void close() throws Exception {
-
- }
+ private static final Logger LOG = LoggerFactory.getLogger(PeopleProvider.class);
+
+ private DataBroker dataProvider;
+
+ private BindingAwareBroker.RoutedRpcRegistration<CarPurchaseService> rpcRegistration;
+
+ public void setDataProvider(final DataBroker salDataProvider) {
+ this.dataProvider = salDataProvider;
+ }
+
+
+ public void setRpcRegistration(final BindingAwareBroker.RoutedRpcRegistration<CarPurchaseService> rpcRegistration) {
+ this.rpcRegistration = rpcRegistration;
+ }
+
+ @Override
+ public Future<RpcResult<Void>> addPerson(final AddPersonInput input) {
+ LOG.info("RPC addPerson : adding person [{}]", input);
+
+ PersonBuilder builder = new PersonBuilder(input);
+ final Person person = builder.build();
+ final SettableFuture<RpcResult<Void>> futureResult = SettableFuture.create();
+
+ // Each entry will be identifiable by a unique key, we have to create that identifier
+ final InstanceIdentifier.InstanceIdentifierBuilder<Person> personIdBuilder =
+ InstanceIdentifier.<People>builder(People.class)
+ .child(Person.class, person.getKey());
+ final InstanceIdentifier<Person> personId = personIdBuilder.build();
+ // Place entry in data store tree
+ WriteTransaction tx = dataProvider.newWriteOnlyTransaction();
+ tx.put(LogicalDatastoreType.CONFIGURATION, personId, person, true);
+
+ Futures.addCallback(tx.submit(), new FutureCallback<Void>() {
+ @Override
+ public void onSuccess(final Void result) {
+ LOG.info("RPC addPerson : person added successfully [{}]", person);
+ rpcRegistration.registerPath(PersonContext.class, personId);
+ LOG.info("RPC addPerson : routed rpc registered for instance ID [{}]", personId);
+ futureResult.set(RpcResultBuilder.<Void>success().build());
+ }
+
+ @Override
+ public void onFailure(final Throwable ex) {
+ LOG.error(String.format("RPC addPerson : person addition failed [%s]", person), ex);
+ futureResult.set(RpcResultBuilder.<Void>failed()
+ .withError(RpcError.ErrorType.APPLICATION, ex.getMessage()).build());
+ }
+ }, MoreExecutors.directExecutor());
+ return futureResult;
+ }
+
+ @Override
+ public void close() throws Exception {
+ }
}
package org.opendaylight.controller.clustering.it.provider;
import com.google.common.util.concurrent.SettableFuture;
+import java.util.concurrent.Future;
import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.BuyCarInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.purchase.rev140818.CarBoughtBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.concurrent.Future;
-
-
-public class PurchaseCarProvider implements CarPurchaseService, AutoCloseable{
-
- private static final Logger LOG = LoggerFactory.getLogger(PurchaseCarProvider.class);
+public class PurchaseCarProvider implements CarPurchaseService, AutoCloseable {
- private NotificationProviderService notificationProvider;
+ private static final Logger LOG = LoggerFactory.getLogger(PurchaseCarProvider.class);
+ private NotificationProviderService notificationProvider;
- public void setNotificationProvider(final NotificationProviderService salService) {
- this.notificationProvider = salService;
- }
+ public void setNotificationProvider(final NotificationProviderService salService) {
+ this.notificationProvider = salService;
+ }
- @Override
- public Future<RpcResult<Void>> buyCar(BuyCarInput input) {
- LOG.info("Routed RPC buyCar : generating notification for buying car [{}]", input);
- SettableFuture<RpcResult<Void>> futureResult = SettableFuture.create();
- CarBoughtBuilder carBoughtBuilder = new CarBoughtBuilder();
- carBoughtBuilder.setCarId(input.getCarId());
- carBoughtBuilder.setPersonId(input.getPersonId());
- notificationProvider.publish(carBoughtBuilder.build());
- futureResult.set(RpcResultBuilder.<Void>success().build());
- return futureResult;
- }
- @Override
- public void close() throws Exception {
+ @Override
+ public Future<RpcResult<Void>> buyCar(BuyCarInput input) {
+ LOG.info("Routed RPC buyCar : generating notification for buying car [{}]", input);
+ final SettableFuture<RpcResult<Void>> futureResult = SettableFuture.create();
+ CarBoughtBuilder carBoughtBuilder = new CarBoughtBuilder();
+ carBoughtBuilder.setCarId(input.getCarId());
+ carBoughtBuilder.setPersonId(input.getPersonId());
+ notificationProvider.publish(carBoughtBuilder.build());
+ futureResult.set(RpcResultBuilder.<Void>success().build());
+ return futureResult;
+ }
- }
+ @Override
+ public void close() {
+ }
}
runTimedOut(new TimeoutException("Collection did not finish in " + DEAD_TIMEOUT_SECONDS + " seconds"));
}
- abstract ListenableFuture<Void> execWrite(final long txId);
+ abstract ListenableFuture<Void> execWrite(long txId);
abstract void runFailed(Throwable cause);
import java.util.concurrent.TimeUnit;
/**
- * A simple ScheduledExecutorService, which shutds down its threads after a period of inactivity. It is safe to not
+ * A simple ScheduledExecutorService, which shuts down its threads after a period of inactivity. It is safe to not
* shutdown this
*
* @author Robert Varga
// This is a bit ugly, but allows
@Override
+ @SuppressWarnings("checkstyle:NoFinalizer")
protected void finalize() {
super.shutdownNow();
}
}
@Override
+ @SuppressWarnings("checkstyle:IllegalCatch")
public void instantiateServiceInstance() {
LOG.debug("Instantiating flapping-singleton-service.");
try {
registration.close();
registration = null;
- } catch (final Exception e) {
+ } catch (Exception e) {
LOG.warn("There was a problem closing flapping singleton service.", e);
setInactive();
flapCount = -flapCount;
}
@Override
+ @SuppressWarnings("checkstyle:IllegalCatch")
public ListenableFuture<Void> closeServiceInstance() {
LOG.debug("Closing flapping-singleton-service, flapCount: {}", flapCount);
LOG.debug("Running re-registration");
try {
registration = singletonServiceProvider.registerClusterSingletonService(this);
- } catch (final Exception e) {
+ } catch (RuntimeException e) {
LOG.warn("There was a problem re-registering flapping singleton service.", e);
setInactive();
flapCount = -flapCount - 1;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class GetConstantService implements DOMRpcImplementation {
+public final class GetConstantService implements DOMRpcImplementation {
private static final Logger LOG = LoggerFactory.getLogger(GetConstantService.class);
private static final long SECOND_AS_NANO = 1000000000;
private NormalizedNode<?, ?> localCopy = null;
- private AtomicLong lastNotifTimestamp = new AtomicLong(0);
+ private final AtomicLong lastNotifTimestamp = new AtomicLong(0);
private ScheduledFuture<?> scheduledFuture;
private ScheduledExecutorService executorService;
executorService = Executors.newSingleThreadScheduledExecutor();
final SettableFuture<Void> settableFuture = SettableFuture.create();
- scheduledFuture = executorService.scheduleAtFixedRate(new CheckFinishedTask(settableFuture), 0, 1, TimeUnit.SECONDS);
+ scheduledFuture = executorService.scheduleAtFixedRate(new CheckFinishedTask(settableFuture),
+ 0, 1, TimeUnit.SECONDS);
return settableFuture;
}
@Override
public void run() {
- if (System.nanoTime() - lastNotifTimestamp.get() > (SECOND_AS_NANO * 4)) {
+ if (System.nanoTime() - lastNotifTimestamp.get() > SECOND_AS_NANO * 4) {
scheduledFuture.cancel(false);
future.set(null);
}
}
}
-
}
private static final long SECOND_AS_NANO = 1000000000;
private NormalizedNode<?, ?> localCopy = null;
- private AtomicLong lastNotifTimestamp = new AtomicLong(0);
+ private final AtomicLong lastNotifTimestamp = new AtomicLong(0);
private ScheduledExecutorService executorService;
private ScheduledFuture<?> scheduledFuture;
executorService = Executors.newSingleThreadScheduledExecutor();
final SettableFuture<Void> settableFuture = SettableFuture.create();
- scheduledFuture = executorService.scheduleAtFixedRate(new CheckFinishedTask(settableFuture), 0, 1, TimeUnit.SECONDS);
+ scheduledFuture = executorService.scheduleAtFixedRate(new CheckFinishedTask(settableFuture),
+ 0, 1, TimeUnit.SECONDS);
return settableFuture;
}
private final SettableFuture<Void> future;
- public CheckFinishedTask(final SettableFuture<Void> future) {
+ CheckFinishedTask(final SettableFuture<Void> future) {
this.future = future;
}
final YangInstanceIdentifier yid = serializer.toYangInstanceIdentifier(input.getPrefix());
final DOMDataTreeIdentifier prefix = new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, yid);
- try (final CDSDataTreeProducer producer =
+ try (CDSDataTreeProducer producer =
(CDSDataTreeProducer) domDataTreeService.createProducer(Collections.singleton(prefix))) {
final CDSShardAccess shardAccess = producer.getShardAccess(prefix);
import static org.opendaylight.controller.clustering.it.provider.impl.AbstractTransactionHandler.ID_INTS;
import static org.opendaylight.controller.clustering.it.provider.impl.AbstractTransactionHandler.ITEM;
-import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import java.util.Collections;
import java.util.HashMap;
import org.opendaylight.controller.cluster.sharding.DistributedShardFactory.DistributedShardRegistration;
import org.opendaylight.mdsal.binding.dom.codec.api.BindingNormalizedNodeSerializer;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
-import org.opendaylight.mdsal.common.api.TransactionCommitFailedException;
import org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.mdsal.dom.api.DOMDataTreeProducer;
final YangInstanceIdentifier identifier = serializer.toYangInstanceIdentifier(input.getPrefix());
try {
- completionStage = shardFactory.createDistributedShard(
+ completionStage = shardFactory.createDistributedShard(
new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, identifier),
input.getReplicas().stream().map(MemberName::forName).collect(Collectors.toList()));
LOG.debug("Shard[{}] created successfully.", identifier);
registrations.put(identifier, registration);
- final CheckedFuture<Void, TransactionCommitFailedException> ensureFuture = ensureListExists();
+ final ListenableFuture<Void> ensureFuture = ensureListExists();
Futures.addCallback(ensureFuture, new FutureCallback<Void>() {
@Override
public void onSuccess(@Nullable final Void result) {
public void onFailure(final Throwable throwable) {
LOG.warn("Shard[{}] creation failed:", identifier, throwable);
- final RpcError error = RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, "create-shard-failed",
- "Shard creation failed", "cluster-test-app", "", throwable);
+ final RpcError error = RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION,
+ "create-shard-failed", "Shard creation failed", "cluster-test-app", "", throwable);
future.set(RpcResultBuilder.<Void>failed().withRpcError(error).build());
}
- });
-
+ }, MoreExecutors.directExecutor());
});
completionStage.exceptionally(throwable -> {
LOG.warn("Shard[{}] creation failed:", identifier, throwable);
return future;
}
- private CheckedFuture<Void, TransactionCommitFailedException> ensureListExists() {
+ private ListenableFuture<Void> ensureListExists() {
final CollectionNodeBuilder<MapEntryNode, MapNode> mapBuilder = ImmutableNodes.mapNodeBuilder(ID_INT);
cursor.merge(containerNode.getIdentifier(), containerNode);
cursor.close();
- final CheckedFuture<Void, TransactionCommitFailedException> future = tx.submit();
+ final ListenableFuture<Void> future = tx.submit();
Futures.addCallback(future, new FutureCallback<Void>() {
@Override
public void onSuccess(@Nullable final Void result) {
public void onFailure(final Throwable throwable) {
//NOOP handled by the caller of this method.
}
- });
+ }, MoreExecutors.directExecutor());
return future;
}
}
import java.util.HashSet;
import java.util.Set;
import java.util.SplittableRandom;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class ProduceTransactionsHandler extends AbstractTransactionHandler {
+public final class ProduceTransactionsHandler extends AbstractTransactionHandler {
private static final Logger LOG = LoggerFactory.getLogger(ProduceTransactionsHandler.class);
private final SettableFuture<RpcResult<ProduceTransactionsOutput>> future = SettableFuture.create();
cursor.close();
try {
- tx.submit().checkedGet(INIT_TX_TIMEOUT_SECONDS, TimeUnit.SECONDS);
- } catch (final Exception e) {
+ tx.submit().get(INIT_TX_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+ } catch (InterruptedException | ExecutionException | TimeoutException e) {
LOG.warn("Unable to fill the initial item list.", e);
closeProducer(itemProducer);
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class RoutedGetConstantService implements DOMRpcImplementation {
+public final class RoutedGetConstantService implements DOMRpcImplementation {
private static final Logger LOG = LoggerFactory.getLogger(RoutedGetConstantService.class);
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class SingletonGetConstantService implements DOMRpcImplementation, ClusterSingletonService {
+public final class SingletonGetConstantService implements DOMRpcImplementation, ClusterSingletonService {
private static final Logger LOG = LoggerFactory.getLogger(SingletonGetConstantService.class);
this.constant = constant;
}
- public static ClusterSingletonServiceRegistration registerNew(final ClusterSingletonServiceProvider singletonService,
- final DOMRpcProviderService rpcProviderService,
- final String constant) {
+ public static ClusterSingletonServiceRegistration registerNew(
+ final ClusterSingletonServiceProvider singletonService, final DOMRpcProviderService rpcProviderService,
+ final String constant) {
LOG.debug("Registering get-singleton-constant into ClusterSingletonService, value {}", constant);
return singletonService
@Nonnull
@Override
- public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(@Nonnull DOMRpcIdentifier rpc, @Nullable NormalizedNode<?, ?> input) {
+ public CheckedFuture<DOMRpcResult, DOMRpcException> invokeRpc(@Nonnull DOMRpcIdentifier rpc,
+ @Nullable NormalizedNode<?, ?> input) {
LOG.debug("get-singleton-constant invoked, current value: {}", constant);
final LeafNode<Object> value = ImmutableLeafNodeBuilder.create()
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.SplittableRandom;
+import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
tx.merge(LogicalDatastoreType.CONFIGURATION, idListItem, entry);
try {
- tx.submit().checkedGet(INIT_TX_TIMEOUT_SECONDS, TimeUnit.SECONDS);
- } catch (final Exception e) {
+ tx.submit().get(INIT_TX_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+ } catch (InterruptedException | ExecutionException | TimeoutException e) {
LOG.warn("Unable to ensure IdInts list for id: {} exists.", id, e);
return Futures.immediateFuture(RpcResultBuilder.<WriteTransactionsOutput>failed()
.withError(RpcError.ErrorType.APPLICATION, "Unexpected-exception", e).build());
tx.put(LogicalDatastoreType.CONFIGURATION, itemListId, mapBuilder.build());
try {
- tx.submit().checkedGet(INIT_TX_TIMEOUT_SECONDS, TimeUnit.SECONDS);
- } catch (final Exception e) {
+ tx.submit().get(INIT_TX_TIMEOUT_SECONDS, TimeUnit.SECONDS);
+ } catch (InterruptedException | ExecutionException | TimeoutException e) {
LOG.warn("Unable to fill the initial item list.", e);
return Futures.immediateFuture(RpcResultBuilder.<WriteTransactionsOutput>failed()
.withError(RpcError.ErrorType.APPLICATION, "Unexpected-exception", e).build());