Class | PhusionPassenger::MessageClient
In: | lib/phusion_passenger/message_client.rb
Parent: | Object

A convenience class for communicating with MessageServer servers, for example the ApplicationPool server.

### Methods

backtraces check_security_response close connected? detach new read read_scalar recv_io status write write_scalar xml

### Included Modules

Utils

### Public Class methods

new(username, password, address = "unix:

Connect to the given server. By default it connects to the current generation‘s helper server.

[Source]

        # File lib/phusion_passenger/message_client.rb, line 39
    39:         def initialize(username, password, address = "unix:#{Utils.passenger_tmpdir}/socket")
    40:                 @socket = connect_to_server(address)
    41:                 begin
    42:                         @channel = MessageChannel.new(@socket)
    43:
    44:                         result = @channel.read
    45:                         if result.nil?
    46:                                 raise EOFError
    47:                         elsif result.size != 2 || result[0] != "version"
    48:                                 raise IOError, "The message server didn't sent a valid version identifier"
    49:                         elsif result[1] != "1"
    50:                                 raise IOError, "Unsupported message server protocol version #{result[1]}"
    51:                         end
    52:
    53:                         @channel.write_scalar(username)
    54:                         @channel.write_scalar(password)
    55:
    56:                         result = @channel.read
    57:                         if result.nil?
    58:                                 raise EOFError
    59:                         elsif result[0] != "ok"
    60:                                 raise SecurityError, result[0]
    61:                         end
    62:                 rescue Exception
    63:                         @socket.close
    64:                         raise
    65:                 end
    66:         end

### Public Instance methods

backtraces()

BacktracesServer methods ###

[Source]

         # File lib/phusion_passenger/message_client.rb, line 107
    107:         def backtraces
    108:                 write("backtraces")
    109:                 check_security_response
    110:                 return read_scalar
    111:         end

check_security_response()

[Source]

         # File lib/phusion_passenger/message_client.rb, line 150
    150:         def check_security_response
    151:                 begin
    152:                         result = @channel.read
    153:                 rescue
    154:                         auto_disconnect
    155:                         raise
    156:                 end
    157:                 if result.nil?
    158:                         raise EOFError
    159:                 elsif result[0] != "Passed security"
    160:                         raise SecurityError, result[0]
    161:                 end
    162:         end

close()

[Source]

        # File lib/phusion_passenger/message_client.rb, line 68
    68:         def close
    69:                 @socket.close if @socket
    70:                 @channel = @socket = nil
    71:         end

connected?()

[Source]

        # File lib/phusion_passenger/message_client.rb, line 73
    73:         def connected?
    74:                 return !!@channel
    75:         end

detach(detach_key)

ApplicationPool::Server methods ###

[Source]

        # File lib/phusion_passenger/message_client.rb, line 79
    79:         def detach(detach_key)
    80:                 write("detach", detach_key)
    81:                 check_security_response
    82:                 result = read
    83:                 if result.nil?
    84:                         raise EOFError
    85:                 else
    86:                         return result.first == "true"
    87:                 end
    88:         end

read()

Low level I/O methods ###

[Source]

         # File lib/phusion_passenger/message_client.rb, line 115
    115:         def read
    116:                 return @channel.read
    117:         rescue
    118:                 auto_disconnect
    119:                 raise
    120:         end

read_scalar()

[Source]

         # File lib/phusion_passenger/message_client.rb, line 136
    136:         def read_scalar
    137:                 return @channel.read_scalar
    138:         rescue
    139:                 auto_disconnect
    140:                 raise
    141:         end

recv_io(klass = IO, negotiate = true)

[Source]

         # File lib/phusion_passenger/message_client.rb, line 143
    143:         def recv_io(klass = IO, negotiate = true)
    144:                 return @channel.recv_io(klass, negotiate)
    145:         rescue
    146:                 auto_disconnect
    147:                 raise
    148:         end

status()

[Source]

        # File lib/phusion_passenger/message_client.rb, line 90
    90:         def status
    91:                 write("inspect")
    92:                 check_security_response
    93:                 return read_scalar
    94:         rescue
    95:                 auto_disconnect
    96:                 raise
    97:         end

write(*args)

[Source]

         # File lib/phusion_passenger/message_client.rb, line 122
    122:         def write(*args)
    123:                 @channel.write(*args)
    124:         rescue
    125:                 auto_disconnect
    126:                 raise
    127:         end

write_scalar(*args)

[Source]

         # File lib/phusion_passenger/message_client.rb, line 129
    129:         def write_scalar(*args)
    130:                 @channel.write_scalar(*args)
    131:         rescue
    132:                 auto_disconnect
    133:                 raise
    134:         end

xml()

[Source]

         # File lib/phusion_passenger/message_client.rb, line 99
     99:         def xml
    100:                 write("toXml", true)
    101:                 check_security_response
    102:                 return read_scalar
    103:         end

[Validate]