Sha256: 04898fa68d65fd33625a63dc560729a22b94e7c8fbc4c937b461b41b98730058

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

#!/usr/bin/env ruby

# * George Moschovitis  <gm@navel.gr>
# (c) 2004-2005 Navel, all rights reserved.
# $Id: drbserver.rb 182 2005-07-22 10:07:50Z gmosx $

require 'drb'
require 'optparse'

require 'glue/hash'
require 'nitro/session'

# A distributes session store implemented as
# a simple DRb server.

address = '127.0.0.1'
port = 9069
debug = false

parser = OptionParser.new do |opts|

  opts.banner = 'Usage: drbserver.rb [options]'
  opts.separator ''
  opts.separator 'Specific options:'

  opts.on('-a A', '--address A', 'Listening address.') do |a|
    address = a
  end

  opts.on('-p P', '--port P', Integer, 'Listening port.') do |p|
    port = p
  end

  opts.on('-D', '--debug', 'Run in debug mode.') do |p|
    debug = true
  end
  
  opts.on_tail('-h', '--help', 'Show this message.') do
    puts opts
    exit
  end
  
end

begin
  parser.parse!(ARGV)
rescue OptionParser::InvalidOption
  puts 'Invalid option, pass the --help parameter to get help!' 
  exit
end

sessions = Glue::SafeHash.new 

if debug

  class << sessions
    def []=(k, v)
      puts "WRITE: #{k} = #{v}"
      super
    end
    
    def [](k)
      puts "READ: #{k}"
      super
    end
  end
  
end

DRb.start_service("druby://#{address}:#{port}", sessions)
DRb.thread.join

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nitro-0.21.0 lib/nitro/session/drbserver.rb
nitro-0.21.2 lib/nitro/session/drbserver.rb
nitro-0.22.0 lib/nitro/session/drbserver.rb