carnivore-files 0.2.2-java → 0.3.0-java

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: efbd33b4233a2a79fa6084a851e877e7049cb112
4
- data.tar.gz: 03990ee4ba3898b06cba3bb5707f0ae2ff384b10
3
+ metadata.gz: c88542fcad8f3f813897a86e70dbefefeb85a430
4
+ data.tar.gz: f22152fdfe0db531bd0d434b4ca6dc3d360a8fa3
5
5
  SHA512:
6
- metadata.gz: bdd854f660a2ca204a0445d6c7dd4252be6b7713cdb0544b60e96b3bb62b8ed99b183f409c01101aa90e2d74435036e9a1583efe79d33b646c96bbdfa2d27d20
7
- data.tar.gz: 170772e2d4b8f71907e507b2cbfa51e9da6f3b6763e3768e32a98636df1907979ea394958fcc41be3559260e22aede2274d9a68ed2fa41c9e56464612fe7b1c9
6
+ metadata.gz: 98e5d3d64b4e647e18e203570c9d742d66341c82a705b738f6e3471bf2792233e77e1605259b0d7a5ef8a3f0c01f56af58cf31651dfa5986caa91abbcb491486
7
+ data.tar.gz: f29e42c186b24f4dbc276f77a06910bbea68f6135c7e03f6d1b5345373f7bd099d33fc42d286751759f629c64b0f4ddc2bb937c44aa63c8bae19719944dab5e7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # v0.3.0
2
+ * Remove nio based fetcher implementation
3
+ * Add polling based fetcher implementation
4
+
5
+ _NOTE: This release removes nio4r. The source still behaves the same, but
6
+ if specific functionality provided by nio4r was required, it is no
7
+ longer available._
8
+
1
9
  # v0.2.2
2
10
  * Clean up file content fetcher implementations
3
11
 
@@ -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_dependency 'carnivore', '>= 0.1.8'
14
- s.add_dependency 'sleepy_penguin'
15
- s.add_dependency 'nio4r'
13
+ s.add_runtime_dependency 'carnivore', '>= 0.1.8'
14
+ s.add_runtime_dependency 'sleepy_penguin'
15
+ s.add_development_dependency 'pry'
16
16
  s.files = Dir['{lib}/**/**/*'] + %w(carnivore-files.gemspec README.md CHANGELOG.md)
17
17
  end
@@ -22,7 +22,7 @@ module Carnivore
22
22
  def setup(*_)
23
23
  @path = ::File.expand_path(args[:path])
24
24
  unless(args[:foundation])
25
- args[:foundation] = RUBY_PLATFORM == 'java' ? :nio4r : :penguin
25
+ args[:foundation] = RUBY_PLATFORM == 'java' ? :poll : :penguin
26
26
  end
27
27
  end
28
28
 
@@ -30,8 +30,8 @@ module Carnivore
30
30
  def connect
31
31
  @fetcher_name = "log_fetcher_#{name}".to_sym
32
32
  case args[:foundation].to_sym
33
- when :nio, :nio4r
34
- @fetcher = Carnivore::Files::Util::Fetcher::Nio.new(args)
33
+ when :poll
34
+ @fetcher = Carnivore::Files::Util::Fetcher::Poll.new(args)
35
35
  else
36
36
  @fetcher = Carnivore::Files::Util::Fetcher::Penguin.new(args)
37
37
  end
@@ -7,7 +7,7 @@ module Carnivore
7
7
  # Fetch lines from file
8
8
  class Fetcher
9
9
 
10
- autoload :Nio, 'carnivore-files/util/nio'
10
+ autoload :Poll, 'carnivore-files/util/poll'
11
11
  autoload :Penguin, 'carnivore-files/util/penguin'
12
12
 
13
13
  include Celluloid
@@ -0,0 +1,60 @@
1
+ require 'carnivore-files'
2
+
3
+ module Carnivore
4
+ module Files
5
+ module Util
6
+ class Fetcher
7
+
8
+ # Polling fetcher
9
+ class Poll < Fetcher
10
+
11
+ # Start the fetcher
12
+ def start_fetcher
13
+ loop do
14
+ build_io
15
+ ino = io.stat.ino
16
+ retrieve_lines.each do |line|
17
+ self.messages << line
18
+ end
19
+ pos = io.pos
20
+ sleep(1)
21
+ begin
22
+ if(io.size < pos || ino != File.stat(path).ino)
23
+ destroy_io
24
+ @waited = true
25
+ end
26
+ rescue Errno::ENOENT
27
+ destroy_io
28
+ @waited = true
29
+ end
30
+ end
31
+ end
32
+
33
+ # Destroy the IO instance and monitor
34
+ #
35
+ # @return [TrueClass]
36
+ def destroy_io
37
+ if(io)
38
+ io.close
39
+ @io = nil
40
+ end
41
+ true
42
+ end
43
+
44
+ # Wait helper for file to appear (2 second intervals)
45
+ #
46
+ # @return [TrueClass]
47
+ def wait_for_file
48
+ warn "Waiting for file to appear (#{path})"
49
+ until(::File.exists?(path))
50
+ @waited = true
51
+ sleep(2)
52
+ end
53
+ info "File has appeared (#{path})!"
54
+ end
55
+
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -1,6 +1,6 @@
1
1
  module Carnivore
