Reuse local RestconfStrategy 94/96194/1
authorRobert Varga <robert.varga@pantheon.tech>
Sat, 15 May 2021 07:38:58 +0000 (09:38 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sat, 15 May 2021 07:43:19 +0000 (09:43 +0200)
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 <robert.varga@pantheon.tech>
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataServiceImpl.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/transactions/MdsalRestconfStrategy.java

index 6bcfe9e9d3897017c9fb6bd56d42b9213d7e8b89..cce8ebc8c1dafa8befe6399240399b6d4f84f2cb 100644 (file)
@@ -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(() -> {
index 9029d65314f9e826a8aaba8ed1c80a0877d7f4f8..2e705bb78550ec779929542d6ac3fd9a89c1c373 100644 (file)
@@ -42,7 +42,7 @@ public final class MdsalRestconfStrategy extends RestconfStrategy {
 
     @Override
     public ListenableFuture<Optional<NormalizedNode<?, ?>>> read(final LogicalDatastoreType store,
-                                                                 final YangInstanceIdentifier path) {
+            final YangInstanceIdentifier path) {
         try (DOMDataTreeReadTransaction tx = dataBroker.newReadOnlyTransaction()) {
             return tx.read(store, path);
         }