summaryrefslogtreecommitdiff
path: root/scripts/context/ruby/base/kpse/drb.rb
blob: db1ce0eec874b6a28f4136cf46b64aef50026f19 (plain)
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)