Documents ConnectionManager

Documents ConnectionManager

From 5c221b567a16305a80168c144fe62e04abde1f65 Mon Sep 17 00:00:00 2001
From: Ben Langfeld <blangfeld@powerhrg.com>
Date: Tue, 27 Nov 2018 22:45:06 -0200
Subject: [PATCH] Documents ConnectionManager


diff --git a/lib/message_bus/connection_manager.rb b/lib/message_bus/connection_manager.rb
index 276e5e4..8b03247 100644
--- a/lib/message_bus/connection_manager.rb
+++ b/lib/message_bus/connection_manager.rb
@@ -8,6 +8,7 @@ class MessageBus::ConnectionManager
   require 'monitor'
   include MonitorMixin
 
+  # @param [MessageBus::Instance] bus the message bus for which to manage connections
   def initialize(bus = nil)
     @clients = {}
     @subscriptions = {}
@@ -15,6 +16,9 @@ class MessageBus::ConnectionManager
     mon_initialize
   end
 
+  # Dispatches a message to any connected clients which are permitted to receive it
+  # @param [MessageBus::Message] msg the message to dispatch
+  # @return [void]
   def notify_clients(msg)
     synchronize do
       begin
@@ -43,6 +47,9 @@ class MessageBus::ConnectionManager
     end
   end
 
+  # Keeps track of a client with an active connection
+  # @param [MessageBus::Client] client the client to track
+  # @return [void]
   def add_client(client)
     synchronize do
       existing = @clients[client.client_id]
@@ -63,6 +70,9 @@ class MessageBus::ConnectionManager
     end
   end
 
+  # Removes a client
+  # @param [MessageBus::Client] c the client to remove
+  # @return [void]
   def remove_client(c)
     synchronize do
       @clients.delete c.client_id
@@ -76,12 +86,24 @@ class MessageBus::ConnectionManager
     end
   end
 
+  # Finds a client by ID
+  # @param [String] client_id the client ID to search by
+  # @return [MessageBus::Client] the client with the specified ID
   def lookup_client(client_id)
     synchronize do
       @clients[client_id]
     end
   end
 
+  # @return [Integer] the number of tracked clients
+  def client_count
+    synchronize do
+      @clients.length
+    end
+  end
+
+  private
+
   def subscribe_client(client, channel)
     synchronize do
       set = @subscriptions[client.site_id][channel]
@@ -92,10 +114,4 @@ class MessageBus::ConnectionManager
       set << client.client_id
     end
   end
-
-  def client_count
-    synchronize do
-      @clients.length
-    end
-  end
 end

GitHub