brb 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+ source 'http://gems.github.com'
3
+
4
+ gem "rspec", "~> 1.3.2"
5
+ gem "eventmachine"
@@ -0,0 +1,13 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ remote: http://gems.github.com/
4
+ specs:
5
+ eventmachine (0.12.10)
6
+ rspec (1.3.2)
7
+
8
+ PLATFORMS
9
+ ruby
10
+
11
+ DEPENDENCIES
12
+ eventmachine
13
+ rspec (~> 1.3.2)
@@ -15,13 +15,15 @@ A process exposes an object over the network and any ruby process (after having
15
15
  BrB only support message passing with Marshable dumpable object : String, symbol, Array, hash, Number, Object etc...
16
16
  That mean you can not send file descriptor, Thread or another funky things like that :)
17
17
 
18
+ For any question, use the Ruby BrB google group: http://groups.google.com/group/ruby-brb
19
+
18
20
  == Main Functionalities
19
21
 
20
22
  * Unlimited objects exposed
21
23
  * Processes can expose object and be client to exposed object too at the same time
22
24
  * Do not wait for return by default : just do simple message passing
23
25
  * Handle return values without blocking with the usage of a simple block
24
- * Blocking wait for return if needed by simply adding <em>_block</em> at the end of the method name
26
+ * Blocking wait for a return value if needed by simply adding <em>_block</em> at the end of the method name
25
27
  * Transmission of Exception when blocking call
26
28
  * Thread safe if used correctly with Event Machine
27
29
 
@@ -40,10 +42,16 @@ After connection are ready, just call method on the tunnel. It will just act lik
40
42
  * Taking advantage of multi-core and multi-threaded systems.
41
43
 
42
44
  == TODO
43
- * Better README and Wiki
44
45
  * Writing more examples
45
46
  * Publish Benchmarks VS drb
46
47
  * Improve logging mechanism
47
48
  * Clean up
48
49
 
50
+ == Contributors
51
+
52
+ * kwi (Guillaume Luccisano)
53
+ * bwalton (Brian Walton)
54
+ * dpree (Jens Bissinger)
55
+
56
+
49
57
  Copyright (c) 2009-2010 Guillaume Luccisano - g-mai|: guillaume.luccisano, released under the MIT license
data/lib/brb.rb CHANGED
@@ -1,4 +1,5 @@
1
+ require File.join(File.dirname(__FILE__), 'brb', 'logger.rb')
1
2
  require File.join(File.dirname(__FILE__), 'brb', 'exception.rb')
2
3
  require File.join(File.dirname(__FILE__), 'brb', 'event_machine.rb')
3
4
  require File.join(File.dirname(__FILE__), 'brb', 'service.rb')
4
- require File.join(File.dirname(__FILE__), 'brb', 'tunnel.rb')
5
+ require File.join(File.dirname(__FILE__), 'brb', 'tunnel.rb')
@@ -40,7 +40,7 @@ module BrB
40
40
  return q.pop
41
41
 
42
42
  rescue Exception => e
43
- puts e.backtrace.join("\n")
43
+ BrB.logger.error e.backtrace.join("\n")
44
44
  raise "#{e} - #{uri}"
45
45
  end
46
46
  end
@@ -65,7 +65,7 @@ module BrB
65
65
  max -= 1
66
66
  port += 1
67
67
  retry if max > 0
68
- puts e.backtrace.join("\n")
68
+ BrB.logger.error e.backtrace.join("\n")
69
69
  raise "#{e} - BrB Tcp Event machine Can not bind on #{host}:#{port}"
70
70
  end
71
71
 
@@ -0,0 +1,35 @@
1
+ require "logger"
2
+
3
+ module BrB
4
+ class << self
5
+
6
+ # returns the default logger instance
7
+ def default_logger
8
+ Logger.new(STDOUT)
9
+ end
10
+
11
+ # set a custom logger instance
12
+ def logger=(custom_logger)
13
+ @@logger = custom_logger
14
+ end
15
+
16
+ # returns the logger instance
17
+ def logger
18
+ # use default logger if no custom logger is set
19
+ @@logger = default_logger unless defined? @@logger
20
+
21
+ # this overwrites the original method with a static definition
22
+ eval %Q{
23
+ def logger
24
+ @@logger
25
+ end
26
+ }
27
+ @@logger
28
+ end
29
+ end
30
+
31
+ # alias to BrB.logger
32
+ def logger
33
+ BrB.logger
34
+ end
35
+ end
@@ -70,8 +70,8 @@ module BrB
70
70
  brb_send([ReturnCode, r, thread, idrequest])
