本文整理汇总了Java中org.opendaylight.controller.cluster.datastore.modification.Modification类的典型用法代码示例。如果您正苦于以下问题:Java Modification类的具体用法?Java Modification怎么用?Java Modification使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Modification类属于org.opendaylight.controller.cluster.datastore.modification包,在下文中一共展示了Modification类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: commitNextBatch
import org.opendaylight.controller.cluster.datastore.modification.Modification; //导入依赖的package包/类
void commitNextBatch(EntityOwnershipShard shard) {
if (inflightCommit != null || pendingModifications.isEmpty() || !shard.hasLeader()) {
return;
}
inflightCommit = newBatchedModifications();
Iterator<Modification> iter = pendingModifications.iterator();
while (iter.hasNext()) {
inflightCommit.addModification(iter.next());
iter.remove();
if (inflightCommit.getModifications().size()
>= shard.getDatastoreContext().getShardBatchedModificationCount()) {
break;
}
}
log.debug("Committing next BatchedModifications {}, size {}", inflightCommit.getTransactionId(),
inflightCommit.getModifications().size());
shard.tryCommitModifications(inflightCommit);
}
示例2: commitModifications
import org.opendaylight.controller.cluster.datastore.modification.Modification; //导入依赖的package包/类
void commitModifications(List<Modification> modifications, EntityOwnershipShard shard) {
if (modifications.isEmpty()) {
return;
}
boolean hasLeader = shard.hasLeader();
if (inflightCommit != null || !hasLeader) {
if (log.isDebugEnabled()) {
log.debug("{} - adding modifications to pending",
inflightCommit != null ? "A commit is inflight" : "No shard leader");
}
pendingModifications.addAll(modifications);
} else {
inflightCommit = newBatchedModifications();
inflightCommit.addModifications(modifications);
shard.tryCommitModifications(inflightCommit);
}
}
示例3: canForwardModificationToNewLeader
import org.opendaylight.controller.cluster.datastore.modification.Modification; //导入依赖的package包/类
private boolean canForwardModificationToNewLeader(Modification mod) {
// If this is a WRITE of entity owner we don't want to forward it to a new leader since the criteria used
// to determine the new owner might be stale.
if (mod instanceof WriteModification) {
WriteModification writeMod = (WriteModification)mod;
boolean canForward = !writeMod.getPath().getLastPathArgument().getNodeType().equals(ENTITY_OWNER_QNAME);
if (!canForward) {
log.debug("Not forwarding WRITE modification for {} to new leader", writeMod.getPath());
}
return canForward;
}
return true;
}
示例4: selectNewOwnerForEntitiesOwnedBy
import org.opendaylight.controller.cluster.datastore.modification.Modification; //导入依赖的package包/类
private void selectNewOwnerForEntitiesOwnedBy(final Set<String> ownedBy) {
final List<Modification> modifications = new ArrayList<>();
searchForEntitiesOwnedBy(ownedBy, (entityTypeNode, entityNode) -> {
YangInstanceIdentifier entityPath = YangInstanceIdentifier.builder(ENTITY_TYPES_PATH)
.node(entityTypeNode.getIdentifier()).node(ENTITY_NODE_ID).node(entityNode.getIdentifier())
.node(ENTITY_OWNER_NODE_ID).build();
String newOwner = newOwner(getCurrentOwner(entityPath), getCandidateNames(entityNode),
getEntityOwnerElectionStrategy(entityPath));
if (!newOwner.isEmpty()) {
LOG.debug("{}: Found entity {}, writing new owner {}", persistenceId(), entityPath, newOwner);
modifications.add(new WriteModification(entityPath,
ImmutableNodes.leafNode(ENTITY_OWNER_NODE_ID, newOwner)));
} else {
LOG.debug("{}: Found entity {} but no other candidates - not clearing owner", persistenceId(),
entityPath, newOwner);
}
});
commitCoordinator.commitModifications(modifications, this);
}
示例5: removeCandidateFromEntities
import org.opendaylight.controller.cluster.datastore.modification.Modification; //导入依赖的package包/类
private void removeCandidateFromEntities(final MemberName member) {
final List<Modification> modifications = new ArrayList<>();
searchForEntities((entityTypeNode, entityNode) -> {
if (hasCandidate(entityNode, member)) {
YangInstanceIdentifier entityId =
(YangInstanceIdentifier) entityNode.getIdentifier().getKeyValues().get(ENTITY_ID_QNAME);
YangInstanceIdentifier candidatePath = candidatePath(
entityTypeNode.getIdentifier().getKeyValues().get(ENTITY_TYPE_QNAME).toString(),
entityId, member.getName());
LOG.info("{}: Found entity {}, removing candidate {}, path {}", persistenceId(), entityId,
member, candidatePath);
modifications.add(new DeleteModification(candidatePath));
}
});
commitCoordinator.commitModifications(modifications, this);
}
示例6: verifyBatchedModifications
import org.opendaylight.controller.cluster.datastore.modification.Modification; //导入依赖的package包/类
protected void verifyBatchedModifications(final Object message, final boolean expIsReady,
final boolean expIsDoCommitOnReady, final Modification... expected) {
assertEquals("Message type", BatchedModifications.class, message.getClass());
BatchedModifications batchedModifications = (BatchedModifications)message;
assertEquals("BatchedModifications size", expected.length, batchedModifications.getModifications().size());
assertEquals("isReady", expIsReady, batchedModifications.isReady());
assertEquals("isDoCommitOnReady", expIsDoCommitOnReady, batchedModifications.isDoCommitOnReady());
for (int i = 0; i < batchedModifications.getModifications().size(); i++) {
Modification actual = batchedModifications.getModifications().get(i);
assertEquals("Modification type", expected[i].getClass(), actual.getClass());
assertEquals("getPath", ((AbstractModification)expected[i]).getPath(),
((AbstractModification)actual).getPath());
if (actual instanceof WriteModification) {
assertEquals("getData", ((WriteModification)expected[i]).getData(),
((WriteModification)actual).getData());
}
}
}
示例7: batchedModifications
import org.opendaylight.controller.cluster.datastore.modification.Modification; //导入依赖的package包/类
@SuppressWarnings("checkstyle:IllegalCatch")
private void batchedModifications(BatchedModifications batched) {
if (checkClosed()) {
if (batched.isReady()) {
getSelf().tell(PoisonPill.getInstance(), getSelf());
}
return;
}
try {
for (Modification modification: batched.getModifications()) {
modification.apply(transaction.getSnapshot());
}
totalBatchedModificationsReceived++;
if (batched.isReady()) {
if (lastBatchedModificationsException != null) {
throw lastBatchedModificationsException;
}
if (totalBatchedModificationsReceived != batched.getTotalMessagesSent()) {
throw new IllegalStateException(String.format(
"The total number of batched messages received %d does not match the number sent %d",
totalBatchedModificationsReceived, batched.getTotalMessagesSent()));
}
readyTransaction(false, batched.isDoCommitOnReady(), batched.getVersion());
} else {
getSender().tell(new BatchedModificationsReply(batched.getModifications().size()), getSelf());
}
} catch (Exception e) {
lastBatchedModificationsException = e;
getSender().tell(new akka.actor.Status.Failure(e), getSelf());
if (batched.isReady()) {
getSelf().tell(PoisonPill.getInstance(), getSelf());
}
}
}
示例8: batchModification
import org.opendaylight.controller.cluster.datastore.modification.Modification; //导入依赖的package包/类
private void batchModification(Modification modification) {
incrementModificationCount();
if (batchedModifications == null) {
batchedModifications = newBatchedModifications();
}
batchedModifications.addModification(modification);
if (batchedModifications.getModifications().size()
>= actorContext.getDatastoreContext().getShardBatchedModificationCount()) {
sendBatchedModifications();
}
}
示例9: applyModifications
import org.opendaylight.controller.cluster.datastore.modification.Modification; //导入依赖的package包/类
@SuppressWarnings("checkstyle:IllegalCatch")
void applyModifications(final Iterable<Modification> modifications) {
totalBatchedModificationsReceived++;
if (lastBatchedModificationsException == null) {
for (Modification modification : modifications) {
try {
modification.apply(transaction.getSnapshot());
} catch (RuntimeException e) {
lastBatchedModificationsException = e;
throw e;
}
}
}
}
示例10: possiblyPrunePendingCommits
import org.opendaylight.controller.cluster.datastore.modification.Modification; //导入依赖的package包/类
private void possiblyPrunePendingCommits(EntityOwnershipShard shard, boolean isLeader) {
// If we were the leader and transitioned to follower, we'll try to forward pending commits to the new leader.
// However certain commits, e.g. entity owner changes, should only be committed by a valid leader as the
// criteria used to determine the commit may be stale. Since we're no longer a valid leader, we should not
// forward such commits thus we prune the pending modifications. We still should forward local candidate change
// commits.
if (shard.hasLeader() && !isLeader) {
// We may have already submitted a transaction for replication and commit. We don't need the base Shard to
// forward it since we also have it stored in the inflightCommit and handle retries. So we just clear
// pending transactions and drop them.
shard.convertPendingTransactionsToMessages();
// Prune the inflightCommit.
if (inflightCommit != null) {
inflightCommit = pruneModifications(inflightCommit);
}
// Prune the subsequent pending modifications.
Iterator<Modification> iter = pendingModifications.iterator();
while (iter.hasNext()) {
Modification mod = iter.next();
if (!canForwardModificationToNewLeader(mod)) {
iter.remove();
}
}
}
}
示例11: pruneModifications
import org.opendaylight.controller.cluster.datastore.modification.Modification; //导入依赖的package包/类
@Nullable
private BatchedModifications pruneModifications(BatchedModifications toPrune) {
BatchedModifications prunedModifications = new BatchedModifications(toPrune.getTransactionId(),
toPrune.getVersion());
prunedModifications.setDoCommitOnReady(toPrune.isDoCommitOnReady());
prunedModifications.setReady(toPrune.isReady());
prunedModifications.setTotalMessagesSent(toPrune.getTotalMessagesSent());
for (Modification mod: toPrune.getModifications()) {
if (canForwardModificationToNewLeader(mod)) {
prunedModifications.addModification(mod);
}
}
return !prunedModifications.getModifications().isEmpty() ? prunedModifications : null;
}
示例12: testToAndFromBinary
import org.opendaylight.controller.cluster.datastore.modification.Modification; //导入依赖的package包/类
@Test
public void testToAndFromBinary() {
TipProducingDataTree dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
dataTree.setSchemaContext(TestModel.createTestContext());
DataTreeModification modification = dataTree.takeSnapshot().newModification();
ContainerNode writeData = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
new WriteModification(TestModel.TEST_PATH, writeData).apply(modification);
MapNode mergeData = ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build();
new MergeModification(TestModel.OUTER_LIST_PATH, mergeData).apply(modification);
TransactionIdentifier txId = nextTransactionId();
ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(txId, modification, true);
ReadyLocalTransactionSerializer serializer = new ReadyLocalTransactionSerializer();
byte[] bytes = serializer.toBinary(readyMessage);
Object deserialized = serializer.fromBinary(bytes, ReadyLocalTransaction.class);
assertNotNull("fromBinary returned null", deserialized);
assertEquals("fromBinary return type", BatchedModifications.class, deserialized.getClass());
BatchedModifications batched = (BatchedModifications)deserialized;
assertEquals("getTransactionID", txId, batched.getTransactionId());
assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, batched.getVersion());
List<Modification> batchedMods = batched.getModifications();
assertEquals("getModifications size", 2, batchedMods.size());
Modification mod = batchedMods.get(0);
assertEquals("Modification type", WriteModification.class, mod.getClass());
assertEquals("Modification getPath", TestModel.TEST_PATH, ((WriteModification)mod).getPath());
assertEquals("Modification getData", writeData, ((WriteModification)mod).getData());
mod = batchedMods.get(1);
assertEquals("Modification type", MergeModification.class, mod.getClass());
assertEquals("Modification getPath", TestModel.OUTER_LIST_PATH, ((MergeModification)mod).getPath());
assertEquals("Modification getData", mergeData, ((MergeModification)mod).getData());
}
示例13: verifyOneBatchedModification
import org.opendaylight.controller.cluster.datastore.modification.Modification; //导入依赖的package包/类
protected void verifyOneBatchedModification(final ActorRef actorRef, final Modification expected,
final boolean expIsReady) {
List<BatchedModifications> batchedModifications = captureBatchedModifications(actorRef);
assertEquals("Captured BatchedModifications count", 1, batchedModifications.size());
verifyBatchedModifications(batchedModifications.get(0), expIsReady, expIsReady, expected);
}
示例14: commitModification
import org.opendaylight.controller.cluster.datastore.modification.Modification; //导入依赖的package包/类
void commitModification(Modification modification, EntityOwnershipShard shard) {
commitModifications(ImmutableList.of(modification), shard);
}