Class: Qup::Session
- Inherits:
-
Object
- Object
- Qup::Session
- Defined in:
- lib/qup/session.rb
Overview
Public: Manage communicating with a provider
Examples:
Session.new( 'maildir:///tmp/qup' )
Session.new( 'kestrel://user:pass@host:port/' )
session.queue( 'foo' ) # => Queue
session.topic( 'bar' ) # => Topic
At the moment, a Session is not considered thread safe, so each Thread should create its own Session.
Defined Under Namespace
Classes: ClosedError
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
Public: The URI of this Session.
Class Method Summary collapse
-
.open(uri, options = {}, &block) ⇒ Object
Public: Create a new Session.
Instance Method Summary collapse
-
#close ⇒ Object
Public: Close the Session.
-
#closed? ⇒ Boolean
Public: Is the Session closed?.
-
#initialize(uri, options = {}) ⇒ Session
constructor
Public: Create a new Session.
-
#queue(name, &block) ⇒ Object
Public: Allocate a new Queue.
-
#topic(name, &block) ⇒ Object
Public: Allocate a new Topic.
Constructor Details
#initialize(uri, options = {}) ⇒ Session
Public: Create a new Session
uri - The connection String used to connect to appropriate provider options - The Hash of options that are passed to the underlying Adapter
Returns a new Session
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/qup/session.rb', line 46 def initialize( uri, = {} ) @uri = URI.parse( uri ) @root_path = Pathname.new( @uri.path ) adapter_klass = Qup::Adapters[@uri.scheme] @adapter = adapter_klass.new( @uri, ) @queues = Hash.new @topics = Hash.new end |
Instance Attribute Details
#uri ⇒ Object (readonly)
Public: The URI of this Session
20 21 22 |
# File 'lib/qup/session.rb', line 20 def uri @uri end |
Class Method Details
.open(uri, options = {}, &block) ⇒ Object
Public: Create a new Session
uri - The connection String used to connect to appropriate provider options - The Hash of options that are passed to the underlying Adapter
Yields the created Session
If a session is yielded, it is closed at the end of the block
Returns a new Session
32 33 34 35 36 37 38 |
# File 'lib/qup/session.rb', line 32 def self.open( uri, = {}, &block ) session = ::Qup::Session.new( uri, ) return session unless block_given? yield session ensure session.close if block_given? end |
Instance Method Details
#close ⇒ Object
Public: Close the Session
Calling closed on an already closed Session does nothing.
Returns nothing
90 91 92 |
# File 'lib/qup/session.rb', line 90 def close @adapter.close end |
#closed? ⇒ Boolean
Public: Is the Session closed?
Returns true if the session is closed, false otherwise.
97 98 99 |
# File 'lib/qup/session.rb', line 97 def closed? @adapter.closed? end |
#queue(name, &block) ⇒ Object
Public: Allocate a new Queue
Connect to an existing, or Create a new Queue with the given name and options.
Yields the Queue.
name - The String name of the Queue to connect/create
Returns a new Queue instance
67 68 69 |
# File 'lib/qup/session.rb', line 67 def queue( name, &block ) destination( name, :queue, @queues, &block ) end |
#topic(name, &block) ⇒ Object
Public: Allocate a new Topic
Connect to an existing, or Create a new Topic with the given name and options.
Yields the Topic.
name - The String name of the Topic to connect/create
Returns a new Topic instance
81 82 83 |
# File 'lib/qup/session.rb', line 81 def topic( name, &block ) destination( name, :topic, @topics, &block ) end |