Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby27/share/ruby/drb
File: timeridconv.rb
# frozen_string_literal: false
[0] Fix | Delete
require_relative 'drb'
[1] Fix | Delete
require 'monitor'
[2] Fix | Delete
[3] Fix | Delete
module DRb
[4] Fix | Delete
[5] Fix | Delete
# Timer id conversion keeps objects alive for a certain amount of time after
[6] Fix | Delete
# their last access. The default time period is 600 seconds and can be
[7] Fix | Delete
# changed upon initialization.
[8] Fix | Delete
#
[9] Fix | Delete
# To use TimerIdConv:
[10] Fix | Delete
#
[11] Fix | Delete
# DRb.install_id_conv TimerIdConv.new 60 # one minute
[12] Fix | Delete
[13] Fix | Delete
class TimerIdConv < DRbIdConv
[14] Fix | Delete
class TimerHolder2 # :nodoc:
[15] Fix | Delete
include MonitorMixin
[16] Fix | Delete
[17] Fix | Delete
class InvalidIndexError < RuntimeError; end
[18] Fix | Delete
[19] Fix | Delete
def initialize(keeping=600)
[20] Fix | Delete
super()
[21] Fix | Delete
@sentinel = Object.new
[22] Fix | Delete
@gc = {}
[23] Fix | Delete
@renew = {}
[24] Fix | Delete
@keeping = keeping
[25] Fix | Delete
@expires = nil
[26] Fix | Delete
end
[27] Fix | Delete
[28] Fix | Delete
def add(obj)
[29] Fix | Delete
synchronize do
[30] Fix | Delete
rotate
[31] Fix | Delete
key = obj.__id__
[32] Fix | Delete
@renew[key] = obj
[33] Fix | Delete
invoke_keeper
[34] Fix | Delete
return key
[35] Fix | Delete
end
[36] Fix | Delete
end
[37] Fix | Delete
[38] Fix | Delete
def fetch(key)
[39] Fix | Delete
synchronize do
[40] Fix | Delete
rotate
[41] Fix | Delete
obj = peek(key)
[42] Fix | Delete
raise InvalidIndexError if obj == @sentinel
[43] Fix | Delete
@renew[key] = obj # KeepIt
[44] Fix | Delete
return obj
[45] Fix | Delete
end
[46] Fix | Delete
end
[47] Fix | Delete
[48] Fix | Delete
private
[49] Fix | Delete
def peek(key)
[50] Fix | Delete
return @renew.fetch(key) { @gc.fetch(key, @sentinel) }
[51] Fix | Delete
end
[52] Fix | Delete
[53] Fix | Delete
def invoke_keeper
[54] Fix | Delete
return if @expires
[55] Fix | Delete
@expires = Time.now + @keeping
[56] Fix | Delete
on_gc
[57] Fix | Delete
end
[58] Fix | Delete
[59] Fix | Delete
def on_gc
[60] Fix | Delete
return unless Thread.main.alive?
[61] Fix | Delete
return if @expires.nil?
[62] Fix | Delete
Thread.new { rotate } if @expires < Time.now
[63] Fix | Delete
ObjectSpace.define_finalizer(Object.new) {on_gc}
[64] Fix | Delete
end
[65] Fix | Delete
[66] Fix | Delete
def rotate
[67] Fix | Delete
synchronize do
[68] Fix | Delete
if @expires &.< Time.now
[69] Fix | Delete
@gc = @renew # GCed
[70] Fix | Delete
@renew = {}
[71] Fix | Delete
@expires = @gc.empty? ? nil : Time.now + @keeping
[72] Fix | Delete
end
[73] Fix | Delete
end
[74] Fix | Delete
end
[75] Fix | Delete
end
[76] Fix | Delete
[77] Fix | Delete
# Creates a new TimerIdConv which will hold objects for +keeping+ seconds.
[78] Fix | Delete
def initialize(keeping=600)
[79] Fix | Delete
@holder = TimerHolder2.new(keeping)
[80] Fix | Delete
end
[81] Fix | Delete
[82] Fix | Delete
def to_obj(ref) # :nodoc:
[83] Fix | Delete
return super if ref.nil?
[84] Fix | Delete
@holder.fetch(ref)
[85] Fix | Delete
rescue TimerHolder2::InvalidIndexError
[86] Fix | Delete
raise "invalid reference"
[87] Fix | Delete
end
[88] Fix | Delete
[89] Fix | Delete
def to_id(obj) # :nodoc:
[90] Fix | Delete
return @holder.add(obj)
[91] Fix | Delete
end
[92] Fix | Delete
end
[93] Fix | Delete
end
[94] Fix | Delete
[95] Fix | Delete
# DRb.install_id_conv(TimerIdConv.new)
[96] Fix | Delete
[97] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function