Class: Archipelago::Tranny::TransactionProxy
- Inherits:
-
Object
- Object
- Archipelago::Tranny::TransactionProxy
- Defined in:
- lib/archipelago/tranny.rb
Overview
A proxy to a transaction managed by this manager.
Used because standard DRbObjects only use object_id to identify objects, while we want the more unique transaction_id.
Will also remember the state of the transaction when it detects methods that will terminate it (:commit | :abort).
Instance Attribute Summary collapse
-
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
Instance Method Summary collapse
-
#==(o) ⇒ Object
Implemented to allow comparison between proxies.
-
#eql?(o) ⇒ Boolean
Implemented to ensure that all TransactionProxies with the same transaction_id are hashwise equal.
-
#hash ⇒ Object
Implemented to ensure that all TransactionProxies with the same transaction_id are hashwise equal.
-
#initialize(transaction) ⇒ TransactionProxy
constructor
A new instance of TransactionProxy.
-
#method_missing(meth, *args) ⇒ Object
Forwards everything to our Transaction and remembers returnvalue if necessary.
-
#state ⇒ Object
Return the cached state of the wrapped Archipelago::Tranny::Transaction if it is known, otherwise fetch it.
Constructor Details
#initialize(transaction) ⇒ TransactionProxy
Returns a new instance of TransactionProxy.
183 184 185 186 187 188 |
# File 'lib/archipelago/tranny.rb', line 183 def initialize(transaction) @manager = transaction.manager @manager_id = transaction.manager.service_id @transaction_id = transaction.transaction_id @state = :unknown end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args) ⇒ Object
Forwards everything to our Transaction and remembers returnvalue if necessary.
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/archipelago/tranny.rb', line 228 def method_missing(meth, *args) #:nodoc: rval = nil begin rval = @manager.call_instance_method(@transaction_id, meth, *args) rescue DRb::DRbConnError => e if defined?(Archipelago::Disco::MC) possible_replacements = Archipelago::Disco::MC.lookup(Archipelago::Disco::Query.new({:service_id => @manager_id})) raise e if possible_replacements.empty? @manager = possible_replacements[@manager_id][:service] retry else raise e end end case meth when :abort! @state = :aborted when :commit! @state = rval end return rval end |
Instance Attribute Details
#transaction_id ⇒ Object
Returns the value of attribute transaction_id.
182 183 184 |
# File 'lib/archipelago/tranny.rb', line 182 def transaction_id @transaction_id end |
Instance Method Details
#==(o) ⇒ Object
Implemented to allow comparison between proxies.
221 222 223 |
# File 'lib/archipelago/tranny.rb', line 221 def ==(o) eql?(o) end |
#eql?(o) ⇒ Boolean
Implemented to ensure that all TransactionProxies with the same transaction_id are hashwise equal.
211 212 213 214 215 216 217 |
# File 'lib/archipelago/tranny.rb', line 211 def eql?(o) if TransactionProxy === o o.transaction_id == @transaction_id else false end end |
#hash ⇒ Object
Implemented to ensure that all TransactionProxies with the same transaction_id are hashwise equal.
204 205 206 |
# File 'lib/archipelago/tranny.rb', line 204 def hash @transaction_id.hash end |
#state ⇒ Object
Return the cached state of the wrapped Archipelago::Tranny::Transaction if it is known, otherwise fetch it.
193 194 195 196 197 198 199 |
# File 'lib/archipelago/tranny.rb', line 193 def state if @state == :unknown method_missing(:state) else @state end end |