watirgrid 0.0.7 → 0.0.8.pre

Sign up to get free protection for your applications and to get access to all the features.
data/lib/controller.rb CHANGED
@@ -1,104 +1,104 @@
1
- #!/usr/bin/env ruby
2
- # controller.rb
3
- # Rinda Ring Server Controlller
4
-
5
- require 'rubygems'
6
- require 'rinda/tuplespace'
7
- require 'rinda/ring'
8
- require 'logger'
9
- require 'optparse'
10
- require 'drb/acl'
11
-
12
- module Rinda
13
-
14
- ##
15
- # Extend Rinda::RingServer to allow a hostname/ipaddress
16
- # to be passed in as parameter arguments. Also pass back
17
- # attribute for ring server uri.
18
- #
19
- class RingServer
20
- attr_accessor :uri
21
-
22
- def initialize(ts, host='', port=Ring_PORT)
23
- @uri = "druby://#{host}:#{port}"
24
- @ts = ts
25
- @soc = UDPSocket.open
26
- @soc.bind(host, port)
27
- @w_service = write_service
28
- @r_service = reply_service
29
- end
30
- end
31
- end
32
-
33
- class Controller
34
-
35
- attr_accessor :drb_server_uri, :ring_server_uri
36
-
37
- def initialize(params = {})
38
- @drb_server_host = params[:drb_server_host] || external_interface
39
- @drb_server_port = params[:drb_server_port] || 0
40
- @ring_server_host = params[:ring_server_host] || external_interface
41
- @ring_server_port = params[:ring_server_port] || Rinda::Ring_PORT
42
- @acls = params[:acls]
43
-
44
- logfile = params[:logfile] || STDOUT
45
- @log = Logger.new(logfile, 'daily')
46
- @log.level = params[:loglevel] || Logger::INFO
47
- @log.datetime_format = "%Y-%m-%d %H:%M:%S "
48
-
49
- @log.debug("DRB Server Port #{@drb_server_port}\nRing Server Port #{@ring_server_port}")
50
- end
51
-
52
- ##
53
- # Start a new tuplespace on the ring server
54
- def start
55
- # create a parent Tuple Space
56
- tuple_space = Rinda::TupleSpace.new
57
-
58
- # Setup the security--remember to call before DRb.start_service()
59
- DRb.install_acl(ACL.new(@acls))
60
-
61
- # start the DRb Server
62
- drb_server = DRb.start_service(
63
- "druby://#{@drb_server_host}:#{@drb_server_port}", tuple_space)
64
-
65
- # obtain DRb Server uri
66
- @drb_server_uri = drb_server.uri
67
- @log.info("DRb server started on : #{@drb_server_uri}")
68
-
69
- # start the Ring Server
70
- ring_server = Rinda::RingServer.new(tuple_space,
71
- @ring_server_host, @ring_server_port)
72
-
73
- # obtain Ring Server uri
74
- @ring_server_uri = ring_server.uri
75
- @log.info("Ring server started on: #{@ring_server_uri}")
76
-
77
- # abort all threads on an exception
78
- Thread.abort_on_exception = true
79
-
80
- # wait for explicit stop via ctrl-c
81
- DRb.thread.join if __FILE__ == $0
82
- end
83
-
84
- ##
85
- # Stop the controller by shutting down the DRb service
86
- def stop
87
- DRb.stop_service
88
- @log.info("DRb server stopped on: #{@drb_server_uri}")
89
- end
90
-
91
- private
92
-
93
- ##
94
- # Get the external facing interface for this server
95
- def external_interface
96
- begin
97
- UDPSocket.open {|s| s.connect('ping.watirgrid.com', 1); s.addr.last }
98
- rescue
99
- '127.0.0.1'
100
- end
101
- end
102
-
103
- end
104
-
1
+ #!/usr/bin/env ruby
2
+ # controller.rb
3
+ # Rinda Ring Server Controlller
4
+
5
+ require 'rubygems'
6
+ require 'rinda/tuplespace'
7
+ require 'rinda/ring'
8
+ require 'logger'
9
+ require 'optparse'
10
+ require 'drb/acl'
11
+
12
+ module Rinda
13
+
14
+ ##
15
+ # Extend Rinda::RingServer to allow a hostname/ipaddress
16
+ # to be passed in as parameter arguments. Also pass back
17
+ # attribute for ring server uri.
18
+ #
19
+ class RingServer
20
+ attr_accessor :uri
21
+
22
+ def initialize(ts, host='', port=Ring_PORT)
23
+ @uri = "druby://#{host}:#{port}"
24
+ @ts = ts
25
+ @soc = UDPSocket.open
26
+ @soc.bind(host, port)
27
+ @w_service = write_service
28
+ @r_service = reply_service
29
+ end
30
+ end
31
+ end
32
+
33
+ class Controller
34
+
35
+ attr_accessor :drb_server_uri, :ring_server_uri
36
+
37
+ def initialize(params = {})
38
+ @drb_server_host = params[:drb_server_host] || external_interface
39
+ @drb_server_port = params[:drb_server_port] || 0
40
+ @ring_server_host = params[:ring_server_host] || external_interface
41
+ @ring_server_port = params[:ring_server_port] || Rinda::Ring_PORT
42
+ @acls = params[:acls]
43
+
44
+ logfile = params[:logfile] || STDOUT
45
+ @log = Logger.new(logfile, 'daily')
46
+ @log.level = params[:loglevel] || Logger::INFO
47
+ @log.datetime_format = "%Y-%m-%d %H:%M:%S "
48
+
49
+ @log.debug("DRB Server Port #{@drb_server_port}\nRing Server Port #{@ring_server_port}")
50
+ end
51
+
52
+ ##
53
+ # Start a new tuplespace on the ring server
54
+ def start
55
+ # create a parent Tuple Space
56
+ tuple_space = Rinda::TupleSpace.new
57
+
58
+ # Setup the security--remember to call before DRb.start_service()
59
+ DRb.install_acl(ACL.new(@acls))
60
+
61
+ # start the DRb Server
62
+ drb_server = DRb.start_service(
63
+ "druby://#{@drb_server_host}:#{@drb_server_port}", tuple_space)
64
+
65
+ # obtain DRb Server uri
66
+ @drb_server_uri = drb_server.uri
67
+ @log.info("DRb server started on : #{@drb_server_uri}")
68
+
69
+ # start the Ring Server
70
+ ring_server = Rinda::RingServer.new(tuple_space,
71
+ @ring_server_host, @ring_server_port)
72
+
73
+ # obtain Ring Server uri
74
+ @ring_server_uri = ring_server.uri
75
+ @log.info("Ring server started on: #{@ring_server_uri}")
76
+
77
+ # abort all threads on an exception
78
+ Thread.abort_on_exception = true
79
+
80
+ # wait for explicit stop via ctrl-c
81
+ DRb.thread.join if __FILE__ == $0
82
+ end
83
+
84
+ ##
85
+ # Stop the controller by shutting down the DRb service
86
+ def stop
87
+ DRb.stop_service
88
+ @log.info("DRb server stopped on: #{@drb_server_uri}")
89
+ end
90
+
91
+ private
92
+
93
+ ##
94
+ # Get the external facing interface for this server
95
+ def external_interface
96
+ begin
97
+ UDPSocket.open {|s| s.connect('ping.watirgrid.com', 1); s.addr.last }
98
+ rescue
99
+ '127.0.0.1'
100
+ end
101
+ end
102
+
103
+ end
104
+