class Rock::WebApp::Tasks::CachedPorts::PortEntry
Attributes
timer[RW]
Public Class Methods
new(port, timeout, init=false)
click to toggle source
if timeout ==0, there will be no timeout
# File lib/rock/webapp/tasks/cached_ports.rb, line 15 def initialize(port, timeout, init=false) @end_lifetime = Time.at(Time.now + timeout) #puts "new port will time out at #{@end_lifetime}" if port.respond_to?(:writer) @writer = port.writer end if port.respond_to?(:reader) @reader = port.reader(init: init, pull: true) end @port = port end
Public Instance Methods
connected?()
click to toggle source
# File lib/rock/webapp/tasks/cached_ports.rb, line 86 def connected? if reader_or_writer.connected? return true else @end_lifetime = Time.at(0) #start of epoch, definately tiimed out return false end end
is_reader?()
click to toggle source
# File lib/rock/webapp/tasks/cached_ports.rb, line 35 def is_reader? @port.respond_to?(:reader) end
is_writer?()
click to toggle source
# File lib/rock/webapp/tasks/cached_ports.rb, line 31 def is_writer? @port.respond_to?(:writer) end
lifetime_left()
click to toggle source
# File lib/rock/webapp/tasks/cached_ports.rb, line 95 def lifetime_left return @end_lifetime - Time.now end
name()
click to toggle source
# File lib/rock/webapp/tasks/cached_ports.rb, line 39 def name @port.name end
port()
click to toggle source
# File lib/rock/webapp/tasks/cached_ports.rb, line 51 def port @port end
read(obj, timeout)
click to toggle source
# File lib/rock/webapp/tasks/cached_ports.rb, line 71 def read(obj, timeout) if self.connected? new_end = Time.at(Time.now + timeout) if new_end > @end_lifetime @end_lifetime = new_end #puts "existing read port will now time out at #{@end_lifetime}" end @reader.read(obj) end end
reader()
click to toggle source
# File lib/rock/webapp/tasks/cached_ports.rb, line 43 def reader @reader end
reader_or_writer()
click to toggle source
# File lib/rock/webapp/tasks/cached_ports.rb, line 82 def reader_or_writer @reader || @writer end
timer=(value)
click to toggle source
# File lib/rock/webapp/tasks/cached_ports.rb, line 55 def timer=(value) @timer=value end
write(obj, timeout)
click to toggle source
# File lib/rock/webapp/tasks/cached_ports.rb, line 59 def write(obj, timeout) if self.connected? new_end = Time.at(Time.now + timeout) #puts "old:\t#{@end_lifetime}\nnew:\t#{new_end}" if new_end > @end_lifetime @end_lifetime = new_end #puts "existing write port will now time out at #{@end_lifetime}" end @writer.write(obj) end end
writer()
click to toggle source
# File lib/rock/webapp/tasks/cached_ports.rb, line 47 def writer @writer end