ap4r 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+ # Author:: Shunichi Shinohara
2
+ # Copyright:: Copyright (c) 2006 Future System Consulting Corp.
3
+ # Licence:: MIT Licence
4
+
5
+ require 'active_support'
6
+ require 'code_statistics'
7
+
8
+ CodeStatistics.new(
9
+ ["Core Sources", "lib"],
10
+ ["Rails plugin", "rails_plugin"],
11
+ ["Scripts", "script"],
12
+ ).to_s
@@ -0,0 +1,123 @@
1
+ # Author:: Shunichi Shinohara
2
+ # Copyright:: Copyright (c) 2006 Future System Consulting Corp.
3
+ # Licence:: MIT Licence
4
+
5
+ module AP4R::Util #:nodoc:
6
+ # This class is TOO EXPERIMENTAL
7
+ #
8
+ # Client class for +QueueManager+.
9
+ # This class wraps DRb client and provides some helper methods.
10
+ # TODO: many drb calls are executed in a method call such as +list_queues+.
11
+ # ParseTree is perhaps needed.
12
+ # TODO: +Proc+ object cannnot be passed via DRb. ParseTree also?
13
+ class QueueClient
14
+ CONFIG_DIR_DEFAULT = 'config'
15
+ CONFIG_FILE_DEFAULT = 'queues.cfg'
16
+
17
+ HOST_DEFAULT = 'localhost'
18
+
19
+ DEFAULT_QUEUE_PREFIX = 'queue.test.'
20
+ DEFAULT_QUEUE_SUFFIX = 'default'
21
+ DEFAULT_MULTI_QUEUE = DEFAULT_QUEUE_PREFIX + '*'
22
+
23
+ @@config_dir = CONFIG_DIR_DEFAULT
24
+ cattr_accessor :config_dir
25
+
26
+ attr_reader :name, :config
27
+
28
+ # Creates new client from a configuration file.
29
+ # Some options are supported.
30
+ # * <tt>:host</tt>
31
+ # * <tt>:port</tt>
32
+ # * <tt>:name</tt>
33
+ def initialize(config_file = CONFIG_FILE_DEFAULT,
34
+ options = {},
35
+ config_dir = @@config_dir)
36
+ @config = ReliableMsg::Config.new(File.join(config_dir, config_file))
37
+ @config.load_no_create
38
+ @host = options[:host] || @config.drb['host'] || 'localhost'
39
+ @port = options[:port] || @config.drb['port'] || 6438
40
+ @name = (options[:name]).to_sym
41
+ @qm = nil
42
+ end
43
+
44
+ def queue_manager
45
+ @qm ||= DRb::DRbObject.new_with_uri(drb_uri)
46
+ end
47
+
48
+ def queue_manager_stop
49
+ manager = queue_manager
50
+ begin
51
+ manager.stop
52
+ rescue DRb::DRbConnError => error
53
+ error.message
54
+ end
55
+ end
56
+
57
+ def list_queues
58
+ qm.store.queues.keys
59
+ end
60
+
61
+ def list_messages(suffix = DEFAULT_QUEUE_SUFFIX,
62
+ prefix = DEFAULT_QUEUE_PREFIX)
63
+ qm.store.queues[prefix.to_s + suffix.to_s]
64
+ end
65
+
66
+ def make_queue(suffix = DEFAULT_QUEUE_SUFFIX,
67
+ prefix = DEFAULT_QUEUE_PREFIX)
68
+ ReliableMsg::Queue.new(prefix.to_s + suffix.to_s, :drb_uri => drb_uri)
69
+ end
70
+
71
+ def queue_get(suffix = DEFAULT_QUEUE_SUFFIX, selector = nil,
72
+ prefix = DEFAULT_QUEUE_PREFIX, &block)
73
+ q = make_queue suffix, prefix
74
+ q.get selector, &block
75
+ end
76
+
77
+ def queue_put(suffix = DEFAULT_QUEUE_SUFFIX,
78
+ message = nil, prefix = DEFAULT_QUEUE_PREFIX,
79
+ headers = nil)
80
+ unless message
81
+ t = Time.now
82
+ message = sprintf("test message %s,%s",
83
+ t.strftime("%Y/%m/%d %H:%M:%S"), t.usec)
84
+ end
85
+ q = make_queue suffix, prefix
86
+ q.put message, headers
87
+ end
88
+
89
+ def make_multi_queue multi_queue = DEFAULT_MULTI_QUEUE
90
+ ReliableMsg::MultiQueue.new(multi_queue.to_s, :drb_uri => drb_uri)
91
+ end
92
+
93
+ def multi_queue_get(selector = nil,
94
+ multi_queue = DEFAULT_MULTI_QUEUE, &block)
95
+ mq = make_multi_queue multi_queue, :drb_uri => irm_drb_uri
96
+ mq.get selector, &block
97
+ end
98
+
99
+ def drb_uri
100
+ "druby://#{@host}:#{@port}"
101
+ end
102
+
103
+ def to_s
104
+ @name.to_s
105
+ end
106
+
107
+ alias qm queue_manager
108
+ alias stop queue_manager_stop
109
+
110
+ alias lsq list_queues
111
+ alias lsm list_messages
112
+
113
+ alias mkq make_queue
114
+ alias qg queue_get
115
+ alias qp queue_put
116
+
117
+ alias mkmq make_multi_queue
118
+ alias mqg multi_queue_get
119
+
120
+ alias uri drb_uri
121
+
122
+ end
123
+ end
@@ -0,0 +1,15 @@
1
+ # Author:: Kiwamu Kato
2
+ # Copyright:: Copyright (c) 2006 Future System Consulting Corp.
3
+ # Licence:: MIT Licence
4
+
5
+ module AP4R
6
+ # Defines version number contants, and provides
7
+ # its string expression.
8
+ module VERSION #:nodoc:
9
+ MAJOR = 0
10
+ MINOR = 1
11
+ TINY = 1
12
+
13
+ STRING = [MAJOR, MINOR, TINY].join('.')
14
+ end
15
+ end
@@ -0,0 +1,10 @@
1
+ # Author:: Shunichi Shinohara
2
+ # Copyright:: Copyright (c) 2006 Future System Consulting Corp.
3
+ # Licence:: MIT Licence
4
+
5
+ require_dependency 'async_controller'
6
+
7
+ class ActionController::Base
8
+ include AP4R::AsyncController
9
+ end
10
+
@@ -0,0 +1,64 @@
1
+ # Author:: Shunichi Shinohara
2
+ # Copyright:: Copyright (c) 2006 Future System Consulting Corp.
3
+ # Licence:: MIT Licence
4
+
5
+ require 'reliable-msg'
6
+
7
+ module AP4R
8
+ # This +asyncController+ is the Rails plugin for asynchronous processing.
9
+ # Asynchronous logics are called via various protocols, such as XML-RPC,
10
+ # SOAP, HTTP PUT, and more. Now implemented jsut as XML-RPC.
11
+ #
12
+ # Examples: The part of calling next asynchronous logics in a controller in the HelloWorld Sample.
13
+ #
14
+ # req = WorldRequest.new
15
+ # req.world_id = 1
16
+ # req.message = "World"
17
+ #
18
+ # req_hash = {}
19
+ # req.each_pair{|k,v| req_hash[k.to_sym]=v}
20
+ #
21
+ # render :action => 'response'
22
+ #
23
+ # async_dispatch(req_hash,
24
+ # :controller => 'async_world', :action => 'execute',
25
+ # :mode => :XMLRPC)
26
+ #
27
+ module AsyncController
28
+ #DEFAULT_DISPATCH_MODE = :SOAP
29
+ DEFAULT_DISPATCH_MODE = :XMLRPC
30
+
31
+ # Queue a message for next asynchronous logic. Some options are supported.
32
+ # * :controller (name of next logic)
33
+ # * :action (name of next logic)
34
+ # * :mode (protocol)
35
+ def async_dispatch(object, options = {})
36
+ target_url = url_for(:controller => options[:controller],
37
+ :action => nil)
38
+ options[:mode] = options[:mode] || dispatch_mode
39
+ options[:target_url] = target_url_name(target_url, options[:mode])
40
+ target_action = action_api_name(options.delete(:action), options[:mode])
41
+ options[:target_action] = target_action
42
+
43
+ queue_name = "queue.".concat(options[:controller].to_s).
44
+ concat('.').concat(target_action)
45
+
46
+ q = ReliableMsg::Queue.new(queue_name)
47
+ mid = q.put(object, options)
48
+ mid
49
+ end
50
+
51
+ private
52
+ def dispatch_mode
53
+ DEFAULT_DISPATCH_MODE
54
+ end
55
+
56
+ def target_url_name(target_url, mode)
57
+ target_url + "/api"
58
+ end
59
+
60
+ def action_api_name(action_method_name, mode)
61
+ action_method_name.capitalize
62
+ end
63
+ end
64
+ end
data/script/irm ADDED
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'ap4r'
3
+
4
+ require 'ap4r/util/irm'
File without changes
File without changes
data/script/start ADDED
@@ -0,0 +1,5 @@
1
+ require 'rubygems'
2
+ require 'ap4r/script/setup'
3
+
4
+ require 'ap4r/script/queue_manager_control'
5
+ AP4R::Script::QueueManagerControl.new.start(ARGV)
data/script/stop ADDED
@@ -0,0 +1 @@
1
+
metadata CHANGED
@@ -3,18 +3,17 @@ rubygems_version: 0.8.11
3
3
  specification_version: 1
