brb 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,7 @@
1
+ 0.2.2 (Apr 21, 2010)
2
+
3
+ * Change silent option to verbose
4
+
1
5
  0.2.1 (Apr 16, 2010)
2
6
 
3
7
  * Automatically start EM if not started
@@ -5,7 +5,7 @@ host = 'localhost'
5
5
 
6
6
  # Connecting to the core server, retrieving its interface object : core
7
7
  # We do not want to expose an object, so the first parameter is nil
8
- core = BrB::Tunnel.create(nil, "brb://#{host}:#{port}", :silent => false)
8
+ core = BrB::Tunnel.create(nil, "brb://#{host}:#{port}", :verbose => true)
9
9
 
10
10
  # Calling 10 times an non blocking method on the distant core server
11
11
  10.times do
@@ -24,5 +24,5 @@ port = 5555
24
24
  host = 'localhost'
25
25
 
26
26
  puts " > Starting the core on brb://#{host}:#{port}"
27
- BrB::Service.start_service(:object => ExposedCoreObject.new, :silent => false, :host => host, :port => port)
27
+ BrB::Service.start_service(:object => ExposedCoreObject.new, :verbose => true, :host => host, :port => port)
28
28
  EM.reactor_thread.join
@@ -27,7 +27,6 @@ module BrB
27
27
  begin
28
28
  r = recv(block, Thread.current[:brb_nb_out])
29
29
  rescue Exception => e
30
- #@object.log_error(e, "Error sending out request #{meth}(#{args.inspect})")
31
30
  raise e
32
31
  ensure
33
32
  #TimeMonitor.instance.remove_thread!
@@ -52,7 +51,6 @@ module BrB
52
51
  idrequest = args.pop
53
52
  thread = args.pop
54
53
  begin
55
- #TimeMonitor.instance.watch_thread!(25)
56
54
  r = ((args.size > 0) ? @object.send(m, *args) : @object.send(m))
57
55
  brb_send([:r, r, thread, idrequest])
58
56
  rescue Exception => e
@@ -60,8 +58,6 @@ module BrB
60
58
  tputs e.to_s
61
59
  tputs e.backtrace.join("\n")
62
60
  #raise e
63
- ensure
64
- #TimeMonitor.instance.remove_thread!
65
61
  end
66
62
  else
67
63
 
@@ -6,13 +6,13 @@ module BrB
6
6
  class Service
7
7
  @@uri = nil
8
8
  @@em_signature = nil
9
- @@silent = true
9
+ @@verbose = false
10
10
 
11
11
  class << self
12
12
 
13
13
  private
14
14
  def tputs(s)
15
- puts s if !@@silent
15
+ puts s if @@verbose
16
16
  end
17
17
 
18
18
  public
@@ -22,10 +22,10 @@ module BrB
22
22
  def start_service(opts = {}, &block)
23
23
  return if @@em_signature
24
24
 
25
- @@silent = opts[:silent]
26
-
27
- addr = "brb://#{opts[:host] || 'localhost'}:#{opts[:port] || 6200}"
28
-
25
+ @@verbose = opts[:verbose]
26
+
27
+ addr = opts[:uri] || "brb://#{opts[:host] || 'localhost'}:#{opts[:port] || 6200}"
28
+
29
29
  tputs " [BrB] Start service on #{addr} ..."
30
30
  @@uri, @@em_signature = BrB::Protocol::open_server(addr, BrB::Tunnel::Handler, opts.merge(:block => block))
31
31
  tputs " [BrB] Service started on #{@@uri}"
@@ -6,6 +6,9 @@ require File.join(File.dirname(__FILE__), 'tunnel', 'shared.rb')
6
6
  module BrB
7
7
  module Tunnel
8
8
 
9
+ # Create a BrB Tunnel by connecting to a distant BrB service
10
+ # Pass a block if you want to get register and unregister events
11
+ # The first parameter object is the object you want to expose in the BrB tunnel
9
12
  def self.create(object, uri = nil, opts = {}, &block)
10
13
  BrB::Protocol.open(uri, BrB::Tunnel::Handler, opts.merge(:object => object, :block => block))
11
14
  end
@@ -20,20 +23,19 @@ module BrB
20
23
  def initialize(opts = {})
21
24
  super
22
25
  @object = opts[:object]
