carnivore-files 0.3.2-java → 0.5.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/carnivore-files.gemspec +2 -2
- data/lib/carnivore-files/carn_file.rb +7 -27
- data/lib/carnivore-files/util/fetcher.rb +6 -6
- data/lib/carnivore-files/util/penguin.rb +2 -4
- data/lib/carnivore-files/version.rb +1 -1
- metadata +10 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36021a5eb3149186d4a24b255aa786bb03ad8af6
|
4
|
+
data.tar.gz: 30c76d4a1e0db3149b0c874404b8a2a83f48b67c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a14f707b7ec20453e2bd9d1088a5de96d66ce7da628229b94587f00983d828346590e7d50282941c7f17239f1fefc9dd749513de54ee1e39b2c0ac41d771da4
|
7
|
+
data.tar.gz: 1ca9d397965ded62770a8019b030105e63647e0febfa21979c7fa609ab0aa3934bbb5955ba19b0435e10a44321b15498be8e5d531dd1c4b23bbdb46dab788ef2
|
data/CHANGELOG.md
CHANGED
data/carnivore-files.gemspec
CHANGED
@@ -10,8 +10,8 @@ spec = Gem::Specification.new do |s|
|
|
10
10
|
s.description = 'Carnivore file source'
|
11
11
|
s.license = 'Apache 2.0'
|
12
12
|
s.require_path = 'lib'
|
13
|
-
s.add_runtime_dependency 'carnivore', '>= 0.
|
14
|
-
s.add_runtime_dependency 'sleepy_penguin'
|
13
|
+
s.add_runtime_dependency 'carnivore', '>= 1.0.0', '< 2.0.0'
|
14
|
+
s.add_runtime_dependency 'sleepy_penguin', '~> 3.4'
|
15
15
|
s.add_development_dependency 'pry'
|
16
16
|
s.files = Dir['{lib}/**/**/*'] + %w(carnivore-files.gemspec README.md CHANGELOG.md)
|
17
17
|
end
|
@@ -9,18 +9,17 @@ module Carnivore
|
|
9
9
|
attr_reader :path
|
10
10
|
# @return [Symbol] registry name of fetcher
|
11
11
|
attr_reader :fetcher
|
12
|
-
|
13
|
-
|
14
|
-
finalizer :fetcher_destroyer
|
12
|
+
# @return [Queue] queue to hold messages
|
13
|
+
attr_reader :message_queue
|
15
14
|
|
16
15
|
# Setup source
|
17
16
|
#
|
18
17
|
# @param args [Hash]
|
19
18
|
# @option args [String] :path path to file
|
20
19
|
# @option args [Symbol] :foundation underlying file interaction library
|
21
|
-
# @option args [Celluloid::Actor] :notify_actor actor to notify on line receive
|
22
20
|
def setup(*_)
|
23
21
|
@path = ::File.expand_path(args[:path])
|
22
|
+
@message_queue = Queue.new
|
24
23
|
unless(args[:foundation])
|
25
24
|
args[:foundation] = RUBY_PLATFORM == 'java' ? :poll : :penguin
|
26
25
|
end
|
@@ -28,37 +27,18 @@ module Carnivore
|
|
28
27
|
|
29
28
|
# Start the line fetcher
|
30
29
|
def connect
|
31
|
-
@fetcher_name = "log_fetcher_#{name}".to_sym
|
32
30
|
case args[:foundation].to_sym
|
33
31
|
when :poll
|
34
|
-
@fetcher = Carnivore::Files::Util::Fetcher::Poll.new(args)
|
32
|
+
@fetcher = Carnivore::Files::Util::Fetcher::Poll.new(args.merge(:queue => message_queue))
|
35
33
|
else
|
36
|
-
@fetcher = Carnivore::Files::Util::Fetcher::Penguin.new(args)
|
34
|
+
@fetcher = Carnivore::Files::Util::Fetcher::Penguin.new(args.merge(:queue => message_queue))
|
37
35
|
end
|
38
|
-
self.link fetcher
|
39
36
|
fetcher.async.start_fetcher
|
40
37
|
end
|
41
38
|
|
42
|
-
# Restart file collector if unexpectedly failed
|
43
|
-
#
|
44
|
-
# @param object [Actor] crashed actor
|
45
|
-
# @param reason [Exception, NilClass]
|
46
|
-
def fetcher_failure(object, reason)
|
47
|
-
if(reason && object == fetcher)
|
48
|
-
error "File message collector unexpectedly failed: #{reason} (restarting)"
|
49
|
-
connect
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def fetcher_destroyer
|
54
|
-
if(fetcher && fetcher.alive?)
|
55
|
-
fetcher.terminate
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
39
|
# @return [Array<Hash>] return messages
|
60
|
-
def receive(*
|
61
|
-
|
40
|
+
def receive(*_)
|
41
|
+
defer{ message_queue.pop }
|
62
42
|
end
|
63
43
|
|
64
44
|
# Send payload
|
@@ -10,7 +10,8 @@ module Carnivore
|
|
10
10
|
autoload :Poll, 'carnivore-files/util/poll'
|
11
11
|
autoload :Penguin, 'carnivore-files/util/penguin'
|
12
12
|
|
13
|
-
include
|
13
|
+
include Zoidberg::SoftShell
|
14
|
+
include Zoidberg::Supervise
|
14
15
|
include Carnivore::Utils::Logging
|
15
16
|
|
16
17
|
# @return [String] path to file
|
@@ -28,12 +29,11 @@ module Carnivore
|
|
28
29
|
# @param args [Hash] initialization args
|
29
30
|
# @option args [String] :path path to file
|
30
31
|
# @option args [String] :delimiter string delimiter to break messages
|
31
|
-
# @option args [Celluloid::Actor] :notify_actor actor to be notified on new messages
|
32
32
|
def initialize(args={})
|
33
33
|
@leftover = ''
|
34
34
|
@path = ::File.expand_path(args[:path])
|
35
35
|
@delimiter = args.fetch(:delimiter, "\n")
|
36
|
-
@messages = Queue.new
|
36
|
+
@messages = args.fetch(:queue, Queue.new)
|
37
37
|
end
|
38
38
|
|
39
39
|
# Start the line fetcher
|
@@ -57,10 +57,9 @@ module Carnivore
|
|
57
57
|
def retrieve_lines
|
58
58
|
if(io)
|
59
59
|
io.pos = @history_pos if @history_pos
|
60
|
-
|
60
|
+
@leftover << io.read(4096).to_s
|
61
61
|
while(data = io.read(4096))
|
62
|
-
@leftover << data
|
63
|
-
data = io.read(4096)
|
62
|
+
@leftover << data.to_s
|
64
63
|
end
|
65
64
|
@history_pos = io.pos
|
66
65
|
result = @leftover.split(delimiter)
|
@@ -77,6 +76,7 @@ module Carnivore
|
|
77
76
|
def build_io
|
78
77
|
unless(io)
|
79
78
|
if(::File.exists?(path))
|
79
|
+
@history_pos = 0
|
80
80
|
@io = ::File.open(path, 'r')
|
81
81
|
unless(@waited)
|
82
82
|
@io.seek(0, ::IO::SEEK_END) # fast-forward to EOF
|
@@ -5,7 +5,6 @@ module Carnivore
|
|
5
5
|
module Util
|
6
6
|
class Fetcher
|
7
7
|
|
8
|
-
|
9
8
|
# NIO based fetcher
|
10
9
|
class Penguin < Fetcher
|
11
10
|
# @return [SP::Inotify]
|
@@ -27,7 +26,7 @@ module Carnivore
|
|
27
26
|
loop do
|
28
27
|
build_io
|
29
28
|
notify.each do |event|
|
30
|
-
|
29
|
+
defer{ event.events }.each do |ev|
|
31
30
|
case ev
|
32
31
|
when :MODIFY
|
33
32
|
retrieve_lines.each do |l|
|
@@ -47,7 +46,6 @@ module Carnivore
|
|
47
46
|
end
|
48
47
|
end
|
49
48
|
|
50
|
-
|
51
49
|
private
|
52
50
|
|
53
51
|
# Build the IO and monitor
|
@@ -84,7 +82,7 @@ module Carnivore
|
|
84
82
|
notify_descriptors[:file_wait] = notify.add_watch(directory, :OPEN)
|
85
83
|
until(notified)
|
86
84
|
warn "Waiting for file to appear (#{path})"
|
87
|
-
event =
|
85
|
+
event = defer{ notify.take }
|
88
86
|
notified = ::File.exists?(path)
|
89
87
|
end
|
90
88
|
notify.rm_watch(notify_descriptors.delete(:file_wait))
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: carnivore-files
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Chris Roberts
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: carnivore
|
@@ -16,14 +16,20 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 1.0.0
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 2.0.0
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - ">="
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
29
|
+
version: 1.0.0
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 2.0.0
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: pry
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|