4
4
  name: ap4r
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.0
7
- date: 2006-09-01 00:00:00 +09:00
6
+ version: 0.1.1
7
+ date: 2006-10-05 00:00:00 +09:00
8
8
  summary: Asynchronous Processing for Ruby.
9
9
  require_paths:
10
10
  - lib
11
- email: kato.kiwamu@future.co.jp, shinohara.shunichi@future.co.jp
11
+ email: shinohara.shunichi@future.co.jp, kato.kiwamu@future.co.jp
12
12
  homepage: http://rubyforge.org/projects/ap4r/
13
13
  rubyforge_project: ap4r
14
14
  description: Asynchronous Processing for Ruby.
15
15
  autorequire: ap4r.rb
16
- default_executable:
17
- - ap4r
16
+ default_executable: ap4r_setup
18
17
  bindir: bin
19
18
  has_rdoc: true
20
19
  required_ruby_version: !ruby/object:Gem::Version::Requirement
@@ -27,19 +26,33 @@ platform: ruby
27
26
  signing_key:
28
27
  cert_chain:
29
28
  authors:
30
- - Shunichi Shinohara, Kiwamu Kato
29
+ - Shunichi Shinohara
30
+ - Kiwamu Kato
31
31
  files:
32
- - bin/ap4r
33
- - bin/irm.cmd
34
- - bin/loop.cmd
35
- - bin/loop.rb
36
- - bin/queues.cmd
37
- - bin/queues.rb
38
- - bin/stop.cmd
39
- - configs/log4r.yaml
40
- - configs/queues.cfg
41
- - configs/queues_disk.cfg
42
- - configs/queues_mysql.cfg
32
+ - bin
33
+ - CHANGELOG
34
+ - config
35
+ - lib
36
+ - MIT-LICENSE
37
+ - rails_plugin
38
+ - Rakefile
39
+ - README
40
+ - script
41
+ - bin/ap4r_setup
42
+ - config/ap4r_settings.rb
43
+ - config/log4r.yaml
44
+ - config/queues.cfg
45
+ - config/queues_disk.cfg
46
+ - config/queues_mysql.cfg
47
+ - rails_plugin/ap4r
48
+ - rails_plugin/ap4r/init.rb
49
+ - rails_plugin/ap4r/lib
50
+ - rails_plugin/ap4r/lib/async_controller.rb
51
+ - script/irm
52
+ - script/loop.cmd
53
+ - script/loop.rb
54
+ - script/start
55
+ - script/stop
43
56
  - lib/ap4r
