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.new( 'redis://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
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/qup/session.rb', line 47 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
21 22 23 |
# File 'lib/qup/session.rb', line 21 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
33 34 35 36 37 38 39 |
# File 'lib/qup/session.rb', line 33 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
91 92 93 |
# File 'lib/qup/session.rb', line 91 def close @adapter.close end |
#closed? ⇒ Boolean
Public: Is the Session closed?
Returns true if the session is closed, false otherwise.
98 99 100 |
# File 'lib/qup/session.rb', line 98 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
68 69 70 |
# File 'lib/qup/session.rb', line 68 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
82 83 84 |
# File 'lib/qup/session.rb', line 82 def topic( name, &block ) destination( name, :topic, @topics, &block ) end |