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
-
#options ⇒ Object
readonly
Internal: access the adapter specific options.
-
#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
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/qup/session.rb', line 50 def initialize( uri, = {} ) @uri = URI.parse( uri ) @root_path = Pathname.new( @uri.path ) @options = adapter_klass = Qup::Adapters[@uri.scheme] @adapter = adapter_klass.new( @uri, @options ) @queues = Hash.new @topics = Hash.new end |
Instance Attribute Details
#options ⇒ Object (readonly)
Internal: access the adapter specific options.
24 25 26 |
# File 'lib/qup/session.rb', line 24 def @options end |
#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
36 37 38 39 40 41 42 |
# File 'lib/qup/session.rb', line 36 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
95 96 97 |
# File 'lib/qup/session.rb', line 95 def close @adapter.close end |
#closed? ⇒ Boolean
Public: Is the Session closed?
Returns true if the session is closed, false otherwise.
102 103 104 |
# File 'lib/qup/session.rb', line 102 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
72 73 74 |
# File 'lib/qup/session.rb', line 72 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
86 87 88 |
# File 'lib/qup/session.rb', line 86 def topic( name, &block ) destination( name, :topic, @topics, &block ) end |