File: drb.rb

package info (click to toggle)
context-modules 20250324-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 32,712 kB
  • sloc: ruby: 15,247; xml: 1,509; sh: 42; makefile: 22
file content (57 lines) | stat: -rw-r--r-- 1,096 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require 'drb'
require 'base/kpse/trees'

class KpseServer

    attr_accessor :port

    def initialize(port=7000)
        @port = port
    end

    def start
        puts "starting drb service at port #{@port}"
        DRb.start_service("druby://localhost:#{@port}", KpseTrees.new)
        trap(:INT) do
            DRb.stop_service
        end
        DRb.thread.join
    end

    def stop
        # todo
    end

end

class KpseClient

    attr_accessor :port

    def initialize(port=7000)
        @port = port
        @kpse = nil
    end

    def start
        # only needed when callbacks are used / slow, due to Socket::getaddrinfo
        # DRb.start_service
    end

    def object
        @kpse = DRbObject.new(nil,"druby://localhost:#{@port}")
    end

end


# SERVER_URI="druby://localhost:8787"
#
#   # Start a local DRbServer to handle callbacks.
#   #
#   # Not necessary for this small example, but will be required
#   # as soon as we pass a non-marshallable object as an argument
#   # to a dRuby call.
#   DRb.start_service
#
#   timeserver = DRbObject.new_with_uri(SERVER_URI)