livedata 0.3.0 → 0.3.1

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/config/routes.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  Rails::Application.routes.draw do
2
- get 'live_data/:channel_id/:user_id' => LiveDataController.action(:get)
3
- get 'live_data/:channel_id/:user_id/put(.:format)' => LiveDataController.action(:put)
4
- put 'live_data/:channel_id/:user_id(.:format)' => LiveDataController.action(:put)
2
+ get 'live_data/:channel_id/:user_id(.:format)' => LiveDataController.action(:get)
3
+ get 'live_data/:channel_id/:user_id/put' => LiveDataController.action(:put)
4
+ put 'live_data/:channel_id/:user_id' => LiveDataController.action(:put)
5
+ post 'live_data/:channel_id/:user_id' => LiveDataController.action(:put)
5
6
  end
@@ -1,8 +1,9 @@
1
1
  module LiveData
2
2
  module ThreadWatch
3
3
  Lock = Mutex.new
4
- WaitTime = 25
4
+ WaitTime = 15
5
5
  UserThreads = {}
6
+ UserData = {}
6
7
 
7
8
  def self.wait( user_id, time = WaitTime, user_threads = UserThreads )
8
9
  already_use = false
@@ -34,5 +35,41 @@ module LiveData
34
35
  end
35
36
  }
36
37
  end
38
+
39
+ def self.read( user_id, wait_time = WaitTime )
40
+ data = get_user_data( user_id )
41
+ obj = nil
42
+ Lock.synchronize{
43
+ obj = data.shift
44
+ }
45
+ return obj if obj
46
+ wait( user_id, wait_time )
47
+ Lock.synchronize{
48
+ obj = data.shift
49
+ }
50
+ return obj
51
+ end
52
+
53
+ def self.write( user_id, obj )
54
+ data = get_user_data( user_id )
55
+ Lock.synchronize {
56
+ data.push( obj )
57
+ }
58
+ wakeup( user_id )
59
+ end
60
+
61
+ def self.clear( user_id )
62
+ data = get_user_data( user_id )
63
+ Lock.synchronize{
64
+ data.clear
65
+ }
66
+ end
67
+
68
+ def self.get_user_data( user_id )
69
+ Lock.synchronize {
70
+ UserData[user_id] ||= []
71
+ }
72
+ end
73
+
37
74
  end
38
75
  end
@@ -1,4 +1,4 @@
1
1
 
2
2
  module LiveData
3
- VERSION = '0.3.0'
3
+ VERSION = '0.3.1'
4
4
  end
@@ -28,4 +28,31 @@ class ThreadWatchTest < Test::Unit::TestCase
28
28
  assert LiveData::ThreadWatch.wait('guest', 10 , threads ) < 10
29
29
  th.join
30
30
  end
31
+
32
+ def test_read_write_process
33
+ content = "Testing"
34
+ LiveData::ThreadWatch.write( 'guest', content )
35
+ assert_equal LiveData::ThreadWatch.read( 'guest' ), content
36
+ assert_equal LiveData::ThreadWatch.read( 'guest', 10 ), nil
37
+ end
38
+
39
+ def test_read_write_process2
40
+ content = { :hai => "testing" }
41
+ content2 = "Testing2"
42
+ Thread.new {
43
+ sleep(4)
44
+ LiveData::ThreadWatch.write( 'guest', content )
45
+ LiveData::ThreadWatch.write( 'guest', content2 )
46
+ }
47
+ assert_equal LiveData::ThreadWatch.read( 'guest', 10 ), content
48
+ assert_equal LiveData::ThreadWatch.read( 'guest', 10 ), content2
49
+ assert_equal LiveData::ThreadWatch.read( 'guest', 2 ), nil
50
+ end
51
+
52
+ def test_clear
53
+ content = { :hai => "testing" }
54
+ LiveData::ThreadWatch.write( 'guest', content )
55
+ LiveData::ThreadWatch.clear( 'guest' )
56
+ assert_equal LiveData::ThreadWatch.read( 'guest', 2 ), nil
57
+ end
31
58
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: livedata
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 0
10
- version: 0.3.0
9
+ - 1
10
+ version: 0.3.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mohammed Siddick. E
@@ -15,7 +15,7 @@ autorequire: live_data
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-17 00:00:00 +05:30
18
+ date: 2010-09-27 00:00:00 +05:30
19
19
  default_executable:
20
20
  dependencies: []
21
21