deadly_serious 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/lib/deadly_serious/engine/channel.rb +41 -14
- data/lib/deadly_serious/engine/lazy_io.rb +10 -3
- data/lib/deadly_serious/engine/spawner.rb +5 -3
- data/lib/deadly_serious/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 835ccef3d84a0bbe1cbcfd6ad4a78ccbea6709f8
|
4
|
+
data.tar.gz: d330508f3b852e4ac98c99b9fc679386bdd75f1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aad544ea7468318303460244dae5db32074317027509b3f84d512f7011667f78a47868e86c39817779c249223d425076f525626d9a0402ba21723992e83487a0
|
7
|
+
data.tar.gz: 717bf292b278dd7d41e5e3ffec05e931a7bc69f6de8a143e0ff4a17f414cd3c8238e1cdb5dc8e867b6db1d744cacc63b903eda1f8b910c35015e87f5009e5ef5
|
data/.gitignore
CHANGED
@@ -12,7 +12,7 @@ module DeadlySerious
|
|
12
12
|
def self.new(name)
|
13
13
|
matcher = name.match(/^(>)?(.*?)(?:(:)(\d{1,5}))?$/)
|
14
14
|
if matcher[1] == '>'
|
15
|
-
FileChannel.new(matcher[2], @data_dir)
|
15
|
+
FileChannel.new(matcher[2], @data_dir, @pipe_dir)
|
16
16
|
elsif matcher[3] == ':'
|
17
17
|
SocketChannel.new(matcher[2], matcher[4].to_i)
|
18
18
|
else
|
@@ -20,20 +20,26 @@ module DeadlySerious
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
def self.config(data_dir, pipe_dir, preserve_pipe_dir)
|
23
|
+
def self.config(data_dir, pipe_dir, lock_dir, preserve_pipe_dir, preserve_lock_dir)
|
24
24
|
@data_dir = data_dir
|
25
25
|
@pipe_dir = pipe_dir
|
26
|
+
@lock_dir = lock_dir
|
26
27
|
@preserve_pipe_dir = preserve_pipe_dir
|
28
|
+
@preserve_lock_dir = preserve_lock_dir
|
27
29
|
end
|
28
30
|
|
29
31
|
def self.setup
|
30
32
|
FileUtils.mkdir_p(@pipe_dir) unless File.exist?(@pipe_dir)
|
33
|
+
FileUtils.mkdir_p(@lock_dir) unless File.exist?(@lock_dir)
|
31
34
|
end
|
32
35
|
|
33
36
|
def self.teardown
|
34
37
|
if !@preserve_pipe_dir && File.exist?(@pipe_dir)
|
35
38
|
FileUtils.rm_r(@pipe_dir, force: true, secure: true)
|
36
39
|
end
|
40
|
+
if !@preserve_lock_dir && File.exist?(@lock_dir)
|
41
|
+
FileUtils.rm_r(@lock_dir, force: true, secure: true)
|
42
|
+
end
|
37
43
|
end
|
38
44
|
|
39
45
|
def self.create_pipe(pipe_name)
|
@@ -42,28 +48,41 @@ module DeadlySerious
|
|
42
48
|
end
|
43
49
|
|
44
50
|
class FileChannel
|
45
|
-
def initialize(name, directory)
|
51
|
+
def initialize(name, directory, temp_dir)
|
46
52
|
@io_name = File.join(directory, name)
|
53
|
+
@readlock_file = "#{temp_dir}/#{name}.readlock"
|
47
54
|
end
|
48
55
|
|
49
56
|
def create
|
50
|
-
|
57
|
+
unless File.exist?(@io_name)
|
58
|
+
`touch #{@io_name} && touch #{@readlock_file}`
|
59
|
+
end
|
51
60
|
@io_name
|
52
61
|
end
|
53
62
|
|
63
|
+
def on_close
|
64
|
+
FileUtils.rm_f(@readlock_file)
|
65
|
+
end
|
66
|
+
|
67
|
+
# If the file has a "readlock", blocks the opening
|
68
|
+
# until the readlock be removed.
|
54
69
|
def open_reader
|
55
70
|
fail %(File "#{@io_name}" not found) unless File.exist?(@io_name)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
file = open(@io_name, 'r')
|
63
|
-
end
|
64
|
-
notifier.process
|
65
|
-
file
|
71
|
+
return open(@io_name, 'r') unless File.exist?(@readlock_file)
|
72
|
+
|
73
|
+
notifier = INotify::Notifier.new
|
74
|
+
file = nil
|
75
|
+
notifier.watch(@readlock_file, :delete) do
|
76
|
+
file = open(@io_name, 'r')
|
66
77
|
end
|
78
|
+
notifier.process
|
79
|
+
file
|
80
|
+
|
81
|
+
rescue Errno::ENOENT
|
82
|
+
# Should occur ONLY if we deleted the
|
83
|
+
# readlock file after the guard clause
|
84
|
+
# and before the Notifier initialization.
|
85
|
+
open(@io_name, 'r')
|
67
86
|
end
|
68
87
|
|
69
88
|
def open_writer
|
@@ -86,6 +105,10 @@ module DeadlySerious
|
|
86
105
|
@io_name
|
87
106
|
end
|
88
107
|
|
108
|
+
def on_close
|
109
|
+
# Do nothing
|
110
|
+
end
|
111
|
+
|
89
112
|
def open_reader
|
90
113
|
fail %(Pipe "#{@io_name}" not found) unless File.exist?(@io_name)
|
91
114
|
open(@io_name, 'r')
|
@@ -111,6 +134,10 @@ module DeadlySerious
|
|
111
134
|
# Do nothing
|
112
135
|
end
|
113
136
|
|
137
|
+
def on_close
|
138
|
+
# Do nothing
|
139
|
+
end
|
140
|
+
|
114
141
|
def open_reader
|
115
142
|
TCPSocket.new(@host, @port)
|
116
143
|
rescue Exception => e
|
@@ -2,12 +2,18 @@ module DeadlySerious
|
|
2
2
|
module Engine
|
3
3
|
|
4
4
|
# Restrict IO class that opens ONLY
|
5
|
-
# when trying to read something.
|
5
|
+
# when trying to read or write something.
|
6
|
+
# This way, the channel is opened during
|
7
|
+
# the shortest time possible.
|
6
8
|
#
|
7
|
-
#
|
9
|
+
# We also can be used it to reopen channels
|
10
|
+
# when they are closed.
|
8
11
|
#
|
9
|
-
# By "restrict", I mean it implements
|
12
|
+
# By "restrict IO", I mean it implements
|
10
13
|
# just a few IO operations.
|
14
|
+
#
|
15
|
+
# Note: Maybe it can be completely removed.
|
16
|
+
# for the sake of simplicity
|
11
17
|
class LazyIo
|
12
18
|
def initialize(channel)
|
13
19
|
@channel = channel
|
@@ -49,6 +55,7 @@ module DeadlySerious
|
|
49
55
|
|
50
56
|
def close
|
51
57
|
@io.close
|
58
|
+
@channel.on_close
|
52
59
|
@io = nil
|
53
60
|
end
|
54
61
|
|
@@ -6,10 +6,12 @@ module DeadlySerious
|
|
6
6
|
module Engine
|
7
7
|
class Spawner
|
8
8
|
def initialize(data_dir: './data',
|
9
|
-
pipe_dir: "/tmp/deadly_serious/#{Process.pid}",
|
10
|
-
|
9
|
+
pipe_dir: "/tmp/deadly_serious/#{Process.pid}/pipes",
|
10
|
+
lock_dir: "/tmp/deadly_serious/#{Process.pid}/locks",
|
11
|
+
preserve_pipe_dir: false,
|
12
|
+
preserve_lock_dir: false)
|
11
13
|
@ids = []
|
12
|
-
Channel.config(data_dir, pipe_dir, preserve_pipe_dir)
|
14
|
+
Channel.config(data_dir, pipe_dir, lock_dir, preserve_pipe_dir, preserve_lock_dir)
|
13
15
|
end
|
14
16
|
|
15
17
|
def run
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: deadly_serious
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ronie Uliana
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|