Class: Daemon::Utils::CommandsServer
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- Daemon::Utils::CommandsServer
- Includes:
- EventMachine::Protocols::LineProtocol
- Defined in:
- lib/onapp/engine/utils/commands_server.rb,
lib/onapp/engine/utils/commands_server/commands.rb,
lib/onapp/engine/utils/commands_server/unix_server_client.rb
Defined Under Namespace
Classes: Commands, UNIXServerClient
Instance Attribute Summary (collapse)
-
- (Object) commands
readonly
Returns the value of attribute commands.
Class Method Summary (collapse)
Instance Method Summary (collapse)
-
- (CommandsServer) initialize(commands)
constructor
A new instance of CommandsServer.
- - (Object) receive_line(line)
Constructor Details
- (CommandsServer) initialize(commands)
Returns a new instance of CommandsServer
21 22 23 |
# File 'lib/onapp/engine/utils/commands_server.rb', line 21 def initialize(commands) @commands = commands end |
Instance Attribute Details
- (Object) commands (readonly)
Returns the value of attribute commands
13 14 15 |
# File 'lib/onapp/engine/utils/commands_server.rb', line 13 def commands @commands end |
Class Method Details
+ (Object) start!(server, port = nil) {|commands| ... }
15 16 17 18 19 |
# File 'lib/onapp/engine/utils/commands_server.rb', line 15 def self.start!(server, port = nil, &block) commands = Commands.new yield commands ::EM.start_server(server, port, self, commands) end |
Instance Method Details
- (Object) receive_line(line)
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/onapp/engine/utils/commands_server.rb', line 25 def receive_line(line) response = begin if commands.exists?(line) {response: commands.call(line) } else {error: "Unknown command: #{line.strip}"} end rescue => ex {error: "#{ex.class}: #{ex.}\n#{ex.backtrace.join("\n")}"} end send_data(response.to_json.gsub(/\r?\n/, "") + "\n") end |