23
- @silent = opts[:silent]
24
- @timeout_rcv_value = opts[:timeout] || 30
26
+ @verbose = opts[:verbose]
27
+ @timeout_rcv_value = opts[:timeout] || 30 # Currently not implemented due to the lack of performance of ruby Timeout
25
28
  @close_after_timeout = opts[:close_after_timeout] || false
26
29
  @uri = opts[:uri]
27
- @closed = nil
28
30
  @replock = Mutex.new
29
31
  @responses = {}
30
32
  @block = opts[:block]
31
- @mu = Mutex.new
32
33
 
33
34
  @queue = Queue.new
34
35
  @buffer = ''
35
36
  end
36
37
 
38
+ # EventMachine Callback, called after connection has been initialized
37
39
  def post_init
38
40
  tputs " [BrB] Tunnel initialized on #{@uri}"
39
41
  @active = true
@@ -49,6 +51,8 @@ module BrB
49
51
  super
50
52
  end
51
53
 
54
+ # EventMachine unbind event
55
+ # The connection has been closed
52
56
  def unbind
53
57
  tputs ' [BrB] Tunnel service closed'
54
58
  @active = false
@@ -59,18 +63,21 @@ module BrB
59
63
  end
60
64
  end
61
65
 
66
+ # Stop the service
62
67
  def stop_service
63
- tputs ' [BrB] Stop Tunnel service'
68
+ tputs ' [BrB] Stopping Tunnel service...'
64
69
  @active = false
65
70
  EM.schedule do
66
71
  close_connection
67
72
  end
68
73
  end
69
74
 
75
+ # Return true if the tunnel is currently active
70
76
  def active?
71
77
  @active
72
78
  end
73
79
 
80
+ # When no method is found on tunnel interface, create an brb out request
74
81
  def method_missing(meth, *args)
75
82
  return nil if !@active
76
83
  new_brb_out_request(meth, *args)
@@ -4,7 +4,7 @@ module BrB
4
4
  module Tunnel
5
5
  module Shared
6
6
  def tputs(s)
7
- puts s if !@silent
7
+ puts s if @verbose
8
8
  end
9
9
 
10
10
  def make_proxy(r)
@@ -88,14 +88,12 @@ module BrB
88
88
  if rep[1] == nb_out # On check ke c'est bien la réponse que l'on attend
89
89
  return rep[0]
90
90
  end
91
- #Error.create(:backtrace => "Error in Brb receiving in thread #{Thread.current}. Try to get #{nb_out} request id, but get #{rep[1]}", :type => 'BrBRecvBadId', :url => "#{@object.class}-#{@uri}")
92
91
  if rep[1] > nb_out
93
92
  return nil
94
93
  end
95
94
  end
96
95
  rescue Exception => e
97
96
  if @close_after_timeout == true
98
- #Error.create(:backtrace => "Error in Rcv in thread #{Thread.current}. Try to get #{nb_out} => Stop service #{e.class.to_s}\n\n#{e.backtrace.join("\n")}", :type => e.to_s, :url => "#{@object.class}-#{@uri}")
99
97
  stop_service
100
98
  sleep 1
101
99
  raise e
@@ -6,11 +6,11 @@ Thread.abort_on_exception = true
6
6
  require File.dirname(__FILE__) + '/../init.rb'
7
7
 
8
8
  def open_service(object, host = 'localhost', port = 6200)
9
- BrB::Service.start_service(:object => object, :silent => true, :host => host, :port => port)
9
+ BrB::Service.start_service(:object => object, :verbose => false, :host => host, :port => port)
10
10
  end
11
11
 
12
12
  def connect_to_the_service(object_exposed, uri, &block)
13
- BrB::Tunnel.create(object_exposed, uri, :silent => true, &block)
13
+ BrB::Tunnel.create(object_exposed, uri, :verbose => false, &block)
14
14
  end
15
15
 
16
16
  class BrBTest
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 1
9
- version: 0.2.1
8
+ - 2
9
+ version: 0.2.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Guillaume Luccisano
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-04-19 00:00:00 +02:00
17
+ date: 2010-04-21 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -22,11 +22,12 @@ dependencies:
22
22
  prerelease: false
23
23
  requirement: &id001 !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ">="
25
+ - - ">"
26
26
  - !ruby/object:Gem::Version
27
27
  segments:
28
28
  - 0
29
- version: "0"
29
+ - 12
30
+ version: "0.12"
30
31
  type: :runtime
31
32
  version_requirements: *id001
32
33
  description: BrB is a simple, fully transparent and extremely fast interface for doing simple distributed ruby and message passing