71
71
  rescue Exception => e
72
72
  brb_send([ReturnCode, e, thread, idrequest])
73
- tputs e.to_s
74
- tputs e.backtrace.join("\n")
73
+ BrB.logger.error e.to_s
74
+ BrB.logger.error e.backtrace.join("\n")
75
75
  #raise e
76
76
  end
77
77
  else
@@ -79,8 +79,8 @@ module BrB
79
79
  begin
80
80
  (args.size > 0) ? @object.send(meth, *args) : @object.send(meth)
81
81
  rescue Exception => e
82
- tputs "#{e.to_s} => By calling #{meth} on #{@object.class} with args : #{args.inspect}"
83
- tputs e.backtrace.join("\n")
82
+ BrB.logger.error "#{e.to_s} => By calling #{meth} on #{@object.class} with args : #{args.inspect}"
83
+ BrB.logger.error e.backtrace.join("\n")
84
84
  raise e
85
85
  end
86
86
 
@@ -7,14 +7,9 @@ module BrB
7
7
  @@uri = nil
8
8
  @@em_signature = nil
9
9
  @@verbose = false
10
-
10
+
11
11
  class << self
12
12
 
13
- private
14
- def tputs(s)
15
- puts s if @@verbose
16
- end
17
-
18
13
  public
19
14
 
20
15
  # Start a server hosted on the object given,
@@ -23,12 +18,13 @@ module BrB
23
18
  return if @@em_signature
24
19
 
25
20
  @@verbose = opts[:verbose]
21
+ BrB.logger.level = @@verbose ? Logger::INFO : Logger::WARN
26
22
 
27
23
  addr = opts[:uri] || "brb://#{opts[:host] || 'localhost'}:#{opts[:port] || 6200}"
28
24
 
29
- tputs " [BrB] Start service on #{addr} ..."
25
+ BrB.logger.info " [BrB] Start service on #{addr} ..."
30
26
  @@uri, @@em_signature = BrB::Protocol::open_server(addr, BrB::Tunnel::Handler, opts.merge(:block => block))
31
- tputs " [BrB] Service started on #{@@uri}"
27
+ BrB.logger.info " [BrB] Service started on #{@@uri}"
32
28
  end
33
29
 
34
30
  def uri
@@ -39,7 +35,7 @@ module BrB
39
35
  def stop_service
40
36
  return if !@@em_signature or !EM::reactor_running?
41
37
 
42
- tputs " [BrB] Stop service on #{@@uri}"
38
+ BrB.logger.info " [BrB] Stop service on #{@@uri}"
43
39
  sign = @@em_signature
44
40
  q = Queue.new # Creation of a Queue for waiting server to stop
45
41
  EM::schedule do
@@ -52,7 +48,7 @@ module BrB
52
48
 
53
49
  # Deprecated old method
54
50
  def instance
55
- puts "DEPRECATION WARNING: BrB::Service::instance is deprecated => Just use BrB::Service"
51
+ BrB.logger.warn "DEPRECATION WARNING: BrB::Service::instance is deprecated => Just use BrB::Service"
56
52
  self
57
53
  end
58
54
  end
@@ -24,6 +24,7 @@ module BrB
24
24
  super
25
25
  @object = opts[:object]
26
26
  @verbose = opts[:verbose]
27
+ BrB.logger.level = @verbose ? Logger::INFO : Logger::WARN
27
28
  @timeout_rcv_value = opts[:timeout] || 30 # Currently not implemented due to the lack of performance of ruby Timeout
28
29
  @close_after_timeout = opts[:close_after_timeout] || false
29
30
  @uri = opts[:uri]
@@ -41,7 +42,7 @@ module BrB
41
42
 
42
43
  # EventMachine Callback, called after connection has been initialized
43
44
  def post_init
44
- tputs " [BrB] Tunnel initialized on #{@uri}"
45
+ BrB.logger.info " [BrB] Tunnel initialized on #{@uri}"
45
46
  @active = true
46
47
  if @block
47
48
  EM.defer do
@@ -58,7 +59,7 @@ module BrB
58
59
  # EventMachine unbind event
59
60
  # The connection has been closed
60
61
  def unbind
61
- tputs ' [BrB] Tunnel service closed'
62
+ BrB.logger.info ' [BrB] Tunnel service closed'
62
63
  @active = false
63
64
  if @block
64
65
  EM.defer do
@@ -69,7 +70,7 @@ module BrB
69
70
 
70
71
  # Stop the service
71
72
  def stop_service
