Class: Riak::Node::Console
- Inherits:
-
Object
- Object
- Riak::Node::Console
- Includes:
- Util::Translation
- Defined in:
- lib/riak/node/console.rb
Overview
Eases working with the Erlang console when attached to the Riak node.
Instance Attribute Summary (collapse)
-
- (String) nodename
The name of the connected node.
Class Method Summary (collapse)
-
+ (Console) open(node)
Opens a Console by connecting to the node.
Instance Method Summary (collapse)
-
- (Object) close
Closes the console by detaching from the pipes.
-
- (Object) command(cmd)
Sends an Erlang command to the console.
-
- (Console) initialize(pipedir, nodename)
constructor
Creates a Console from the IO pipes connected to the node.
-
- (Boolean) open?
Detects whether the console connection is still open, that is, if the node hasn't disconnected from the other side of the pipe.
-
- (Object) wait_for(pattern)
Scans the output of the console for the given pattern.
-
- (Object) wait_for_erlang_prompt
Scans the output of the console until an Erlang shell prompt is found.
Methods included from Util::Translation
Constructor Details
- (Console) initialize(pipedir, nodename)
Creates a Riak::Node::Console from the IO pipes connected to the node.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/riak/node/console.rb', line 30 def initialize(pipedir, nodename) @nodename = nodename @mutex = Mutex.new @winch = Signal.trap("WINCH", &method(:handle_winch)) @prompt = /\(#{Regexp.escape(nodename)}\)\d+>\s*/ pipedir = Pathname(pipedir) pipedir.children.each do |path| if path.pipe? if path.fnmatch("*.r") # Read pipe # debug "Found read pipe: #{path}" @rfile ||= path elsif path.fnmatch("*.w") # Write pipe # debug "Found write pipe: #{path}" @wfile ||= path end else debug "Non-pipe found! #{path}" end end raise ArgumentError, t('no_pipes', :path => pipedir.to_s) if [@rfile, @wfile].any? {|p| p.nil? } # We have to open the read pipe AFTER we have sent some data # to the write pipe, otherwise JRuby hangs. begin debug "Opening write pipe." @w = open_write_pipe @w.sync = true debug "Opening read pipe." @r = open_read_pipe command 'ok.' debug "Initialized console: #{@r.inspect} #{@w.inspect}" rescue => e debug e. close raise t('no_pipes', :path => pipedir.to_s) + "[ #{e.} ]" end end |
Instance Attribute Details
- (String) nodename
The name of the connected node
17 18 19 |
# File 'lib/riak/node/console.rb', line 17 def nodename @nodename end |
Class Method Details
+ (Console) open(node)
Opens a Riak::Node::Console by connecting to the node.
21 22 23 |
# File 'lib/riak/node/console.rb', line 21 def self.open(node) new node.pipe, node.name end |
Instance Method Details
- (Object) close
Closes the console by detaching from the pipes.
103 104 105 106 107 108 |
# File 'lib/riak/node/console.rb', line 103 def close @r.close if @r && !@r.closed? @w.close if @w && !@w.closed? Signal.trap("WINCH", @winch) freeze end |
- (Object) command(cmd)
Sends an Erlang command to the console
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/riak/node/console.rb', line 69 def command(cmd) @mutex.synchronize do begin debug "Sending command #{cmd.inspect}" @w.print "#{cmd}\n" wait_for_erlang_prompt rescue SystemCallError close end end end |
- (Boolean) open?
Detects whether the console connection is still open, that is, if the node hasn't disconnected from the other side of the pipe.
84 85 86 |
# File 'lib/riak/node/console.rb', line 84 def open? (@r && !@r.closed?) && (@w && !@w.closed?) end |
- (Object) wait_for(pattern)
Scans the output of the console for the given pattern.
97 98 99 100 |
# File 'lib/riak/node/console.rb', line 97 def wait_for(pattern) debug "Scanning for #{pattern.inspect}" @r.expect(pattern) end |