Class: RR::DatabaseProxy
- Inherits:
-
Object
- Object
- RR::DatabaseProxy
- Includes:
- DRbUndumped
- Defined in:
- lib/rubyrep/database_proxy.rb
Overview
The proxy to a remote database connection
Constant Summary collapse
- DEFAULT_PORT =
Default tcp port to listen on
9876
Instance Attribute Summary collapse
-
#session_register ⇒ Object
A simple Hash to hold Session object Purpose: preventing them from being garbage collected when they are only referenced through Drb.
Instance Method Summary collapse
-
#create_session(config) ⇒ Object
Create a ProxyConnection according to provided configuration Hash.
-
#destroy_session(session) ⇒ Object
Destroys the given session from the session register.
-
#initialize ⇒ DatabaseProxy
constructor
A new instance of DatabaseProxy.
-
#ping ⇒ Object
Returns ‘pong’.
-
#terminate! ⇒ Object
Terminates this proxy.
Constructor Details
#initialize ⇒ DatabaseProxy
Returns a new instance of DatabaseProxy.
22 23 24 |
# File 'lib/rubyrep/database_proxy.rb', line 22 def initialize self.session_register = {} end |
Instance Attribute Details
#session_register ⇒ Object
A simple Hash to hold Session object Purpose: preventing them from being garbage collected when they are only referenced through Drb
20 21 22 |
# File 'lib/rubyrep/database_proxy.rb', line 20 def session_register @session_register end |
Instance Method Details
#create_session(config) ⇒ Object
Create a ProxyConnection according to provided configuration Hash. config
is a hash as described by ActiveRecord::Base#establish_connection
28 29 30 31 32 |
# File 'lib/rubyrep/database_proxy.rb', line 28 def create_session(config) session = ProxyConnection.new config self.session_register[session] = session session end |
#destroy_session(session) ⇒ Object
Destroys the given session from the session register
35 36 37 38 |
# File 'lib/rubyrep/database_proxy.rb', line 35 def destroy_session(session) session.destroy session_register.delete session end |
#ping ⇒ Object
Returns ‘pong’. Used to verify that a working proxy is running.
41 42 43 |
# File 'lib/rubyrep/database_proxy.rb', line 41 def ping 'pong' end |
#terminate! ⇒ Object
Terminates this proxy
46 47 48 49 |
# File 'lib/rubyrep/database_proxy.rb', line 46 def terminate! # AL: The only way I could find to kill the main thread from a sub thread Thread.main.raise SystemExit end |