2
2
  module Files
3
3
  # Current version of library
4
- VERSION = Gem::Version.new('0.2.2')
4
+ VERSION = Gem::Version.new('0.3.0')
5
5
  end
6
6
  end
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.2.2
4
+ version: 0.3.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-02-02 00:00:00.000000000 Z
11
+ date: 2015-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carnivore
@@ -25,7 +25,7 @@ dependencies:
25
25
  prerelease: false
26
26
  type: :runtime
27
27
  - !ruby/object:Gem::Dependency
28
- name: nio4r
28
+ name: pry
29
29
  version_requirements: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '>='
@@ -37,7 +37,7 @@ dependencies:
37
37
  - !ruby/object:Gem::Version
38
38
  version: '0'
39
39
  prerelease: false
40
- type: :runtime
40
+ type: :development
41
41
  description: Carnivore file source
42
42
  email: code@chrisroberts.org
43
43
  executables: []
@@ -48,7 +48,7 @@ files:
48
48
  - lib/carnivore-files/carn_file.rb
49
49
  - lib/carnivore-files/version.rb
50
50
  - lib/carnivore-files/util/penguin.rb
51
- - lib/carnivore-files/util/nio.rb
51
+ - lib/carnivore-files/util/poll.rb
52
52
  - lib/carnivore-files/util/fetcher.rb
53
53
  - carnivore-files.gemspec
54
54
  - README.md
@@ -1,98 +0,0 @@
1
- require 'nio'
2
-
3
- module Carnivore
4
- module Files
5
- module Util
6
- class Fetcher
7
-
8
- # NIO based fetcher
9
- class Nio < Fetcher
10
-
11
- # @return [NIO::Monitor]
12
- attr_accessor :monitor
13
- # @return [NIO::Selector]
14
- attr_accessor :selector
15
-
16
- # Create new instance
17
- #
18
- # @param args [Hash] initialization arguments (unused)
19
- def initialize(args={})
20
- super
21
- @selector = NIO::Selector.new
22
- every(5) do
23
- check_file
24
- end
25
- end
26
-
27
- # Start the fetcher
28
- def start_fetcher
29
- loop do
30
- build_io
31
- messages = nil
32
- Celluloid::Future.new{ selector.select }.value.each do |mon|
33
- retrieve_lines.each do |l|
34
- self.messages << l
35
- end
36
- end
37
- end
38
- end
39
-
40
- private
41
-
42
- # Check for file and destroy monitor if file has changed
43
- def check_file
44
- if(io)
45
- begin
46
- unless(io.stat.ino == ::File.stat(path).ino)
47
- destroy_io
48
- @waited = true
49
- end
50
- rescue Errno::ENOENT
51
- destroy_io
52
- end
53
- end
54
- end
55
-
56
- # Build the IO instance if found
57
- #
58
- # @return [TrueClass]
59
- def build_io
60
- result = super
61
- if(result && @monitor.nil?)
62
- @monitor = selector.register(io, :r)
63
- end
64
- result
65
- end
66
-
67
- # Destroy the IO instance and monitor
68
- #
69
- # @return [TrueClass]
70
- def destroy_io
71
- if(monitor)
72
- selector.deregister(monitor)
73
- @monitor = nil
74
- end
75
- if(io)
76
- io.close
77
- @io = nil
78
- end
79
- true
80
- end
81
-
82
- # Wait helper for file to appear (5 sleep second intervals)
83
- #
84
- # @return [TrueClass]
85
- def wait_for_file
86
- warn "Waiting for file to appear (#{path})"
87
- until(::File.exists?(path))
88
- @waited = true
89
- sleep(5)
90
- end
91
- info "File has appeared (#{path})!"
92
- end
93
-
94
- end
95
- end
96
- end
97
- end
98
- end