$91 GRAYBYTE WORDPRESS FILE MANAGER $24

SERVER : premium201.web-hosting.com #1 SMP Wed Mar 26 12:08:09 UTC 2025
SERVER IP : 172.67.217.254 | ADMIN IP 216.73.216.23
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/alt/ruby21/lib64/ruby/2.1.0/drb/

HOME
Current File : /opt/alt/ruby21/lib64/ruby/2.1.0/drb//timeridconv.rb
require 'drb/drb'
require 'monitor'

module DRb

  # Timer id conversion keeps objects alive for a certain amount of time after
  # their last access.  The default time period is 600 seconds and can be
  # changed upon initialization.
  #
  # To use TimerIdConv:
  #
  #  DRb.install_id_conv TimerIdConv.new 60 # one minute

  class TimerIdConv < DRbIdConv
    class TimerHolder2 # :nodoc:
      include MonitorMixin

      class InvalidIndexError < RuntimeError; end

      def initialize(timeout=600)
        super()
        @sentinel = Object.new
        @gc = {}
        @curr = {}
        @renew = {}
        @timeout = timeout
        @keeper = keeper
      end

      def add(obj)
        synchronize do
          key = obj.__id__
          @curr[key] = obj
          return key
        end
      end

      def fetch(key, dv=@sentinel)
        synchronize do
          obj = peek(key)
          if obj == @sentinel
            return dv unless dv == @sentinel
            raise InvalidIndexError
          end
          @renew[key] = obj # KeepIt
          return obj
        end
      end

      def include?(key)
        synchronize do
          obj = peek(key)
          return false if obj == @sentinel
          true
        end
      end

      def peek(key)
        synchronize do
          return @curr.fetch(key, @renew.fetch(key, @gc.fetch(key, @sentinel)))
        end
      end

      private
      def alternate
        synchronize do
          @gc = @curr       # GCed
          @curr = @renew
          @renew = {}
        end
      end

      def keeper
        Thread.new do
          loop do
            alternate
            sleep(@timeout)
          end
        end
      end
    end

    # Creates a new TimerIdConv which will hold objects for +timeout+ seconds.
    def initialize(timeout=600)
      @holder = TimerHolder2.new(timeout)
    end

    def to_obj(ref) # :nodoc:
      return super if ref.nil?
      @holder.fetch(ref)
    rescue TimerHolder2::InvalidIndexError
      raise "invalid reference"
    end

    def to_id(obj) # :nodoc:
      return @holder.add(obj)
    end
  end
end

# DRb.install_id_conv(TimerIdConv.new)


Current_dir [ NOT WRITEABLE ] Document_root [ NOT WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
3 Mar 2024 10.53 PM
root / root
0755
acl.rb
4.65 KB
19 May 2011 12.07 AM
root / linksafe
0644
drb.rb
55.396 KB
9 Nov 2013 11.13 PM
root / linksafe
0644
eq.rb
0.238 KB
25 Jan 2013 3.25 AM
root / linksafe
0644
extserv.rb
1.201 KB
25 Jan 2013 3.25 AM
root / linksafe
0644
extservm.rb
1.71 KB
22 Apr 2012 11.35 AM
root / linksafe
0644
gw.rb
2.97 KB
25 Jan 2013 3.25 AM
root / linksafe
0644
invokemethod.rb
0.729 KB
23 Jul 2013 12.28 AM
root / linksafe
0644
observer.rb
0.621 KB
25 Jan 2013 3.25 AM
root / linksafe
0644
ssl.rb
11.507 KB
13 Dec 2013 4.11 PM
root / linksafe
0644
timeridconv.rb
2.111 KB
25 Jan 2013 3.25 AM
root / linksafe
0644
unix.rb
2.719 KB
25 Jan 2013 3.25 AM
root / linksafe
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2025 CONTACT ME
Static GIF