Class: Smplkit::ContextRegistrationBuffer Private
- Inherits:
-
Object
- Object
- Smplkit::ContextRegistrationBuffer
- Defined in:
- lib/smplkit/buffers.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Thread-safe batch buffer for context registration.
Instance Method Summary collapse
-
#drain ⇒ Object
private
Return and clear the current pending batch.
-
#initialize ⇒ ContextRegistrationBuffer
constructor
private
A new instance of ContextRegistrationBuffer.
-
#observe(contexts) ⇒ Object
private
Queue any unseen contexts.
- #pending_count ⇒ Object private
Constructor Details
#initialize ⇒ ContextRegistrationBuffer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ContextRegistrationBuffer.
39 40 41 42 43 |
# File 'lib/smplkit/buffers.rb', line 39 def initialize @seen = {} @pending = [] @lock = Mutex.new end |
Instance Method Details
#drain ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return and clear the current pending batch.
60 61 62 63 64 65 66 |
# File 'lib/smplkit/buffers.rb', line 60 def drain @lock.synchronize do batch = @pending @pending = [] batch end end |
#observe(contexts) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Queue any unseen contexts.
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/smplkit/buffers.rb', line 46 def observe(contexts) @lock.synchronize do contexts.each do |ctx| cache_key = [ctx.type, ctx.key] next if @seen.key?(cache_key) @seen.shift if @seen.size >= CONTEXT_REGISTRATION_LRU_SIZE @seen[cache_key] = ctx.attributes @pending << { "type" => ctx.type, "key" => ctx.key, "attributes" => ctx.attributes.dup } end end end |
#pending_count ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 |
# File 'lib/smplkit/buffers.rb', line 68 def pending_count @lock.synchronize { @pending.length } end |