Sha256: 48791c244ca5f83d7713097dcc311f5dc1b1767c395990be2e1cf7b7a303e87c

Contents?: true

Size: 1.33 KB

Versions: 14

Compression:

Stored size: 1.33 KB

Contents

# -*- encoding: utf-8 -*-

# Mixin for {OnStomp::Client clients} to provide receipt management
module OnStomp::Interfaces::SubscriptionManager
  # Returns an array of {OnStomp::Components::Subscription} objects for all
  # currently active subscriptions.
  # @return [Array<OnStomp::Components::Subscription>]
  def subscriptions
    @subcription_mon.synchronize { @subscriptions.values }
  end
  
  private
  def configure_subscription_management
    @subcription_mon = Monitor.new
    @subscriptions = {}
    on_message { |m, c| dispatch_subscription m }
    on_unsubscribe { |u, c| remove_subscription u[:id] }
  end
  
  def add_subscription f, cb
    s_id = f[:id]
    dest = f[:destination]
    @subcription_mon.synchronize do
      @subscriptions[s_id] = OnStomp::Components::Subscription.new(f, cb)
    end
  end

  def remove_subscription sub_id
    @subcription_mon.synchronize do
      @subscriptions.delete sub_id
    end
  end
  
  def clear_subscriptions
    @subcription_mon.synchronize { @subscriptions.clear }
  end
  
  def dispatch_subscription m
    if m.header? :subscription
      sub = @subcription_mon.synchronize { @subscriptions[m[:subscription]] }
      sub && sub.call(m)
    else
      @subcription_mon.synchronize do
        @subscriptions.values.select { |sub| sub.include? m }
      end.each { |sub| sub.call m }
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
onstomp-1.0.12 lib/onstomp/interfaces/subscription_manager.rb
onstomp-1.0.11 lib/onstomp/interfaces/subscription_manager.rb
onstomp-1.0.10 lib/onstomp/interfaces/subscription_manager.rb
onstomp-1.0.9 lib/onstomp/interfaces/subscription_manager.rb
onstomp-1.0.8 lib/onstomp/interfaces/subscription_manager.rb
onstomp-1.0.7 lib/onstomp/interfaces/subscription_manager.rb
onstomp-1.0.6 lib/onstomp/interfaces/subscription_manager.rb
onstomp-1.0.5 lib/onstomp/interfaces/subscription_manager.rb
onstomp-1.0.4 lib/onstomp/interfaces/subscription_manager.rb
onstomp-1.0.3 lib/onstomp/interfaces/subscription_manager.rb
onstomp-1.0.2 lib/onstomp/interfaces/subscription_manager.rb
onstomp-1.0.1 lib/onstomp/interfaces/subscription_manager.rb
onstomp-1.0.0 lib/onstomp/interfaces/subscription_manager.rb
onstomp-1.0.0pre1 lib/onstomp/interfaces/subscription_manager.rb