livedata 0.2.3 → 0.2.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ * v0.2.4
2
+ 1. LiveData::ThreadWatch module is implemented.
3
+ 2. default ReadTime and WaitTime is set to 25
4
+ 3. write_json method is removed from Channel class
1
5
  * v0.2.3
2
6
  1. Make the live data compartable to ruby 1.8.x
3
7
  * v0.2.2
@@ -35,13 +35,6 @@ module LiveData
35
35
  }
36
36
  end
37
37
 
38
- # Write data, which contain json format
39
- def write_json( json_data )
40
- @users.each{|user|
41
- user.write_json( json_data )
42
- }
43
- end
44
-
45
38
  # Write any object
46
39
  def write( data )
47
40
  @users.each{|user|
@@ -0,0 +1,38 @@
1
+ module LiveData
2
+ module ThreadWatch
3
+ Lock = Mutex.new
4
+ WaitTime = 25
5
+ UserThreads = {}
6
+
7
+ def self.wait( user_id, time = WaitTime, user_threads = UserThreads )
8
+ already_use = false
9
+ Lock.synchronize {
10
+ if( user_threads[user_id] )
11
+ already_use = true
12
+ else
13
+ user_threads[user_id] = Thread.current
14
+ end
15
+ }
16
+ if( already_use )
17
+ return nil
18
+ end
19
+ used_time = sleep(time )
20
+ Lock.synchronize {
21
+ user_threads.delete( user_id )
22
+ }
23
+ return used_time
24
+ end
25
+
26
+ def self.wakeup( user_id , user_threads = UserThreads )
27
+ Lock.synchronize {
28
+ uthread = user_threads[user_id]
29
+ if( uthread )
30
+ uthread.wakeup
31
+ return true
32
+ else
33
+ return false
34
+ end
35
+ }
36
+ end
37
+ end
38
+ end
@@ -3,7 +3,7 @@ module LiveData
3
3
  class User
4
4
 
5
5
  IntegerPackCode = "I"
6
- ReadTime = 30
6
+ ReadTime = 25
7
7
 
8
8
  attr :groups, true
9
9
  attr :name, true
@@ -11,8 +11,8 @@ module LiveData
11
11
  # Create a user object
12
12
  def initialize( name = nil, channel = nil )
13
13
  @name = name || self
14
- @channel = channel
15
- @read_time = ReadTime
14
+ @channel = channel
15
+ @read_time = ReadTime
16
16
  @lock = Mutex.new
17
17
  @read_pipe, @write_pipe = IO.pipe
18
18
  @groups = []
@@ -1,4 +1,4 @@
1
1
 
2
2
  module LiveData
3
- VERSION = '0.2.3'
3
+ VERSION = '0.2.4'
4
4
  end
data/lib/live_data.rb CHANGED
@@ -7,6 +7,8 @@ require 'live_data/version'
7
7
  require 'live_data/channel'
8
8
  require 'live_data/user'
9
9
  require 'live_data/group'
10
+ require 'live_data/thread_watch'
11
+
10
12
  module LiveData
11
13
  Channels = {}
12
14
 
@@ -0,0 +1,31 @@
1
+ require 'test_helper'
2
+
3
+ class ThreadWatchTest < Test::Unit::TestCase
4
+ def test_thread_watch
5
+ th = Thread.new{
6
+ sleep(6)
7
+ LiveData::ThreadWatch.wakeup('guest')
8
+ }
9
+ assert LiveData::ThreadWatch.wait('guest', 10 ) < 10
10
+ th.join
11
+
12
+ assert LiveData::ThreadWatch.wait('guest', 2 ) >= 2
13
+
14
+ th = Thread.new{
15
+ sleep(2)
16
+ assert LiveData::ThreadWatch.wait('guest', 2) == nil
17
+ }
18
+ assert LiveData::ThreadWatch.wait('guest', 5 ) >= 5
19
+ th.join
20
+ end
21
+
22
+ def test_own_object
23
+ threads = {}
24
+ th = Thread.new{
25
+ sleep(6)
26
+ LiveData::ThreadWatch.wakeup('guest', threads )
27
+ }
28
+ assert LiveData::ThreadWatch.wait('guest', 10 , threads ) < 10
29
+ th.join
30
+ end
31
+ end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: livedata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 2
8
+ - 4
9
+ version: 0.2.4
5
10
  platform: ruby
6
11
  authors:
7
12
  - Mohammed Siddick. E
@@ -9,7 +14,7 @@ autorequire: live_data
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-02-15 00:00:00 +05:30
17
+ date: 2010-02-26 00:00:00 +05:30
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
@@ -28,11 +33,13 @@ files:
28
33
  - README
29
34
  - CHANGELOG
30
35
  - lib/live_data/channel.rb
36
+ - lib/live_data/thread_watch.rb
31
37
  - lib/live_data/group.rb
32
38
  - lib/live_data/user.rb
33
39
  - lib/live_data/version.rb
34
40
  - lib/livedata.rb
35
41
  - lib/live_data.rb
42
+ - test/thread_watch_test.rb
36
43
  - test/live_data_test.rb
37
44
  - test/test_helper.rb
38
45
  has_rdoc: true
@@ -49,18 +56,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
49
56
  requirements:
50
57
  - - ">="
51
58
  - !ruby/object:Gem::Version
59
+ segments:
60
+ - 0
52
61
  version: "0"
53
- version:
54
62
  required_rubygems_version: !ruby/object:Gem::Requirement
55
63
  requirements:
56
64
  - - ">="
57
65
  - !ruby/object:Gem::Version
66
+ segments:
67
+ - 0
58
68
  version: "0"
59
- version:
60
69
  requirements: []
61
70
 
62
71
  rubyforge_project:
63
- rubygems_version: 1.3.5
72
+ rubygems_version: 1.3.6
64
73
  signing_key:
65
74
  specification_version: 3
66
75
  summary: Handle live data