public
Description: Tempo is a set of runtime components that support human workflow within an service-oriented architecture (SOA)
Homepage: http://tempo.intalio.org
Clone URL: git://github.com/intalio/tempo.git
tempo / rsc / samples / threaded_get_tasks.rb
100755 43 lines (40 sloc) 1.004 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env ruby
load File.dirname(File.expand_path("#{$0}"))+"/lib/sample_tms_client.rb"
require "pp"
 
class TaskGetter
  def initialize(round=10, sleep_interval=0.5)
    @round = round
    @debug = true
    @sleep = sleep_interval
  end
  def run
    tms_client = SampleTMSClient.new
    (1..@round).each do |i|
      t1 = Time.now
      ts = tms_client.get_available_tasks "", "PATask"
      t2 = Time.now
      puts t2-t1 if @debug
      sleep(@sleep)
    end
  end
end
 
class TaskGetterStarter
  def initialize(number=3, round=10, sleep_interval=1)
    @number = number
    @round = round
    @sleep_interval = sleep_interval
  end
  def run
    clients = Hash.new
    (0..@number).each do |client|
      puts "Spawning client:#{client}"
      clients[client] = Thread.new {g = TaskGetter.new(@round,@sleep_interval) ; g.run}
    end
    (1..@number).each do |client|
      clients[client].join
    end
  end
end
 
# tgs = TaskGetterStarter.new(3,10)
tgs = TaskGetterStarter.new(1,1)
tgs.run