package org.opendaylight.controller.clustering.it.provider;
import com.google.common.base.Stopwatch;
-import com.google.common.collect.ImmutableClassToInstanceMap;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import org.opendaylight.mdsal.common.api.CommitInfo;
import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
import org.opendaylight.mdsal.dom.api.DOMDataBroker;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohortRegistration;
-import org.opendaylight.mdsal.dom.api.DOMDataTreeCommitCohortRegistry;
+import org.opendaylight.mdsal.dom.api.DOMDataBroker.CommitCohortExtension;
import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
import org.opendaylight.mdsal.eos.binding.api.Entity;
import org.opendaylight.mdsal.eos.binding.api.EntityOwnershipListener;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.UnregisterOwnershipOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.cars.CarEntry;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.cars.CarEntryBuilder;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yangtools.concepts.ObjectRegistration;
import org.opendaylight.yangtools.concepts.Registration;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.Rpc;
import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
private static final String ENTITY_TYPE = "cars";
private static final InstanceIdentifier<Cars> CARS_IID = InstanceIdentifier.builder(Cars.class).build();
- private static final DataTreeIdentifier<Cars> CARS_DTID = DataTreeIdentifier.create(
+ private static final DataTreeIdentifier<Cars> CARS_DTID = DataTreeIdentifier.of(
LogicalDatastoreType.CONFIGURATION, CARS_IID);
private final DataBroker dataProvider;
private final AtomicLong succcessCounter = new AtomicLong();
private final AtomicLong failureCounter = new AtomicLong();
- private final EntityOwnershipListener ownershipListener =
- ownershipChange -> LOG.info("ownershipChanged: {}", ownershipChange);
+ private final EntityOwnershipListener ownershipListener = (entity, change, inJeopardy) ->
+ LOG.info("ownershipChanged: entity={} change={} inJeopardy={}", entity, change, inJeopardy);
private final AtomicBoolean registeredListener = new AtomicBoolean();
-
- private final Set<ListenerRegistration<?>> carsDclRegistrations = ConcurrentHashMap.newKeySet();
-
+ private final AtomicReference<Registration> commitCohortReg = new AtomicReference<>();
+ private final Set<ObjectRegistration<?>> carsDclRegistrations = ConcurrentHashMap.newKeySet();
private final Set<Registration> regs = new HashSet<>();
- private final Set<ListenerRegistration<CarDataTreeChangeListener>> carsDtclRegistrations =
- ConcurrentHashMap.newKeySet();
+ private final Set<Registration> carsDtclRegistrations = ConcurrentHashMap.newKeySet();
private volatile Thread testThread;
private volatile boolean stopThread;
- private final AtomicReference<DOMDataTreeCommitCohortRegistration<CarEntryDataTreeCommitCohort>> commitCohortReg =
- new AtomicReference<>();
@Inject
@Activate
this.dataProvider = dataProvider;
this.ownershipService = ownershipService;
this.domDataBroker = domDataBroker;
- regs.add(rpcProviderService.registerRpcImplementations(ImmutableClassToInstanceMap.<Rpc<?, ?>>builder()
- .put(StressTest.class, this::stressTest)
- .put(StopStressTest.class, this::stopStressTest)
- .put(RegisterOwnership.class, this::registerOwnership)
- .put(UnregisterOwnership.class, this::unregisterOwnership)
- .put(RegisterLoggingDtcl.class, this::registerLoggingDtcl)
- .put(UnregisterLoggingDtcls.class, this::unregisterLoggingDtcls)
- .put(RegisterCommitCohort.class, this::registerCommitCohort)
- .put(UnregisterCommitCohort.class, this::unregisterCommitCohort)
- .build()));
+ regs.add(rpcProviderService.registerRpcImplementations(
+ (StressTest) this::stressTest,
+ (StopStressTest) this::stopStressTest,
+ (RegisterOwnership) this::registerOwnership,
+ (UnregisterOwnership) this::unregisterOwnership,
+ (RegisterLoggingDtcl) this::registerLoggingDtcl,
+ (UnregisterLoggingDtcls) this::unregisterLoggingDtcls,
+ (RegisterCommitCohort) this::registerCommitCohort,
+ (UnregisterCommitCohort) this::unregisterCommitCohort));
}
@PreDestroy
private ListenableFuture<RpcResult<RegisterLoggingDtclOutput>> registerLoggingDtcl(
final RegisterLoggingDtclInput input) {
LOG.info("Registering a new CarDataTreeChangeListener");
- final ListenerRegistration<CarDataTreeChangeListener> carsDtclRegistration =
- dataProvider.registerDataTreeChangeListener(CARS_DTID, new CarDataTreeChangeListener());
-
- carsDtclRegistrations.add(carsDtclRegistration);
+ final var reg = dataProvider.registerTreeChangeListener(CARS_DTID, new CarDataTreeChangeListener());
+ carsDtclRegistrations.add(reg);
return RpcResultBuilder.success(new RegisterLoggingDtclOutputBuilder().build()).buildFuture();
}
LOG.info("Unregistering the CarDataTreeChangeListener(s)");
synchronized (carsDtclRegistrations) {
int numListeners = 0;
- for (ListenerRegistration<CarDataTreeChangeListener> carsDtclRegistration : carsDtclRegistrations) {
+ for (var carsDtclRegistration : carsDtclRegistrations) {
carsDtclRegistration.close();
numListeners++;
}
}
private void closeCommitCohortRegistration() {
- final DOMDataTreeCommitCohortRegistration<CarEntryDataTreeCommitCohort> reg = commitCohortReg.getAndSet(null);
+ final var reg = commitCohortReg.getAndSet(null);
if (reg != null) {
reg.close();
LOG.info("Unregistered commit cohort");
return RpcResultBuilder.success(new RegisterCommitCohortOutputBuilder().build()).buildFuture();
}
- final DOMDataTreeCommitCohortRegistry commitCohortRegistry = domDataBroker.getExtensions().getInstance(
- DOMDataTreeCommitCohortRegistry.class);
-
+ final var commitCohortRegistry = domDataBroker.extension(CommitCohortExtension.class);
if (commitCohortRegistry == null) {
// Shouldn't happen
return RpcResultBuilder.<RegisterCommitCohortOutput>failed().withError(ErrorType.APPLICATION,
// to address all list entries, the second path argument is wild-carded by specifying just the CarEntry.QNAME.
final YangInstanceIdentifier carEntryPath = YangInstanceIdentifier.builder(
YangInstanceIdentifier.of(Cars.QNAME)).node(CarEntry.QNAME).node(CarEntry.QNAME).build();
- commitCohortReg.set(commitCohortRegistry.registerCommitCohort(new DOMDataTreeIdentifier(
+ commitCohortReg.set(commitCohortRegistry.registerCommitCohort(DOMDataTreeIdentifier.of(
LogicalDatastoreType.CONFIGURATION, carEntryPath), new CarEntryDataTreeCommitCohort()));
LOG.info("Registered commit cohort");