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
#created_at, #metadata, #modified_at, #state, #unique_id
Instance Method Summary
collapse
Methods inherited from Chunk
#append, #close, #closed?, #enqueued!, #queued?, #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
56
57
58
|
# File 'lib/fluent/plugin/buffer/memory_chunk.rb', line 56
def bytesize
@chunk_bytes + @adding_bytes
end
|
#commit ⇒ Object
41
42
43
44
45
46
47
48
|
# 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 = Time.now
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
64
65
66
|
# File 'lib/fluent/plugin/buffer/memory_chunk.rb', line 64
def empty?
@chunk.empty?
end
|
#open(**kwargs, &block) ⇒ Object
79
80
81
|
# File 'lib/fluent/plugin/buffer/memory_chunk.rb', line 79
def open(**kwargs, &block)
StringIO.open(@chunk, &block)
end
|
#purge ⇒ Object
68
69
70
71
72
73
|
# File 'lib/fluent/plugin/buffer/memory_chunk.rb', line 68
def purge
super
@chunk = ''.force_encoding("ASCII-8BIT")
@chunk_bytes = @size = @adding_bytes = @adding_size = 0
true
end
|
#read(**kwargs) ⇒ Object
75
76
77
|
# File 'lib/fluent/plugin/buffer/memory_chunk.rb', line 75
def read(**kwargs)
@chunk
end
|
#rollback ⇒ Object
50
51
52
53
54
|
# File 'lib/fluent/plugin/buffer/memory_chunk.rb', line 50
def rollback
@chunk.slice!(@chunk_bytes, @adding_bytes)
@adding_bytes = @adding_size = 0
true
end
|
#size ⇒ Object
60
61
62
|
# File 'lib/fluent/plugin/buffer/memory_chunk.rb', line 60
def size
@size + @adding_size
end
|
#write_to(io, **kwargs) ⇒ Object
83
84
85
86
|
# File 'lib/fluent/plugin/buffer/memory_chunk.rb', line 83
def write_to(io, **kwargs)
io.write @chunk
end
|