Class: Archipelago::Tranny::Manager
- Inherits:
-
Object
- Object
- Archipelago::Tranny::Manager
- Includes:
- Disco::Publishable
- Defined in:
- lib/archipelago/tranny.rb
Overview
The manager itself.
This will be the drb exported object that participants talk to, either directly or through a TransactionProxy.
See also the TransactionProxy and Transaction classes.
Instance Attribute Summary collapse
-
#error_logger ⇒ Object
Returns the value of attribute error_logger.
-
#transaction_timeout ⇒ Object
Returns the value of attribute transaction_timeout.
Instance Method Summary collapse
-
#begin(options = {}) ⇒ Object
Returns a proxy to a newly created Transaction.
-
#call_instance_method(transaction_id, meth, *args) ⇒ Object
Used by a transaction proxy to run
meth
withargs
on itstransaction_id
. -
#initialize(options = {}) ⇒ Manager
constructor
Will use a BerkeleyHashishProvider using tranny_manager.db in the same dir to get its hashes if not :persistence_directory is given.
-
#log_error(exception) ⇒ Object
Used by transactions to notify this manager about an error.
-
#remove_transaction!(transaction) ⇒ Object
Used by a
transaction
to remove its state when finished. -
#store_transaction!(transaction) ⇒ Object
Used by a
transaction
to store its state for future reference.
Methods included from Disco::Publishable
#_dump, append_features, #close!, #publish!, #service_id, #unpublish!, #valid?
Constructor Details
#initialize(options = {}) ⇒ Manager
Will use a BerkeleyHashishProvider using tranny_manager.db in the same dir to get its hashes if not :persistence_directory is given.
Will create Transactions timing out after :transaction_timeout seconds or TRANSACTION_TIMEOUT if none is given.
Will use Archipelago::Disco::Publishable by calling initialize_publishable with options
.
109 110 111 112 113 114 115 |
# File 'lib/archipelago/tranny.rb', line 109 def initialize( = {}) initialize_publishable() @transaction_timeout = [:transaction_timeout] || TRANSACTION_TIMEOUT @db = @persistence_provider.get_cached_hashish(:name => "db") end |
Instance Attribute Details
#error_logger ⇒ Object
Returns the value of attribute error_logger.
97 98 99 |
# File 'lib/archipelago/tranny.rb', line 97 def error_logger @error_logger end |
#transaction_timeout ⇒ Object
Returns the value of attribute transaction_timeout.
98 99 100 |
# File 'lib/archipelago/tranny.rb', line 98 def transaction_timeout @transaction_timeout end |
Instance Method Details
#begin(options = {}) ⇒ Object
Returns a proxy to a newly created Transaction.
The Transaction will timeout after :timeout seconds or @transaction_timeout if none is given.
123 124 125 126 127 |
# File 'lib/archipelago/tranny.rb', line 123 def begin( = {}) [:manager] = self [:timeout] ||= @transaction_timeout return Transaction.new().proxy end |
#call_instance_method(transaction_id, meth, *args) ⇒ Object
Used by a transaction proxy to run meth
with args
on its transaction_id
.
158 159 160 161 162 163 164 165 |
# File 'lib/archipelago/tranny.rb', line 158 def call_instance_method(transaction_id, meth, *args) transaction = @db[transaction_id] if transaction return transaction.send(meth, *args) else raise UnknownTransactionException.new(transaction_id, self) end end |
#log_error(exception) ⇒ Object
Used by transactions to notify this manager about an error. Delegates the actual logging to @error_logger.call(exception).
Set @error_logger or override this method if you want to log any errors.
137 138 139 |
# File 'lib/archipelago/tranny.rb', line 137 def log_error(exception) self.error_logger.call(exception) if self.error_logger end |
#remove_transaction!(transaction) ⇒ Object
Used by a transaction
to remove its state when finished.
151 152 153 |
# File 'lib/archipelago/tranny.rb', line 151 def remove_transaction!(transaction) @db.delete(transaction.transaction_id) end |
#store_transaction!(transaction) ⇒ Object
Used by a transaction
to store its state for future reference.
144 145 146 |
# File 'lib/archipelago/tranny.rb', line 144 def store_transaction!(transaction) @db[transaction.transaction_id] = transaction end |