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
-
#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.
185 186 187 188 189 190 |
# File 'lib/archipelago/tranny.rb', line 185 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.
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/archipelago/tranny.rb', line 224 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.
184 185 186 |
# File 'lib/archipelago/tranny.rb', line 184 def transaction_id @transaction_id end |
Instance Method Details
#eql?(o) ⇒ Boolean
Implemented to ensure that all TransactionProxies with the same transaction_id are hashwise equal.
213 214 215 216 217 218 219 |
# File 'lib/archipelago/tranny.rb', line 213 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.
206 207 208 |
# File 'lib/archipelago/tranny.rb', line 206 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.
195 196 197 198 199 200 201 |
# File 'lib/archipelago/tranny.rb', line 195 def state if @state == :unknown method_missing(:state) else @state end end |