Unmask NotificationListenerAdapter 02/96202/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 17 May 2021 09:41:47 +0000 (11:41 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 17 May 2021 09:42:01 +0000 (11:42 +0200)
Use .orElseThrow() to acquire a nice instance, without needing to issue
multiple .get()s.

JIRA: NETCONF-773
Change-Id: If67fb5391642e437ce27c2d9f21688c875de4561
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/rests/services/impl/RestconfDataStreamServiceImpl.java

index 6b06b5278a0b6c6e0eed7259a5de8dfb0fcfef32..85c6cfbdb1109409790370cb2c4a69d77be9542e 100644 (file)
@@ -7,7 +7,6 @@
  */
 package org.opendaylight.restconf.nb.rfc8040.rests.services.impl;
 
-import java.util.Optional;
 import java.util.concurrent.ScheduledExecutorService;
 import javax.inject.Inject;
 import javax.inject.Singleton;
@@ -46,16 +45,15 @@ public class RestconfDataStreamServiceImpl implements RestconfDataStreamService
     @Override
     public EventOutput getSSE(final String identifier, final UriInfo uriInfo) {
         final String streamName = ListenersBroker.createStreamNameFromUri(identifier);
-        final Optional<BaseListenerInterface> listener = listenersBroker.getListenerFor(streamName);
-
-        if (listener.isEmpty()) {
-            LOG.debug("Listener for stream with name {} was not found.", streamName);
-            throw new RestconfDocumentedException("Data missing", ErrorType.APPLICATION, ErrorTag.DATA_MISSING);
-        }
+        final BaseListenerInterface listener = listenersBroker.getListenerFor(streamName)
+            .orElseThrow(() -> {
+                LOG.debug("Listener for stream with name {} was not found.", streamName);
+                throw new RestconfDocumentedException("Data missing", ErrorType.APPLICATION, ErrorTag.DATA_MISSING);
+            });
 
         LOG.debug("Listener for stream with name {} has been found, SSE session handler will be created.", streamName);
         final EventOutput eventOutput = new EventOutput();
-        final SSESessionHandler handler = new SSESessionHandler(executorService, eventOutput, listener.get(),
+        final SSESessionHandler handler = new SSESessionHandler(executorService, eventOutput, listener,
             maximumFragmentLength, heartbeatInterval);
         handler.init();
         return eventOutput;