Class: MysqlPause::Proxy
- Inherits:
-
EM::Connection
- Object
- EM::Connection
- MysqlPause::Proxy
- Defined in:
- lib/mysql-pause/proxy.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(be_host, be_port, options) ⇒ Proxy
constructor
A new instance of Proxy.
- #post_init ⇒ Object
- #receive_data(data) ⇒ Object
- #unbind ⇒ Object
Constructor Details
#initialize(be_host, be_port, options) ⇒ Proxy
Returns a new instance of Proxy.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mysql-pause/proxy.rb', line 15 def initialize(be_host, be_port, ) @options = @logger = Logger.new($stdout) n = 0 begin ping(be_host, be_port) @backend = EM.connect(be_host, be_port, MysqlPause::Backend, self) raise('connection error') if @backend.error? rescue => e @logger.error("#{e.class.name}: #{e.}") if n < RETRY_LIMIT close_backend_connection sleep RETRY_INTERVAL @logger.warn("connection retry") n += 1 retry else @logger.error("connection abort") raise e end end end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
13 14 15 |
# File 'lib/mysql-pause/proxy.rb', line 13 def logger @logger end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
12 13 14 |
# File 'lib/mysql-pause/proxy.rb', line 12 def @options end |
Instance Method Details
#post_init ⇒ Object
41 42 43 44 45 |
# File 'lib/mysql-pause/proxy.rb', line 41 def post_init if @options[:debug] @logger.debug("proxy: connect") end end |
#receive_data(data) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/mysql-pause/proxy.rb', line 53 def receive_data(data) EM.defer { if @options[:pause] @logger.info("pause: #{data.inspect}") sleep(@options[:interval]) while @options[:pause] @logger.info("resume: #{data.inspect}") end if @backend.error? @logger.info("backend error: #{data.inspect}") close_backend_connection payload_length, sequence_id = parse_mysql_packet(data) = MysqlPause::Error.(MysqlPause::Error::ABORTED_BACKEND_CONNECTION, sequence_id + 1) send_data() close_connection_after_writing else @backend.send_data(data) end } end |
#unbind ⇒ Object
47 48 49 50 51 |
# File 'lib/mysql-pause/proxy.rb', line 47 def unbind if @options[:debug] @logger.debug("proxy: unbind") end end |