Class: Qup::Adapter::Maildir::Topic
- Inherits:
-
Object
- Object
- Qup::Adapter::Maildir::Topic
- Includes:
- TopicAPI
- Defined in:
- lib/qup/adapter/maildir/topic.rb
Overview
Internal: A Topic for use in a publish-subscribe Messaging
The topic delivers each Message that it is give to each and every Subscriber
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Internal: the name of the Topic.
Instance Method Summary collapse
-
#destroy ⇒ Object
Internal: Destroy the Topic.
-
#initialize(root_path, name) ⇒ Topic
constructor
Internal: Create a new Topic.
-
#publish(message) ⇒ Object
Internal: Publish a Message to all the Subscribers.
-
#publisher ⇒ Object
Internal: Creates a Publisher for the Topic.
-
#subscriber(name) ⇒ Object
Internal: Create a subscriber for the Topic.
-
#subscriber_count ⇒ Object
Internal: Return the number of Subscribers to this Topic.
Constructor Details
#initialize(root_path, name) ⇒ Topic
Internal: Create a new Topic
root_path - the Session this Topic is attached to name - the String name of the Topic
Returns a new Topic.
19 20 21 22 23 24 25 26 |
# File 'lib/qup/adapter/maildir/topic.rb', line 19 def initialize( root_path, name ) @root_path = ::Pathname.new( root_path ) @name = name @topic_path = @root_path + @name @subscribers = Hash.new FileUtils.mkdir_p( @topic_path ) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Internal: the name of the Topic
11 12 13 |
# File 'lib/qup/adapter/maildir/topic.rb', line 11 def name @name end |
Instance Method Details
#destroy ⇒ Object
Internal: Destroy the Topic
If possible remove the existence of the Topic from the System
Returns nothing.
33 34 35 |
# File 'lib/qup/adapter/maildir/topic.rb', line 33 def destroy @topic_path.rmtree end |
#publish(message) ⇒ Object
Internal: Publish a Message to all the Subscribers
message - the Object to send to all subscribers
Returns nothing
71 72 73 74 75 |
# File 'lib/qup/adapter/maildir/topic.rb', line 71 def publish( ) @subscribers.each do |name, sub| sub.produce( ) end end |
#publisher ⇒ Object
Internal: Creates a Publisher for the Topic
Returns a new Publisher
40 41 42 |
# File 'lib/qup/adapter/maildir/topic.rb', line 40 def publisher ::Qup::Publisher.new( self ) end |
#subscriber(name) ⇒ Object
Internal: Create a subscriber for the Topic
name - the String name of the subscriber
Creating a subscriber creates a new Subscriber that will receive a copy of every message that is published to the Topic.
Subscribers are unique by name, two subscribers with the same name will act as individual Consumers on a queue of their name.
Returns a Subscriber
55 56 57 |
# File 'lib/qup/adapter/maildir/topic.rb', line 55 def subscriber( name ) ::Qup::Subscriber.new( self, sub_queue( name ) ) end |
#subscriber_count ⇒ Object
Internal: Return the number of Subscribers to this Topic
Returns integer
62 63 64 |
# File 'lib/qup/adapter/maildir/topic.rb', line 62 def subscriber_count @subscribers.size end |