opee 0.1.0 → 1.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.md CHANGED
@@ -10,9 +10,13 @@ portions of the Actors. They can be used to modify the control of the Actor.
10
10
  Once a reasonable API has been established a high performance C extension will
11
11
  be written to improve performance.
12
12
 
13
- This is no where close to being ready for prime time.
13
+ Give it a try. Any comments, thoughts, or suggestions are welcome.
14
14
 
15
- Any comments, thoughts, or suggestions are welcome.
15
+ ## <a name="source">Source</a>
16
+
17
+ *GitHub* *repo*: https://github.com/ohler55/opee
18
+
19
+ *RubyGems* *repo*: https://rubygems.org/gems/opee
16
20
 
17
21
  ## <a name="links">Links of Interest</a>
18
22
 
@@ -20,37 +24,17 @@ Any comments, thoughts, or suggestions are welcome.
20
24
 
21
25
  ## <a name="release">Release Notes</a>
22
26
 
23
- ### Release 0.1.0
27
+ ### Release 1.0.0
24
28
 
25
- - Documented classes.
29
+ - Added names to Actors
26
30
 
27
- - Added a rescuer attribute to the Env for global error handling.
31
+ - Use Actor name in log messages if set
28
32
 
29
- - Added Collector and Job classes along with unit tests.
33
+ - Added Actor lookup by name
30
34
 
31
35
  # Plans and Notes
32
36
 
33
- - add name or label to Actors so they can be discovered by name or symbol
34
-
35
- - pick a problem to test against
36
- - drop file path into dir_wq
37
- - pick up and decompose
38
- - if dir then drop into queue again
39
- - if file then send to filter actor
40
- - may need to read start to determine text if no extention
41
- - check for #! something and assume text/script
42
- - if not one of know extension then search low chars that are not \n\r\t or other well knows in text
43
- - cache text if file is read in
44
- - if text send to through work queue density checker then to summary
45
-
46
- - file density distribution
47
- - find all files under a directory
48
- - detemine if the file is a text or bin file and only keep text files
49
- - read in the text file and on work queue
50
- - worker determines density of file (non-white/total)
51
- - pass on to summary actor
52
- - wait_finish
53
- - ask to print or write report
37
+ - implement in C if there is enough interest
54
38
 
55
39
  ### License:
56
40
 
@@ -16,6 +16,8 @@ module Opee
16
16
 
17
17
  # The current processing state of the Actor
18
18
  attr_reader :state
19
+ # name of the actor
20
+ attr_reader :name
19
21
 
20
22
  # Initializes the Actor with the options specified. A new thread is
21
23
  # created during intialization after calling the set_options() method.
@@ -37,9 +39,11 @@ module Opee
37
39
  @ask_thread = nil
38
40
  @state = RUNNING
39
41
  @busy = false
42
+ @name = nil
40
43
  Env.add_actor(self)
41
44
  set_options(options)
42
45
  @loop = Thread.start(self) do |me|
46
+ Thread.current[:name] = me.name
43
47
  while CLOSING != @state
44
48
  begin
45
49
  if RUNNING == @state || STEP == @state
@@ -87,13 +91,21 @@ module Opee
87
91
  def set_options(options)
88
92
  @max_queue_count = options.fetch(:max_queue_count, @max_queue_count)
89
93
  @ask_timeout = options.fetch(:ask_timeout, @ask_timeout).to_f
94
+ @name = options[:name]
95
+ end
96
+
97
+ # Sets the name of the Actor.
98
+ # @param [String] name new name
99
+ def name=(name)
100
+ @name = name
101
+ @loop[:name] = name
90
102
  end
91
103
 
92
104
  # Calls {#ask}() but uses the specified timeout instead of the default
93
105
  # {#ask_timeout} to determine how long to wait if the Actor's queue is full.
94
106
  # @param [Fixnum|Float] timeout maximum time to wait trying to add a request to the Actor's queue
95
107
  # @param [Symbol] op method to queue for the Actor
96
- # @param [Array] *args arguments to the op method
108
+ # @param [Array] args arguments to the op method
97
109
  # @raise [BusyError] if the request queue does not become available in the timeout specified
98
110
  def timeout_ask(timeout, op, *args)
99
111
  unless @max_queue_count.nil? || 0 == @max_queue_count || @queue.size() < @max_queue_count
@@ -110,7 +122,7 @@ module Opee
110
122
 
111
123
  # Queues an operation and arguments to be called when the Actor is ready.
112
124
  # @param [Symbol] op method to queue for the Actor
113
- # @param [Array] *args arguments to the op method
125
+ # @param [Array] args arguments to the op method
114
126
  # @raise [BusyError] if the request queue does not become available in the {#ask_timeout} seconds
115
127
  def ask(op, *args)
116
128
  timeout_ask(@ask_timeout, op, *args)
@@ -119,7 +131,7 @@ module Opee
119
131
  # Queues an operation and arguments to be called when the Actor is has no
120
132
  # other requests to process.
121
133
  # @param [Symbol] op method to queue for the Actor
122
- # @param [Array] *args arguments to the op method
134
+ # @param [Array] args arguments to the op method
123
135
  def on_idle(op, *args)
