mailbox 0.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +7 -0
- data/Rakefile +27 -0
- data/VERSION.yml +1 -0
- data/lib/mailbox.rb +78 -0
- data/mailbox.gemspec +45 -0
- data/test/mailbox_test.rb +75 -0
- metadata +63 -0
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "rubygems"
|
2
|
+
require "rake/testtask"
|
3
|
+
require "jeweler"
|
4
|
+
|
5
|
+
task :default => :test
|
6
|
+
|
7
|
+
Rake::TestTask.new do |t|
|
8
|
+
t.libs << "test"
|
9
|
+
t.test_files = FileList['test/**/*_test.rb']
|
10
|
+
t.verbose = true
|
11
|
+
end
|
12
|
+
|
13
|
+
Jeweler::Tasks.new do |gemspec|
|
14
|
+
gemspec.name = "mailbox"
|
15
|
+
gemspec.summary = "Mailbox is a JRuby module that simplifies concurrency and is backed by JVM threads."
|
16
|
+
gemspec.description = gemspec.summary
|
17
|
+
gemspec.email = "asher.friedman@gmail.com"
|
18
|
+
gemspec.homepage = "http://joelash.github.com/mailbox"
|
19
|
+
gemspec.authors = ["Joel Friedman", "Patrick Farley"]
|
20
|
+
|
21
|
+
gemspec.rubyforge_project = "mailbox"
|
22
|
+
end
|
23
|
+
|
24
|
+
Jeweler::RubyforgeTasks.new do |rubyforge|
|
25
|
+
rubyforge.doc_task = "rdoc"
|
26
|
+
end
|
27
|
+
|
data/VERSION.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/mailbox.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'jretlang'
|
3
|
+
|
4
|
+
module Mailbox
|
5
|
+
|
6
|
+
def self.included(base)
|
7
|
+
base.extend(Mailbox::ClassMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
def register_channel(channel_name, channel)
|
11
|
+
channel_registry = self.class.__channel_registry__
|
12
|
+
channel_registry.each_pair { |key, value| __subscribe__(channel, key) if value == channel_name }
|
13
|
+
end
|
14
|
+
|
15
|
+
def __subscribe__(channel, method)
|
16
|
+
channel.subscribe_on_fiber(__fiber__) { |*args| self.send(method, *args) }
|
17
|
+
end
|
18
|
+
|
19
|
+
def __started_fiber__
|
20
|
+
fiber = JRL::Fiber.new
|
21
|
+
fiber.start
|
22
|
+
fiber
|
23
|
+
end
|
24
|
+
|
25
|
+
def __fiber__
|
26
|
+
@fiber ||= __started_fiber__
|
27
|
+
end
|
28
|
+
|
29
|
+
module ClassMethods
|
30
|
+
|
31
|
+
attr_accessor :__channel_registry__
|
32
|
+
|
33
|
+
def mailslot(params={})
|
34
|
+
@next_channel_name = params[:channel]
|
35
|
+
@mailslot = true
|
36
|
+
end
|
37
|
+
|
38
|
+
def method_added(method_name, &block)
|
39
|
+
return if @adding_mailbox_to_method == method_name
|
40
|
+
|
41
|
+
unless @mailslot == true
|
42
|
+
private method_name
|
43
|
+
return
|
44
|
+
end
|
45
|
+
|
46
|
+
@mailslot = false
|
47
|
+
|
48
|
+
if @next_channel_name.nil?
|
49
|
+
__setup_on_fiber__(method_name)
|
50
|
+
else
|
51
|
+
__setup_on_channel__(method_name)
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def __setup_on_fiber__(method_name)
|
57
|
+
alias_method :"__#{method_name}__", method_name
|
58
|
+
|
59
|
+
@adding_mailbox_to_method = method_name
|
60
|
+
|
61
|
+
define_method( method_name, lambda do |*args|
|
62
|
+
__fiber__.execute { self.send(:"__#{method_name}__", *args ) }
|
63
|
+
end )
|
64
|
+
|
65
|
+
@adding_mailbox_to_method = nil
|
66
|
+
end
|
67
|
+
|
68
|
+
def __setup_on_channel__(method_name)
|
69
|
+
private method_name
|
70
|
+
@__channel_registry__ ||= {}
|
71
|
+
__channel_registry__[method_name] = @next_channel_name
|
72
|
+
@next_channel_name = nil
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
data/mailbox.gemspec
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{mailbox}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Joel Friedman", "Patrick Farley"]
|
12
|
+
s.date = %q{2009-10-13}
|
13
|
+
s.description = %q{Mailbox is a JRuby module that simplifies concurrency and is backed by JVM threads.}
|
14
|
+
s.email = %q{asher.friedman@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"README",
|
20
|
+
"Rakefile",
|
21
|
+
"VERSION.yml",
|
22
|
+
"lib/mailbox.rb",
|
23
|
+
"mailbox.gemspec",
|
24
|
+
"test/mailbox_test.rb"
|
25
|
+
]
|
26
|
+
s.homepage = %q{http://joelash.github.com/mailbox}
|
27
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
28
|
+
s.require_paths = ["lib"]
|
29
|
+
s.rubyforge_project = %q{mailbox}
|
30
|
+
s.rubygems_version = %q{1.3.3}
|
31
|
+
s.summary = %q{Mailbox is a JRuby module that simplifies concurrency and is backed by JVM threads.}
|
32
|
+
s.test_files = [
|
33
|
+
"test/mailbox_test.rb"
|
34
|
+
]
|
35
|
+
|
36
|
+
if s.respond_to? :specification_version then
|
37
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
38
|
+
s.specification_version = 3
|
39
|
+
|
40
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
41
|
+
else
|
42
|
+
end
|
43
|
+
else
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
require File.dirname(__FILE__) + "/../lib/mailbox"
|
5
|
+
|
6
|
+
module Latches
|
7
|
+
include_package 'java.util.concurrent'
|
8
|
+
end
|
9
|
+
|
10
|
+
class MailboxTest < Test::Unit::TestCase
|
11
|
+
|
12
|
+
def test_mailslot_causes_execution_on_separate_thread
|
13
|
+
|
14
|
+
klass = Class.new do
|
15
|
+
include Mailbox
|
16
|
+
|
17
|
+
mailslot
|
18
|
+
def test_method(latch, thread_ids)
|
19
|
+
thread_ids << Thread.current.object_id
|
20
|
+
latch.count_down
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
thread_ids = []
|
25
|
+
latch = Latches::CountDownLatch.new( 1 )
|
26
|
+
klass.new.test_method(latch, thread_ids)
|
27
|
+
|
28
|
+
assert( latch.await( 1, Latches::TimeUnit::SECONDS ), "Timed out" )
|
29
|
+
assert_not_equal Thread.current.object_id, thread_ids.first
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_non_mailslot_methods_become_private
|
34
|
+
|
35
|
+
klass = Class.new do
|
36
|
+
include Mailbox
|
37
|
+
|
38
|
+
def bar
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
exception = assert_raise NoMethodError do
|
43
|
+
klass.new.bar
|
44
|
+
end
|
45
|
+
|
46
|
+
assert_match /private method `bar'/, exception.message
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_should_supports_channels
|
50
|
+
|
51
|
+
klass = Class.new do
|
52
|
+
include Mailbox
|
53
|
+
|
54
|
+
def initialize(channel)
|
55
|
+
register_channel :test_channel, channel
|
56
|
+
end
|
57
|
+
|
58
|
+
mailslot :channel => :test_channel
|
59
|
+
def test_method(latch)
|
60
|
+
latch.count_down
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
thread_ids = []
|
65
|
+
latch = Latches::CountDownLatch.new 1
|
66
|
+
a_channel = JRL::Channel.new
|
67
|
+
|
68
|
+
klass.new(a_channel)
|
69
|
+
a_channel.publish latch
|
70
|
+
|
71
|
+
assert latch.await( 1, Latches::TimeUnit::SECONDS ), "Timed out"
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
3
|
+
requirements:
|
4
|
+
- - '>='
|
5
|
+
- !ruby/object:Gem::Version
|
6
|
+
version: "0"
|
7
|
+
version:
|
8
|
+
email: asher.friedman@gmail.com
|
9
|
+
cert_chain: []
|
10
|
+
|
11
|
+
summary: Mailbox is a JRuby module that simplifies concurrency and is backed by JVM
|
12
|
+
threads.
|
13
|
+
post_install_message:
|
14
|
+
extra_rdoc_files:
|
15
|
+
- README
|
16
|
+
homepage: http://joelash.github.com/mailbox
|
17
|
+
signing_key:
|
18
|
+
name: mailbox
|
19
|
+
rdoc_options:
|
20
|
+
- --charset=UTF-8
|
21
|
+
rubyforge_project: mailbox
|
22
|
+
autorequire:
|
23
|
+
licenses: []
|
24
|
+
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
description: Mailbox is a JRuby module that simplifies concurrency and is backed by
|
28
|
+
JVM threads.
|
29
|
+
specification_version: 3
|
30
|
+
default_executable:
|
31
|
+
files:
|
32
|
+
- README
|
33
|
+
- Rakefile
|
34
|
+
- VERSION.yml
|
35
|
+
- lib/mailbox.rb
|
36
|
+
- mailbox.gemspec
|
37
|
+
- test/mailbox_test.rb
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: "0"
|
43
|
+
version:
|
44
|
+
extensions: []
|
45
|
+
|
46
|
+
rubygems_version: 1.3.3
|
47
|
+
requirements: []
|
48
|
+
|
49
|
+
authors:
|
50
|
+
- Joel Friedman
|
51
|
+
- Patrick Farley
|
52
|
+
date: 2009-10-13 05:00:00 +00:00
|
53
|
+
platform: ruby
|
54
|
+
test_files:
|
55
|
+
- test/mailbox_test.rb
|
56
|
+
version: !ruby/object:Gem::Version
|
57
|
+
version: 0.0.0
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
dependencies: []
|
61
|
+
|
62
|
+
bindir: bin
|
63
|
+
has_rdoc: true
|