Class: Fluent::Plugin::Buffer::MemoryChunk
- Inherits:
-
Chunk
- Object
- Chunk
- Fluent::Plugin::Buffer::MemoryChunk
show all
- Defined in:
- lib/fluent/plugin/buffer/memory_chunk.rb
Instance Attribute Summary
Attributes inherited from Chunk
#metadata, #state, #unique_id
Instance Method Summary
collapse
Methods inherited from Chunk
#append, #close, #closed?, #created_at, #enqueued!, #modified_at, #queued?, #raw_create_at, #raw_modified_at, #staged!, #staged?, #unstaged!, #unstaged?, #writable?
#dump_unique_id_hex, #generate_unique_id
Constructor Details
#initialize(metadata, compress: :text) ⇒ MemoryChunk
Returns a new instance of MemoryChunk.
23
24
25
26
27
28
29
|
# File 'lib/fluent/plugin/buffer/memory_chunk.rb', line 23
def initialize(metadata, compress: :text)
super
@chunk = ''.force_encoding(Encoding::ASCII_8BIT)
@chunk_bytes = 0
@adding_bytes = 0
@adding_size = 0
end
|
Instance Method Details
#bytesize ⇒ Object
57
58
59
|
# File 'lib/fluent/plugin/buffer/memory_chunk.rb', line 57
def bytesize
@chunk_bytes + @adding_bytes
end
|
#commit ⇒ Object
41
42
43
44
45
46
47
48
49
|
# File 'lib/fluent/plugin/buffer/memory_chunk.rb', line 41
def commit
@size += @adding_size
@chunk_bytes += @adding_bytes
@adding_bytes = @adding_size = 0
@modified_at = Fluent::Clock.real_now
@modified_at_object = nil
true
end
|
#concat(bulk, bulk_size) ⇒ Object
31
32
33
34
35
36
37
38
39
|
# File 'lib/fluent/plugin/buffer/memory_chunk.rb', line 31
def concat(bulk, bulk_size)
raise "BUG: concatenating to unwritable chunk, now '#{self.state}'" unless self.writable?
bulk.force_encoding(Encoding::ASCII_8BIT)
@chunk << bulk
@adding_bytes += bulk.bytesize
@adding_size += bulk_size
true
end
|
#empty? ⇒ Boolean
65
66
67
|
# File 'lib/fluent/plugin/buffer/memory_chunk.rb', line 65
def empty?
@chunk.empty?
end
|
#open(**kwargs, &block) ⇒ Object
80
81
82
|
# File 'lib/fluent/plugin/buffer/memory_chunk.rb', line 80
def open(**kwargs, &block)
StringIO.open(@chunk, &block)
end
|
#purge ⇒ Object
69
70
71
72
73
74
|
# File 'lib/fluent/plugin/buffer/memory_chunk.rb', line 69
def purge
super
@chunk = ''.force_encoding("ASCII-8BIT")
@chunk_bytes = @size = @adding_bytes = @adding_size = 0
true
end
|
#read(**kwargs) ⇒ Object
76
77
78
|
# File 'lib/fluent/plugin/buffer/memory_chunk.rb', line 76
def read(**kwargs)
@chunk
end
|
#rollback ⇒ Object
51
52
53
54
55
|
# File 'lib/fluent/plugin/buffer/memory_chunk.rb', line 51
def rollback
@chunk.slice!(@chunk_bytes, @adding_bytes)
@adding_bytes = @adding_size = 0
true
end
|
#size ⇒ Object
61
62
63
|
# File 'lib/fluent/plugin/buffer/memory_chunk.rb', line 61
def size
@size + @adding_size
end
|
#write_to(io, **kwargs) ⇒ Object
84
85
86
87
|
# File 'lib/fluent/plugin/buffer/memory_chunk.rb', line 84
def write_to(io, **kwargs)
io.write @chunk
end
|