Class: Baykit::BayServer::Protocol::PacketStore
- Inherits:
-
Object
- Object
- Baykit::BayServer::Protocol::PacketStore
show all
- Includes:
- Agent, Util, Util::Reusable
- Defined in:
- lib/baykit/bayserver/protocol/packet_store.rb
Defined Under Namespace
Classes: AgentListener, ProtocolInfo
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(proto, factory) ⇒ PacketStore
65
66
67
68
69
|
# File 'lib/baykit/bayserver/protocol/packet_store.rb', line 65
def initialize(proto, factory)
@protocol = proto
@factory = factory
@store_map = {}
end
|
Class Attribute Details
.proto_map ⇒ Object
Returns the value of attribute proto_map.
57
58
59
|
# File 'lib/baykit/bayserver/protocol/packet_store.rb', line 57
def proto_map
@proto_map
end
|
Instance Attribute Details
#factory ⇒ Object
Returns the value of attribute factory.
63
64
65
|
# File 'lib/baykit/bayserver/protocol/packet_store.rb', line 63
def factory
@factory
end
|
#protocol ⇒ Object
Returns the value of attribute protocol.
61
62
63
|
# File 'lib/baykit/bayserver/protocol/packet_store.rb', line 61
def protocol
@protocol
end
|
#store_map ⇒ Object
Returns the value of attribute store_map.
62
63
64
|
# File 'lib/baykit/bayserver/protocol/packet_store.rb', line 62
def store_map
@store_map
end
|
Class Method Details
.get_store(protocol, agent_id) ⇒ Object
119
120
121
|
# File 'lib/baykit/bayserver/protocol/packet_store.rb', line 119
def self.get_store(protocol, agent_id)
return @proto_map[protocol].stores[agent_id]
end
|
.get_stores(agent_id) ⇒ Object
129
130
131
132
133
134
135
|
# File 'lib/baykit/bayserver/protocol/packet_store.rb', line 129
def self.get_stores(agent_id)
store_list = []
@proto_map.values.each do |ifo|
store_list.append(ifo.stores[agent_id])
end
return store_list
end
|
.init ⇒ Object
115
116
117
|
# File 'lib/baykit/bayserver/protocol/packet_store.rb', line 115
def self.init()
GrandAgent.add_lifecycle_listener(AgentListener.new())
end
|
.register_protocol(protocol, factory) ⇒ Object
123
124
125
126
127
|
# File 'lib/baykit/bayserver/protocol/packet_store.rb', line 123
def self.register_protocol(protocol, factory)
if !@proto_map.include?(protocol)
@proto_map[protocol] = PacketStore::ProtocolInfo.new(protocol, factory)
end
end
|
Instance Method Details
#print_usage(indent) ⇒ Object
104
105
106
107
108
109
110
|
# File 'lib/baykit/bayserver/protocol/packet_store.rb', line 104
def print_usage(indent)
BayLog.info("%sPacketStore(%s) usage nTypes=%d", StringUtil.indent(indent), @protocol, @store_map.keys().size)
@store_map.keys.each do |type|
BayLog.info("%sType: %s", StringUtil.indent(indent+1), type)
@store_map[type].print_usage(indent+2)
end
end
|
#rent(type) ⇒ Object
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/baykit/bayserver/protocol/packet_store.rb', line 77
def rent(type)
if type == nil
raise RuntimeError.new("Nil argument")
end
store = @store_map[type]
if store == nil
store = ObjectStore.new(lambda do
if @factory.kind_of?(PacketFactory)
return @factory.create_packet(type)
else
return @factory.call(type)
end
end)
@store_map[type] = store
end
return store.rent
end
|
#reset ⇒ Object
71
72
73
74
75
|
# File 'lib/baykit/bayserver/protocol/packet_store.rb', line 71
def reset
@store_map.values.each do |store|
store.reset
end
end
|
#Return(pkt) ⇒ Object
97
98
99
100
101
|
# File 'lib/baykit/bayserver/protocol/packet_store.rb', line 97
def Return(pkt)
store = @store_map[pkt.type]
store.Return(pkt)
end
|