From bf609a15bf47541400eb3d128741e27b80b187fc Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sat, 15 May 2021 09:38:58 +0200 Subject: [PATCH 1/1] Reuse local RestconfStrategy RestconfStrategy is now completely stateless, hence we can reuse the same object, reducing GC pressure a bit. JIRA: NETCONF-773 Change-Id: Ic6c7968f1279bd0aa7c5f58452af499d16079464 Signed-off-by: Robert Varga --- .../rests/services/impl/RestconfDataServiceImpl.java | 9 ++++----- .../rests/transactions/MdsalRestconfStrategy.java | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java index 6bcfe9e9d3..cce8ebc8c1 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java @@ -104,19 +104,18 @@ public class RestconfDataServiceImpl implements RestconfDataService { private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MMM-dd HH:mm:ss"); private final RestconfStreamsSubscriptionService delegRestconfSubscrService; - private final SubscribeToStreamUtil streamUtils; - private final SchemaContextHandler schemaContextHandler; + private final MdsalRestconfStrategy restconfStrategy; private final DOMMountPointService mountPointService; + private final SubscribeToStreamUtil streamUtils; private final DOMActionService actionService; - private final DOMDataBroker dataBroker; public RestconfDataServiceImpl(final SchemaContextHandler schemaContextHandler, final DOMDataBroker dataBroker, final DOMMountPointService mountPointService, final RestconfStreamsSubscriptionService delegRestconfSubscrService, final DOMActionService actionService, final Configuration configuration) { this.schemaContextHandler = requireNonNull(schemaContextHandler); - this.dataBroker = requireNonNull(dataBroker); + this.restconfStrategy = new MdsalRestconfStrategy(dataBroker); this.mountPointService = requireNonNull(mountPointService); this.delegRestconfSubscrService = requireNonNull(delegRestconfSubscrService); this.actionService = requireNonNull(actionService); @@ -371,7 +370,7 @@ public class RestconfDataServiceImpl implements RestconfDataService { // FIXME: why is this synchronized? public synchronized RestconfStrategy getRestconfStrategy(final DOMMountPoint mountPoint) { if (mountPoint == null) { - return new MdsalRestconfStrategy(dataBroker); + return restconfStrategy; } return RestconfStrategy.forMountPoint(mountPoint).orElseThrow(() -> { diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/MdsalRestconfStrategy.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/MdsalRestconfStrategy.java index 9029d65314..2e705bb785 100644 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/MdsalRestconfStrategy.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/MdsalRestconfStrategy.java @@ -42,7 +42,7 @@ public final class MdsalRestconfStrategy extends RestconfStrategy { @Override public ListenableFuture>> read(final LogicalDatastoreType store, - final YangInstanceIdentifier path) { + final YangInstanceIdentifier path) { try (DOMDataTreeReadTransaction tx = dataBroker.newReadOnlyTransaction()) { return tx.read(store, path); } -- 2.36.6