Class: Cosmos::PacketBase

Inherits:
Object show all
Defined in:
lib/cosmos/microservices/trigger_group_microservice.rb

Overview

Stored in the TriggerGroupShare this should be a thread safe hash that triggers will be added, updated, and removed from

Instance Method Summary collapse

Constructor Details

#initialize(scope:) ⇒ PacketBase

Returns a new instance of PacketBase.



36
37
38
39
40
# File 'lib/cosmos/microservices/trigger_group_microservice.rb', line 36

def initialize(scope:)
  @scope = scope
  @mutex = Mutex.new
  @packets = Hash.new
end

Instance Method Details

#add(topic:, packet:) ⇒ Object



56
57
58
59
60
# File 'lib/cosmos/microservices/trigger_group_microservice.rb', line 56

def add(topic:, packet:)
  @mutex.synchronize do
    @packets[topic] = packet
  end
end

#get(topic:) ⇒ Object



50
51
52
53
54
# File 'lib/cosmos/microservices/trigger_group_microservice.rb', line 50

def get(topic:)
  @mutex.synchronize do
    return Marshal.load( Marshal.dump(@packets[topic]) )
  end
end

#packet(target:, packet:) ⇒ Object

“#@scope__DECOM__#{@target}__#@packet”


43
44
45
46
47
48
# File 'lib/cosmos/microservices/trigger_group_microservice.rb', line 43

def packet(target:, packet:)
  topic = "#{@scope}__DECOM__{#{target}}__#{packet}"
  @mutex.synchronize do
    return Marshal.load( Marshal.dump(@packets[topic]) )
  end
end

#remove(topic:) ⇒ Object



62
63
64
65
66
# File 'lib/cosmos/microservices/trigger_group_microservice.rb', line 62

def remove(topic:)
  @mutex.synchronize do
    @packets.delete(topic)
  end
end