Class Irc::MessageQueue
In: lib/rbot/ircsocket.rb
Parent: Object
BasicUserMessage JoinMessage NamesMessage WhoisMessage ModeChangeMessage KickMessage MotdMessage QuitMessage BanlistMessage UserMessage NoSuchTargetMessage TopicMessage NickMessage WelcomeMessage UnknownMessage InviteMessage PartMessage NetmaskList UserList ArrayOf ChannelList Netmask User\n[lib/rbot/botuser.rb\nlib/rbot/irc.rb] Channel Singleton RfcCasemap StrictRfcCasemap AsciiCasemap Casemap PrivMessage NoticeMessage TokyoCabinet::BDB CIBDB Btree CIBtree Socket MessageQueue QueueRing Client DBHash\n[lib/rbot/registry/bdb.rb\nlib/rbot/registry/tc.rb] DBTree\n[lib/rbot/registry/bdb.rb\nlib/rbot/registry/tc.rb] Server NetmaskDb Bot\n[lib/rbot/botuser.rb\nlib/rbot/config.rb\nlib/rbot/ircbot.rb\nlib/rbot/language.rb\nlib/rbot/message.rb\nlib/rbot/messagemapper.rb\nlib/rbot/plugins.rb\nlib/rbot/rbotconfig.rb\nlib/rbot/registry/bdb.rb\nlib/rbot/registry/tc.rb] lib/rbot/ircsocket.rb lib/rbot/rfc2812.rb lib/rbot/registry/tc.rb lib/rbot/irc.rb lib/rbot/maskdb.rb lib/rbot/message.rb lib/rbot/messagemapper.rb lib/rbot/botuser.rb lib/rbot/registry/tc.rb (null) BotConfig PKGConfig ServerOrCasemap Irc dot/m_35_0.png

Methods

clear   empty?   length   new   push   shift   size   unsafe_shift  

Public Class methods

[Source]

     # File lib/rbot/ircsocket.rb, line 153
153:     def initialize
154:       # a MessageQueue is an array of QueueRings
155:       # rings have decreasing priority, so messages in ring 0
156:       # are more important than messages in ring 1, and so on
157:       @rings = Array.new(3) { |i|
158:         if i > 0
159:           QueueRing.new
160:         else
161:           # ring 0 is special in that if it's not empty, it will
162:           # be popped. IOW, ring 0 can starve the other rings
163:           # ring 0 is strictly FIFO and is therefore implemented
164:           # as an array
165:           Array.new
166:         end
167:       }
168:       # the other rings are satisfied round-robin
169:       @last_ring = 0
170:       self.extend(MonitorMixin)
171:       @non_empty = self.new_cond
172:     end

Public Instance methods

[Source]

     # File lib/rbot/ircsocket.rb, line 174
174:     def clear
175:       self.synchronize do
176:         @rings.each { |r| r.clear }
177:         @last_ring = 0
178:       end
179:     end

[Source]

     # File lib/rbot/ircsocket.rb, line 181
181:     def push(mess, chan=nil, cring=0)
182:       ring = cring
183:       self.synchronize do
184:         if ring == 0
185:           warning "message #{mess} at ring 0 has channel #{chan}: channel will be ignored" if !chan.nil?
186:           @rings[0] << mess
187:         else
188:           error "message #{mess} at ring #{ring} must have a channel" if chan.nil?
189:           @rings[ring].push mess, chan
190:         end
191:         @non_empty.signal
192:       end
193:     end

[Source]

     # File lib/rbot/ircsocket.rb, line 195
195:     def shift(tmout = nil)
196:       self.synchronize do
197:         @non_empty.wait(tmout) if self.empty?
198:         return unsafe_shift
199:       end
200:     end

Protected Instance methods

[Source]

     # File lib/rbot/ircsocket.rb, line 204
204:     def empty?
205:       !@rings.find { |r| !r.empty? }
206:     end

[Source]

     # File lib/rbot/ircsocket.rb, line 208
208:     def length
209:       @rings.inject(0) { |s, r| s + r.size }
210:     end
size()

Alias for length

[Source]

     # File lib/rbot/ircsocket.rb, line 213
213:     def unsafe_shift
214:       if !@rings[0].empty?
215:         return @rings[0].shift
216:       end
217:       (@rings.size - 1).times do
218:         @last_ring = (@last_ring % (@rings.size - 1)) + 1
219:         return @rings[@last_ring].shift unless @rings[@last_ring].empty?
220:       end
221:       warning "trying to access an empty message queue"
222:       return nil
223:     end

[Validate]