From: Robert Varga Date: Mon, 3 Apr 2023 15:07:21 +0000 (+0200) Subject: Use instanceof pattern in AbstractFrontendHistory X-Git-Tag: v7.0.5~21 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;ds=sidebyside;h=refs%2Fchanges%2F79%2F105179%2F1;p=controller.git Use instanceof pattern in AbstractFrontendHistory Reduce the number of casts by using instanceof patterns. Change-Id: I0ce1ca0229b1e55a5b4745584b679a7872953297 Signed-off-by: Robert Varga --- diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractFrontendHistory.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractFrontendHistory.java index 5c879b8c7d..59d10cbd09 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractFrontendHistory.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/AbstractFrontendHistory.java @@ -79,10 +79,10 @@ abstract class AbstractFrontendHistory implements Identifiable handleTransactionRequest(final TransactionRequest request, final RequestEnvelope envelope, final long now) throws RequestException { - if (request instanceof TransactionPurgeRequest) { - return handleTransactionPurgeRequest((TransactionPurgeRequest) request, envelope, now); - } else if (request instanceof SkipTransactionsRequest) { - return handleSkipTransactionsRequest((SkipTransactionsRequest) request, envelope, now); + if (request instanceof TransactionPurgeRequest purgeRequest) { + return handleTransactionPurgeRequest(purgeRequest, envelope, now); + } else if (request instanceof SkipTransactionsRequest skipRequest) { + return handleSkipTransactionsRequest(skipRequest, envelope, now); } final TransactionIdentifier id = request.getTarget(); @@ -224,13 +224,12 @@ abstract class AbstractFrontendHistory implements Identifiable request, final TransactionIdentifier id) { - if (request instanceof CommitLocalTransactionRequest) { + if (request instanceof CommitLocalTransactionRequest commitLocalRequest) { LOG.debug("{}: allocating new ready transaction {}", persistenceId(), id); tree.getStats().incrementReadWriteTransactionCount(); - return createReadyTransaction(id, ((CommitLocalTransactionRequest) request).getModification()); + return createReadyTransaction(id, commitLocalRequest.getModification()); } - if (request instanceof AbstractReadTransactionRequest - && ((AbstractReadTransactionRequest) request).isSnapshotOnly()) { + if (request instanceof AbstractReadTransactionRequest readTxRequest && readTxRequest.isSnapshotOnly()) { LOG.debug("{}: allocating new open snapshot {}", persistenceId(), id); tree.getStats().incrementReadOnlyTransactionCount(); return createOpenSnapshot(id);