Class: RDKit::Server
- Inherits:
-
Object
- Object
- RDKit::Server
- Defined in:
- lib/rdkit/server.rb
Constant Summary collapse
- HZ =
10
- CYCLES_TIL_MEMORY_RESAMPLE =
1000
Instance Attribute Summary collapse
-
#core ⇒ Object
readonly
Returns the value of attribute core.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#runner ⇒ Object
readonly
Returns the value of attribute runner.
-
#server_up_since ⇒ Object
readonly
Returns the value of attribute server_up_since.
Instance Method Summary collapse
-
#initialize(host, port) ⇒ Server
constructor
A new instance of Server.
- #introspection ⇒ Object
- #sanity_check! ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(host, port) ⇒ Server
Returns a new instance of Server.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rdkit/server.rb', line 13 def initialize(host, port) @host, @port = host, port @cycles = 0 @peak_memory = 0 @peak_connected_clients = 0 @clients, @command_parsers = Hash.new, Hash.new @logger = Logger.new Introspection.register(self) @server_up_since = Time.now end |
Instance Attribute Details
#core ⇒ Object (readonly)
Returns the value of attribute core.
10 11 12 |
# File 'lib/rdkit/server.rb', line 10 def core @core end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
11 12 13 |
# File 'lib/rdkit/server.rb', line 11 def host @host end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
11 12 13 |
# File 'lib/rdkit/server.rb', line 11 def port @port end |
#runner ⇒ Object (readonly)
Returns the value of attribute runner.
9 10 11 |
# File 'lib/rdkit/server.rb', line 9 def runner @runner end |
#server_up_since ⇒ Object (readonly)
Returns the value of attribute server_up_since.
8 9 10 |
# File 'lib/rdkit/server.rb', line 8 def server_up_since @server_up_since end |
Instance Method Details
#introspection ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rdkit/server.rb', line 56 def introspection { server: { rdkit_version: RDKit::VERSION, multiplexing_api: 'select', process_id: Process.pid, tcp_port: @port, uptime_in_seconds: (Time.now - @server_up_since).to_i, uptime_in_days: ((Time.now - @server_up_since) / (24 * 60 * 60)).to_i, hz: HZ, }, clients: { connected_clients: @clients.size, connected_clients_peak: @peak_connected_clients }, memory: { used_memory_rss: used_memory_rss_in_mb, used_memory_peak: used_memory_peak_in_mb }, } end |
#sanity_check! ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rdkit/server.rb', line 29 def sanity_check! unless @host && @port raise SDKRequirementNotMetError, '@host and @port are required for server to run' end if @core.nil? raise SDKRequirementNotMetError, '@core is required to represent your business logics' end if @runner.nil? raise SDKRequirementNotMetError, '@runner is required to act as an RESP frontend' end end |
#start ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/rdkit/server.rb', line 43 def start sanity_check! @server_socket = TCPServer.new(@host, @port) run_acceptor end |
#stop ⇒ Object
51 52 53 54 |
# File 'lib/rdkit/server.rb', line 51 def stop @logger.warn "signal caught, shutting down..." exit end |