Rename SessionHandlerInterface 04/96204/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 17 May 2021 11:36:13 +0000 (13:36 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 17 May 2021 11:36:13 +0000 (13:36 +0200)
The 'Interface' part is obvious, but it is not immediately obvious
what sort of 'session' and 'handler' we are talking about. Rename
it to StreamSessionHandler.

Change-Id: I76fe4f0a7fc87134ce15dece17bb5bdd2075b779
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/StreamSessionHandler.java [moved from restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/SessionHandlerInterface.java with 94% similarity]
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/AbstractCommonSubscriber.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/listeners/BaseListenerInterface.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/sse/SSESessionHandler.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/websockets/WebSocketFactory.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/websockets/WebSocketInitializer.java
restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/websockets/WebSocketSessionHandler.java

@@ -10,8 +10,7 @@ package org.opendaylight.restconf.nb.rfc8040.streams;
 /**
  * Interface for session handler that is responsible for sending of data over established session.
  */
-public interface SessionHandlerInterface {
-
+public interface StreamSessionHandler {
     /**
      * Identification of created session.
      */
@@ -23,5 +22,4 @@ public interface SessionHandlerInterface {
      * @param data Message data to be send.
      */
     void sendDataMessage(String data);
-
 }
index 9c456bdfde938ea782e59d2901aa7ff4206bd8ab..751ee83394e495879101c45743a90e17613a9787 100644 (file)
@@ -11,7 +11,7 @@ import com.google.common.base.Preconditions;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Set;
-import org.opendaylight.restconf.nb.rfc8040.streams.SessionHandlerInterface;
+import org.opendaylight.restconf.nb.rfc8040.streams.StreamSessionHandler;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -23,7 +23,7 @@ abstract class AbstractCommonSubscriber extends AbstractQueryParams implements B
 
     private static final Logger LOG = LoggerFactory.getLogger(AbstractCommonSubscriber.class);
 
-    private final Set<SessionHandlerInterface> subscribers = new HashSet<>();
+    private final Set<StreamSessionHandler> subscribers = new HashSet<>();
     private volatile ListenerRegistration<?> registration;
 
     @Override
@@ -32,7 +32,7 @@ abstract class AbstractCommonSubscriber extends AbstractQueryParams implements B
     }
 
     @Override
-    public final synchronized Set<SessionHandlerInterface> getSubscribers() {
+    public final synchronized Set<StreamSessionHandler> getSubscribers() {
         return new HashSet<>(this.subscribers);
     }
 
@@ -47,7 +47,7 @@ abstract class AbstractCommonSubscriber extends AbstractQueryParams implements B
     }
 
     @Override
-    public synchronized void addSubscriber(final SessionHandlerInterface subscriber) {
+    public synchronized void addSubscriber(final StreamSessionHandler subscriber) {
         final boolean isConnected = subscriber.isConnected();
         Preconditions.checkState(isConnected);
         LOG.debug("Subscriber {} is added.", subscriber);
@@ -55,7 +55,7 @@ abstract class AbstractCommonSubscriber extends AbstractQueryParams implements B
     }
 
     @Override
-    public synchronized void removeSubscriber(final SessionHandlerInterface subscriber) {
+    public synchronized void removeSubscriber(final StreamSessionHandler subscriber) {
         final boolean isConnected = subscriber.isConnected();
         Preconditions.checkState(isConnected);
         LOG.debug("Subscriber {} is removed", subscriber);
@@ -81,9 +81,9 @@ abstract class AbstractCommonSubscriber extends AbstractQueryParams implements B
      * @param data Data of incoming notifications.
      */
     synchronized void post(final String data) {
-        final Iterator<SessionHandlerInterface> iterator = subscribers.iterator();
+        final Iterator<StreamSessionHandler> iterator = subscribers.iterator();
         while (iterator.hasNext()) {
-            final SessionHandlerInterface subscriber = iterator.next();
+            final StreamSessionHandler subscriber = iterator.next();
             final boolean isConnected = subscriber.isConnected();
             if (isConnected) {
                 subscriber.sendDataMessage(data);
index ba40d1589d8a2de6cc81b567ad8ab077306ce8f7..851b48f303b3a03b1d4e46c7c7c35eddb6d7ea67 100644 (file)
@@ -8,7 +8,7 @@
 package org.opendaylight.restconf.nb.rfc8040.streams.listeners;
 
 import java.util.Set;
-import org.opendaylight.restconf.nb.rfc8040.streams.SessionHandlerInterface;
+import org.opendaylight.restconf.nb.rfc8040.streams.StreamSessionHandler;
 import org.opendaylight.yangtools.concepts.ListenerRegistration;
 
 /**
@@ -21,12 +21,12 @@ public interface BaseListenerInterface extends AutoCloseable {
      *
      * @return Set of all subscribers.
      */
-    Set<SessionHandlerInterface> getSubscribers();
+    Set<StreamSessionHandler> getSubscribers();
 
     /**
-     * Checks if exists at least one {@link SessionHandlerInterface} subscriber.
+     * Checks if exists at least one {@link StreamSessionHandler} subscriber.
      *
-     * @return {@code true} if exist at least one {@link SessionHandlerInterface} subscriber, {@code false} otherwise.
+     * @return {@code true} if exist at least one {@link StreamSessionHandler} subscriber, {@code false} otherwise.
      */
     boolean hasSubscribers();
 
@@ -45,18 +45,18 @@ public interface BaseListenerInterface extends AutoCloseable {
     String getOutputType();
 
     /**
-     * Registers {@link SessionHandlerInterface} subscriber.
+     * Registers {@link StreamSessionHandler} subscriber.
      *
      * @param subscriber SSE or WS session handler.
      */
-    void addSubscriber(SessionHandlerInterface subscriber);
+    void addSubscriber(StreamSessionHandler subscriber);
 
     /**
-     * Removes {@link SessionHandlerInterface} subscriber.
+     * Removes {@link StreamSessionHandler} subscriber.
      *
      * @param subscriber SSE or WS session handler.
      */
-    void removeSubscriber(SessionHandlerInterface subscriber);
+    void removeSubscriber(StreamSessionHandler subscriber);
 
     /**
      * Sets {@link ListenerRegistration} registration.
index fa68b7e0eceb449d4e91b8b0028578b9b529ea16..e6494924d9633c61d7d58edc0d9c610b94a21277 100644 (file)
@@ -15,7 +15,7 @@ import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 import org.glassfish.jersey.media.sse.EventOutput;
 import org.glassfish.jersey.media.sse.OutboundEvent;
-import org.opendaylight.restconf.nb.rfc8040.streams.SessionHandlerInterface;
+import org.opendaylight.restconf.nb.rfc8040.streams.StreamSessionHandler;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.BaseListenerInterface;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -24,7 +24,7 @@ import org.slf4j.LoggerFactory;
  * SSE session handler that is responsible for controlling of session, managing subscription to data-change-event or
  * notification listener, and sending of data over established SSE session.
  */
-public class SSESessionHandler implements SessionHandlerInterface {
+public class SSESessionHandler implements StreamSessionHandler {
     private static final Logger LOG = LoggerFactory.getLogger(SSESessionHandler.class);
     private static final String PING_PAYLOAD = "ping";
 
index 8ebace438b8a91103bf8068786aac440500f071a..994780f8f96814b7da6b60bdfe0497f302f7ec4f 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.restconf.nb.rfc8040.streams.websockets;
 
 import java.util.Optional;
@@ -23,7 +22,6 @@ import org.slf4j.LoggerFactory;
  * Factory that is used for creation of new web-sockets based on HTTP/HTTPS upgrade request.
  */
 class WebSocketFactory implements WebSocketCreator {
-
     private static final Logger LOG = LoggerFactory.getLogger(WebSocketFactory.class);
 
     private final ScheduledExecutorService executorService;
index 69f821ce00d82d3713fb7379e0652e74b1edda6d..66face7a36815a45d1dba445c84c61c7436e177d 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.restconf.nb.rfc8040.streams.websockets;
 
 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
@@ -21,11 +20,15 @@ import org.opendaylight.restconf.nb.rfc8040.streams.Configuration;
  * Web-socket servlet listening on ws or wss schemas for created data-change-event or notification streams.
  */
 @Singleton
-@SuppressFBWarnings({"SE_NO_SERIALVERSIONID", "SE_BAD_FIELD"})
 public class WebSocketInitializer extends WebSocketServlet {
+    private static final long serialVersionUID = 1L;
 
+    @SuppressFBWarnings(value = "SE_BAD_FIELD",
+        justification = "Servlet/WebSocket bridge, we need this service for heartbeats")
     private final ScheduledExecutorService executorService;
-    private final Configuration configuration;
+    private final int maximumFragmentLength;
+    private final int heartbeatInterval;
+    private final int idleTimeoutMillis;
 
     /**
      * Creation of the web-socket initializer.
@@ -34,10 +37,11 @@ public class WebSocketInitializer extends WebSocketServlet {
      * @param configuration          Web-socket configuration holder.
      */
     @Inject
-    public WebSocketInitializer(final ScheduledThreadPool scheduledThreadPool,
-            final Configuration configuration) {
+    public WebSocketInitializer(final ScheduledThreadPool scheduledThreadPool, final Configuration configuration) {
         this.executorService = scheduledThreadPool.getExecutor();
-        this.configuration = configuration;
+        this.maximumFragmentLength = configuration.getMaximumFragmentLength();
+        this.heartbeatInterval = configuration.getHeartbeatInterval();
+        this.idleTimeoutMillis = configuration.getIdleTimeout();
     }
 
     /**
@@ -47,8 +51,7 @@ public class WebSocketInitializer extends WebSocketServlet {
      */
     @Override
     public void configure(final WebSocketServletFactory factory) {
-        factory.getPolicy().setIdleTimeout(configuration.getIdleTimeout());
-        factory.setCreator(new WebSocketFactory(executorService, configuration.getMaximumFragmentLength(),
-                configuration.getHeartbeatInterval()));
+        factory.getPolicy().setIdleTimeout(idleTimeoutMillis);
+        factory.setCreator(new WebSocketFactory(executorService, maximumFragmentLength, heartbeatInterval));
     }
 }
index 4ab507c561fd69132f512855a18ac9350bc14f46..75b744f6e9d948ab57c9b9dcd74ca192a572107b 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.restconf.nb.rfc8040.streams.websockets;
 
 import com.google.common.base.Strings;
@@ -26,7 +25,7 @@ import org.eclipse.jetty.websocket.api.annotations.OnWebSocketClose;
 import org.eclipse.jetty.websocket.api.annotations.OnWebSocketConnect;
 import org.eclipse.jetty.websocket.api.annotations.OnWebSocketError;
 import org.eclipse.jetty.websocket.api.annotations.WebSocket;
-import org.opendaylight.restconf.nb.rfc8040.streams.SessionHandlerInterface;
+import org.opendaylight.restconf.nb.rfc8040.streams.StreamSessionHandler;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.BaseListenerInterface;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -36,8 +35,7 @@ import org.slf4j.LoggerFactory;
  * to data-change-event or notification listener, and sending of data over established web-socket session.
  */
 @WebSocket
-public class WebSocketSessionHandler implements SessionHandlerInterface {
-
+public class WebSocketSessionHandler implements StreamSessionHandler {
     private static final Logger LOG = LoggerFactory.getLogger(WebSocketSessionHandler.class);
     private static final byte[] PING_PAYLOAD = "ping".getBytes(Charset.defaultCharset());
 
@@ -149,6 +147,7 @@ public class WebSocketSessionHandler implements SessionHandlerInterface {
      *
      * @param message Message data to be send over web-socket session.
      */
+    @Override
     public synchronized void sendDataMessage(final String message) {
         if (Strings.isNullOrEmpty(message)) {
             // FIXME: should this be tolerated?