72
- tputs ' [BrB] Stopping Tunnel service...'
73
+ BrB.logger.info ' [BrB] Stopping Tunnel service...'
73
74
  @active = false
74
75
  EM.schedule do
75
76
  close_connection
@@ -3,10 +3,6 @@
3
3
  module BrB
4
4
  module Tunnel
5
5
  module Shared
6
- def tputs(s)
7
- puts s if @verbose
8
- end
9
-
10
6
  def make_proxy(r)
11
7
  if r.is_a?(Array)
12
8
  t = []
@@ -14,7 +10,7 @@ module BrB
14
10
  t << if obj.is_a? Array
15
11
  make_proxy(obj)
16
12
  elsif !obj.is_a?(Symbol) and !obj.is_a?(String) and obj and !(Marshal::dump(obj) rescue nil)
17
- #puts " - > Make proxy for : #{obj.class}"
13
+ #BrB.logger.debug " - > Make proxy for : #{obj.class}"
18
14
  obj.to_s.to_sym
19
15
  else
20
16
  obj
@@ -0,0 +1,35 @@
1
+ require 'spec_helper'
2
+
3
+ class CustomLogger
4
+ attr_accessor :level, :history
5
+ def initialize
6
+ @history = []
7
+ end
8
+ def info(msg)
9
+ @history << msg
10
+ end
11
+ alias :error :info
12
+ alias :warn :info
13
+ alias :debug :info
14
+ end
15
+
16
+ describe :brb_logger do
17
+ before(:each) do
18
+ @original_logger = BrB.logger
19
+ end
20
+
21
+ after(:each) do
22
+ BrB.logger = @original_logger
23
+ end
24
+
25
+ it 'should be assigned a default logger' do
26
+ BrB.logger.should_not be_nil
27
+ BrB.logger.class.should == Logger
28
+ end
29
+
30
+ it 'should be possible to use a custom logger' do
31
+ BrB.logger = CustomLogger.new
32
+ BrB.logger.info('foo')
33
+ BrB.logger.history.last.should == 'foo'
34
+ end
35
+ end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: brb
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 3
8
- - 0
9
- version: 0.3.0
4
+ prerelease:
5
+ version: 0.3.1
10
6
  platform: ruby
11
7
  authors:
12
8
  - Guillaume Luccisano
@@ -14,19 +10,17 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2010-05-21 00:00:00 +02:00
13
+ date: 2011-05-18 00:00:00 -07:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
21
17
  name: eventmachine
22
18
  prerelease: false
23
19
  requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
24
21
  requirements:
25
22
  - - ">"
26
23
  - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- - 12
30
24
  version: "0.12"
31
25
  type: :runtime
32
26
  version_requirements: *id001
@@ -43,16 +37,20 @@ files:
43
37
  - examples/simple_core.rb
44
38
  - lib/brb/event_machine.rb
45
39
  - lib/brb/exception.rb
40
+ - lib/brb/logger.rb
46
41
  - lib/brb/request.rb
47
42
  - lib/brb/service.rb
48
43
  - lib/brb/tunnel/shared.rb
49
44
  - lib/brb/tunnel.rb
50
45
  - lib/brb.rb
46
+ - spec/brb/brb_logger_spec.rb
51
47
  - spec/brb/brb_massive_usage_spec.rb
52
48
  - spec/brb/brb_service_spec.rb
53
49
  - spec/brb/brb_tunnel_spec.rb
54
50
  - spec/spec_helper.rb
55
51
  - CHANGELOG.rdoc
52
+ - Gemfile
53
+ - Gemfile.lock
56
54
  - MIT-LICENSE
57
55
  - Rakefile
58
56
  - README.rdoc
@@ -67,25 +65,21 @@ rdoc_options: []
67
65
  require_paths:
68
66
  - lib
69
67
  required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
70
69
  requirements:
71
70
  - - ">="
72
71
  - !ruby/object:Gem::Version
73
- segments:
74
- - 0
75
72
  version: "0"
76
73
  required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
77
75
  requirements:
78
76
  - - ">="
79
77
  - !ruby/object:Gem::Version
80
- segments:
81
- - 1
82
- - 3
83
- - 4
84
78
  version: 1.3.4
85
79
  requirements:
86
80
  - eventmachine
87
81
  rubyforge_project: brb
88
- rubygems_version: 1.3.6
82
+ rubygems_version: 1.5.2
89
83
  signing_key:
90
84
  specification_version: 3
91
85
  summary: BrB is a simple, fully transparent and extremely fast interface for doing simple distributed ruby