Class: Skein::Connected
- Inherits:
-
Object
- Object
- Skein::Connected
- Defined in:
- lib/skein/connected.rb
Direct Known Subclasses
Client, Skein::Client::Publisher, Skein::Client::RPC, Skein::Client::Subscriber, Skein::Client::Worker
Instance Attribute Summary collapse
-
#channel ⇒ Object
readonly
Returns the value of attribute channel.
-
#connection ⇒ Object
readonly
Returns the value of attribute connection.
-
#context ⇒ Object
readonly
Properties ===========================================================.
-
#ident ⇒ Object
readonly
Returns the value of attribute ident.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(connection: nil, context: nil) ⇒ Connected
constructor
Instance Methods =====================================================.
- #lock ⇒ Object
Constructor Details
#initialize(connection: nil, context: nil) ⇒ Connected
Instance Methods =====================================================
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/skein/connected.rb', line 11 def initialize(connection: nil, context: nil) @mutex = Mutex.new @shared_connection = !!connection @connection = connection || Skein::RabbitMQ.connect @channel = @connection.create_channel @context = context || Skein::Context.new @ident = @context.ident(self) end |
Instance Attribute Details
#channel ⇒ Object (readonly)
Returns the value of attribute channel.
7 8 9 |
# File 'lib/skein/connected.rb', line 7 def channel @channel end |
#connection ⇒ Object (readonly)
Returns the value of attribute connection.
6 7 8 |
# File 'lib/skein/connected.rb', line 6 def connection @connection end |
#context ⇒ Object (readonly)
Properties ===========================================================
4 5 6 |
# File 'lib/skein/connected.rb', line 4 def context @context end |
#ident ⇒ Object (readonly)
Returns the value of attribute ident.
5 6 7 |
# File 'lib/skein/connected.rb', line 5 def ident @ident end |
Instance Method Details
#close ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/skein/connected.rb', line 28 def close lock do begin @channel and @channel.close rescue => e if (defined?(MarchHare)) case e when MarchHare::ChannelLevelException, MarchHare::ChannelAlreadyClosed # Ignored since we're finished with the channel anyway else raise e end end end @channel = nil unless (@shared_connection) @connection and @connection.close @connection = nil end end end |
#lock ⇒ Object
22 23 24 25 26 |
# File 'lib/skein/connected.rb', line 22 def lock @mutex.synchronize do yield end end |