44
57
  - lib/ap4r.rb
45
58
  - lib/ap4r/message_store_ext.rb
@@ -47,26 +60,35 @@ files:
47
60
  - lib/ap4r/queue_manager_ext.rb
48
61
  - lib/ap4r/queue_manager_ext_debug.rb
49
62
  - lib/ap4r/retention_history.rb
63
+ - lib/ap4r/script
50
64
  - lib/ap4r/start_with_log4r.rb
51
- - lib/ap4r/utils
52
- - lib/ap4r/utils/irm.rb
53
- - lib/ap4r/utils/loc.rb
54
- - CHANGELOG
55
- - MIT-LICENSE
56
- - Rakefile
57
- - README
65
+ - lib/ap4r/util
66
+ - lib/ap4r/version.rb
67
+ - lib/ap4r/script/base.rb
68
+ - lib/ap4r/script/queue_manager_control.rb
69
+ - lib/ap4r/script/setup.rb
70
+ - lib/ap4r/script/workspace_generator.rb
71
+ - lib/ap4r/util/irm.rb
72
+ - lib/ap4r/util/loc.rb
73
+ - lib/ap4r/util/queue_client.rb
58
74
  test_files: []
59
75
 
60
- rdoc_options: []
61
-
62
- extra_rdoc_files: []
63
-
76
+ rdoc_options:
77
+ - --main
78
+ - README
79
+ - --title
80
+ - Asynchronous Processing for Ruby
81
+ - --line-numbers
82
+ extra_rdoc_files:
83
+ - README
84
+ - CHANGELOG
85
+ - rails_plugin
64
86
  executables:
65
- - ap4r
87
+ - ap4r_setup
66
88
  extensions: []
67
89
 
68
- requirements:
69
- - none
90
+ requirements: []
91
+
70
92
  dependencies:
71
93
  - !ruby/object:Gem::Dependency
72
94
  name: reliable-msg
