A Drb server, typically used to host the application caches (sessions, application scoped variables, og cache, fragment cache, etc).
Example
require ‘nitro/server/drb
class MyDrbServer < Nitro::DrbServer
def setup_drb_objects
...
end
end
MyDrbServer.start
Methods
Public Class methods
A helper method to start the DRb server.
[ show source ]
# File lib/nitro/state.rb, line 105
105: def self.start
106: self.new.start
107: end
Public Instance methods
Parse the command line arguments.
[ show source ]
# File lib/nitro/state.rb, line 40
40: def parse_options
41: parser = OptionParser.new do |opts|
42: opts.banner = "Usage: #$0 [options]"
43: opts.separator ''
44: opts.separator 'Specific options:'
45:
46: opts.on('-D', '--debug', 'Run in debug mode.') do |p|
47: @debug = true
48: end
49:
50: opts.on('-d', '--daemon', 'Run as daemon.') do |p|
51: @daemon = true
52: end
53:
54: opts.on_tail('-h', '--help', 'Show this message.') do
55: puts opts
56: exit
57: end
58: end
59:
60: begin
61: parser.parse!(ARGV)
62: rescue OptionParser::InvalidOption
63: puts 'Invalid option, pass the --help parameter to get help!'
64: exit
65: end
66: end
[ show source ]
# File lib/nitro/state.rb, line 78
78: def setup_drb
79: setup_drb_objects()
80: DRb.thread.join
81: end
Override in your application to setup your custom objects. The default implementation only creates a session store.
[ show source ]
# File lib/nitro/state.rb, line 71
71: def setup_drb_objects
72: require 'nitro/session/drb'
73: @session_cache = SyncHash.new
74: DRb.start_service("druby://#{Session.cache_address}:#{Session.cache_port}", @session_cache)
75: puts "Drb session cache at druby://#{Session.cache_address}:#{Session.cache_port}."
76: end
Start the DRb server.
This method is also aliased as
start!
[ show source ]
# File lib/nitro/state.rb, line 88
88: def start
89: parse_options
90:
91: if @daemon
92: require "facets/core/kernel/daemonize"
93:
94: daemonize()
95:
96: # Save a process sentinel file.
97: FileUtils.touch(File.join(".temp","d#{Process.pid}.pid"))
98: end
99: setup_drb()
100: end
Alias for #start