124
136
  @idle_mutex.synchronize {
125
137
  @idle.insert(0, Act.new(op, args))
@@ -130,7 +142,7 @@ module Opee
130
142
  # Queues an operation and arguments to be called as soon as possible by
131
143
  # the Actor. These requests take precedence over other ordinary requests.
132
144
  # @param [Symbol] op method to queue for the Actor
133
- # @param [Array] *args arguments to the op method
145
+ # @param [Array] args arguments to the op method
134
146
  def priority_ask(op, *args)
135
147
  @priority_mutex.synchronize {
136
148
  @priority.insert(0, Act.new(op, args))
@@ -142,7 +154,7 @@ module Opee
142
154
  # places on the processing queue. Other methods cause a NoMethodError to
143
155
  # be raised as it normally would.
144
156
  # @param [Symbol] m method to queue for the Actor
145
- # @param [Array] *args arguments to the op method
157
+ # @param [Array] args arguments to the op method
146
158
  # @param [Proc] blk ignored
147
159
  def method_missing(m, *args, &blk)
148
160
  raise NoMethodError.new("undefine method '#{m}' for #{self.class}", m, args) unless respond_to?(m, true)
@@ -43,6 +43,16 @@ module Opee
43
43
  @@actors.each { |a| blk.yield(a) }
44
44
  end
45
45
 
46
+ # Locates and return an Actor with the specified name. If there is more
47
+ # than one Actor with the name specified then the first one encountered is
48
+ # returned.
49
+ # @param [String] name name of the Actor
50
+ # @return [Actor|NilClass] the Actor with the name specified or nil
51
+ def self.find_actor(name)
52
+ @@actors.each { |a| return a if name == a.name }
53
+ nil
54
+ end
55
+
46
56
  # Returns the number of active Actors.
47
57
  def self.actor_count()
48
58
  @@actors.size
@@ -62,7 +72,13 @@ module Opee
62
72
  # @param [String] message string to log
63
73
  def self.log(severity, message)
64
74
  @@log = Log.new() if @@log.nil?
65
- @@log.ask(:log, severity, message)
75
+ t = Thread.current
76
+ if (name = t[:name]).nil?
77
+ tid = "%d/0x%014x" % [Process.pid, Thread.current.object_id * 2]
78
+ else
79
+ tid = "#{Process.pid}/#{name}"
80
+ end
81
+ @@log.ask(:log, severity, message, tid)
66
82
  end
67
83
 
68
84
  # Asks the logger to log a message if the current severity level is less
@@ -9,19 +9,21 @@ module Opee
9
9
  def initialize(options={})
10
10
  @logger = nil
11
11
  @forward = nil
12
+ @formatter = nil
12
13
  super(options)
13
14
  end
14
15
 
15
16
  # Returns the current severity level.
16
17
  # @return [Fixnum] Logger severity level
17
- def level()
18
+ def severity()
18
19
  @logger.level
19
20
  end
21
+ alias :level :severity
20
22
 
21
23
  # Returns the current formatter.
22
24
  # @return [Logger::Formatter] current formatter
23
25
  def formatter()
24
- @logger.formatter
26
+ @formatter
25
27
  end
26
28
 
27
29
  # Returns the forward Log Actor if one has been set.
@@ -53,17 +55,27 @@ module Opee
53
55
  else
54
56
  @logger = Logger.new(STDOUT)
55
57
  end
56
- severity = options[:severity] if options.has_key?(:severity)
57
- formatter = options[:formatter] if options.has_key?(:formatter)
58
+ @logger.severity = options[:severity] if options.has_key?(:severity)
59
+ @formatter = options.fetch(:formatter, nil)
60
+ @logger.formatter = proc { |s,t,p,m| m }
58
61
  end
59
62
 
60
63
  # Writes a message if the severity is high enough. This method is
61
64
  # executed asynchronously.
62
65
  # @param [Fixnum] severity one of the Logger levels
63
66
  # @param [String] message string to log
64
- def log(severity, message)
65
- @logger.add(severity, message)
66
- @forward.log(severity, message) unless @forward.nil?
67
+ # @param [Fixnum|String] tid thread id of the thread generating the message
68
+ def log(severity, message, tid)
69
+ now = Time.now
70
+ ss = ['DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL'][severity]
71
+ ss = '' if ss.nil?
72
+ if @formatter.nil?
73
+ msg = "#{ss[0]}, [#{now.strftime('%Y-%m-%dT%H:%M:%S.%6N')} ##{tid}] #{ss} -- : #{message}\n"
74
+ else
75
+ msg = @formatter.call(ss, now, tid, message)
76
+ end
77
+ @logger.add(severity, msg)
78
+ @forward.log(severity, message, tid) unless @forward.nil?
67
79
  end
68
80
 
69
81
  # Sets the logger to use the stream specified. This method is executed
@@ -126,7 +138,7 @@ module Opee
126
138
  # asynchronously.
127
139
  # @param [Proc] proc value to set the formatter to
128
140
  def formatter=(proc)
129
- @logger.formatter = proc
141
+ @formatter = proc
130
142
  end
131
143
 
132
144
  end # Log
@@ -1,5 +1,5 @@
1
1
 
2
2
  module Opee
3
3
  # Current version of the module.
4
- VERSION = '0.1.0'
4
+ VERSION = '1.0.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-14 00:00:00.000000000 Z
12
+ date: 2012-05-15 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! 'An experimental Object-base Parallel Evaluation Environment. '
15
15
  email: peter@ohler.com