data/bin/ap4r DELETED
File without changes
data/bin/irm.cmd DELETED
@@ -1,2 +0,0 @@
1
- @ECHO OFF
2
- irb -Ilib/ -r utils/irm
data/bin/queues.cmd DELETED
@@ -1,2 +0,0 @@
1
- @ECHO OFF
2
- ruby script\queues.rb %*
data/bin/queues.rb DELETED
@@ -1,3 +0,0 @@
1
- require 'ap4r'
2
-
3
- ReliableMsg::CLI.new.run
data/bin/stop.cmd DELETED
@@ -1 +0,0 @@
1
- ./queues manager stop
@@ -1,15 +0,0 @@
1
- ---
2
- store:
3
- username: orca
4
- type: mysql
5
- host: localhost
6
- database: ap4r
7
- password: ap4r
8
- drb:
9
- host:
10
- port: 6438
11
- acl: allow 127.0.0.1 allow 10.0.0.0/8
12
- dispatchers:
13
- -
14
- queue: queue.orders.*
15
- threads: 1
@@ -1,109 +0,0 @@
1
- # interactive reliable message
2
- # version 0.1.1
3
- # written by shino
4
-
5
- require 'reliable-msg-hack'
6
-
7
- require 'pathname'
8
- require 'uri'
9
-
10
- $KCODE = 'u'
11
-
12
- $config = 'queues.cfg'
13
- $drb_host = 'localhost'
14
- $drb_port = 6438
15
-
16
- module Kernel
17
- DEFAULT_QUEUE_PREFIX = 'queue.test.'
18
- DEFAULT_QUEUE_SUFFIX = 'default'
19
- DEFAULT_MULTI_QUEUE = DEFAULT_QUEUE_PREFIX + '*'
20
-
21
- def irm_queue_manager config = $config
22
- raise "NOT exist : #{config}" unless Pathname.new(config).exist?
23
- DRb::DRbObject.new_with_uri irm_drb_uri
24
- end
25
-
26
- def irm_queue_manager_stop config = $config
27
- manager = irm_queue_manager config
28
- begin
29
- manager.stop
30
- rescue DRb::DRbConnError => error
31
- error.message
32
- end
33
- end
34
-
35
-
36
- def irm_list_queues
37
- qm.store.queues.keys
38
- end
39
-
40
- def irm_list_messages suffix = DEFAULT_QUEUE_SUFFIX,
41
- prefix = DEFAULT_QUEUE_PREFIX
42
- qm.store.queues[prefix.to_s + suffix.to_s]
43
- end
44
-
45
-
46
- def irm_make_queue suffix = DEFAULT_QUEUE_SUFFIX,
47
- prefix = DEFAULT_QUEUE_PREFIX
48
- ReliableMsg::Queue.new prefix.to_s + suffix.to_s, :drb_uri => irm_drb_uri
49
- end
50
-
51
- def irm_queue_get suffix = DEFAULT_QUEUE_SUFFIX, selector = nil,
52
- prefix = DEFAULT_QUEUE_PREFIX, &block
53
- q = irm_make_queue suffix, prefix
54
- q.get selector, &block
55
- end
56
-
57
- def irm_queue_put suffix = DEFAULT_QUEUE_SUFFIX,
58
- message = nil, prefix = DEFAULT_QUEUE_PREFIX,
59
- headers = nil
60
- unless message
61
- t = Time.now
62
- message = sprintf("test message %s,%s",
63
- t.strftime("%Y/%m/%d %H:%M:%S"), t.usec)
64
- end
65
- q = irm_make_queue suffix, prefix
66
- q.put message, headers
67
- end
68
-
69
- def irm_make_multi_queue multi_queue = DEFAULT_MULTI_QUEUE
70
- ReliableMsg::MultiQueue.new multi_queue.to_s
71
- end
72
-
73
- def irm_multi_queue_get selector = nil,
74
- multi_queue = DEFAULT_MULTI_QUEUE, &block
75
- mq = irm_make_multi_queue multi_queue, :drb_uri => irm_drb_uri
76
- mq.get selector, &block
77
- end
78
-
79
- def irm_set_config arg
80
- if arg.is_a? Integer
81
- $config = "queues#{arg.to_s}.cfg"
82
- else
83
- $config = arg.to_s
84
- end
85
- config = ReliableMsg::Config.new($config)
86
- config.load_no_create
87
- $drb_port = config.drb['port']
88
- end
89
-
90
- def irm_drb_uri
91
- "druby://#{$drb_host}:#{$drb_port}"
92
- end
93
-
94
- alias qm irm_queue_manager
95
- alias qm_stop irm_queue_manager_stop
96
-
97
- alias lsq irm_list_queues
98
- alias lsm irm_list_messages
99
-
100
- alias mkq irm_make_queue
101
- alias qg irm_queue_get
102
- alias qp irm_queue_put
103
- alias mkmq irm_make_multi_queue
104
- alias mqg irm_multi_queue_get
105
-
106
- alias cfg irm_set_config
107
- alias uri irm_drb_uri
108
- end
109
-