Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/alt/ruby27/share/ruby/drb
File: gw.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
# Gateway id conversion forms a gateway between different DRb protocols or
[6] Fix | Delete
# networks.
[7] Fix | Delete
#
[8] Fix | Delete
# The gateway needs to install this id conversion and create servers for
[9] Fix | Delete
# each of the protocols or networks it will be a gateway between. It then
[10] Fix | Delete
# needs to create a server that attaches to each of these networks. For
[11] Fix | Delete
# example:
[12] Fix | Delete
#
[13] Fix | Delete
# require 'drb/drb'
[14] Fix | Delete
# require 'drb/unix'
[15] Fix | Delete
# require 'drb/gw'
[16] Fix | Delete
#
[17] Fix | Delete
# DRb.install_id_conv DRb::GWIdConv.new
[18] Fix | Delete
# gw = DRb::GW.new
[19] Fix | Delete
# s1 = DRb::DRbServer.new 'drbunix:/path/to/gateway', gw
[20] Fix | Delete
# s2 = DRb::DRbServer.new 'druby://example:10000', gw
[21] Fix | Delete
#
[22] Fix | Delete
# s1.thread.join
[23] Fix | Delete
# s2.thread.join
[24] Fix | Delete
#
[25] Fix | Delete
# Each client must register services with the gateway, for example:
[26] Fix | Delete
#
[27] Fix | Delete
# DRb.start_service 'drbunix:', nil # an anonymous server
[28] Fix | Delete
# gw = DRbObject.new nil, 'drbunix:/path/to/gateway'
[29] Fix | Delete
# gw[:unix] = some_service
[30] Fix | Delete
# DRb.thread.join
[31] Fix | Delete
[32] Fix | Delete
class GWIdConv < DRbIdConv
[33] Fix | Delete
def to_obj(ref) # :nodoc:
[34] Fix | Delete
if Array === ref && ref[0] == :DRbObject
[35] Fix | Delete
return DRbObject.new_with(ref[1], ref[2])
[36] Fix | Delete
end
[37] Fix | Delete
super(ref)
[38] Fix | Delete
end
[39] Fix | Delete
end
[40] Fix | Delete
[41] Fix | Delete
# The GW provides a synchronized store for participants in the gateway to
[42] Fix | Delete
# communicate.
[43] Fix | Delete
[44] Fix | Delete
class GW
[45] Fix | Delete
include MonitorMixin
[46] Fix | Delete
[47] Fix | Delete
# Creates a new GW
[48] Fix | Delete
[49] Fix | Delete
def initialize
[50] Fix | Delete
super()
[51] Fix | Delete
@hash = {}
[52] Fix | Delete
end
[53] Fix | Delete
[54] Fix | Delete
# Retrieves +key+ from the GW
[55] Fix | Delete
[56] Fix | Delete
def [](key)
[57] Fix | Delete
synchronize do
[58] Fix | Delete
@hash[key]
[59] Fix | Delete
end
[60] Fix | Delete
end
[61] Fix | Delete
[62] Fix | Delete
# Stores value +v+ at +key+ in the GW
[63] Fix | Delete
[64] Fix | Delete
def []=(key, v)
[65] Fix | Delete
synchronize do
[66] Fix | Delete
@hash[key] = v
[67] Fix | Delete
end
[68] Fix | Delete
end
[69] Fix | Delete
end
[70] Fix | Delete
[71] Fix | Delete
class DRbObject # :nodoc:
[72] Fix | Delete
def self._load(s)
[73] Fix | Delete
uri, ref = Marshal.load(s)
[74] Fix | Delete
if DRb.uri == uri
[75] Fix | Delete
return ref ? DRb.to_obj(ref) : DRb.front
[76] Fix | Delete
end
[77] Fix | Delete
[78] Fix | Delete
self.new_with(DRb.uri, [:DRbObject, uri, ref])
[79] Fix | Delete
end
[80] Fix | Delete
[81] Fix | Delete
def _dump(lv)
[82] Fix | Delete
if DRb.uri == @uri
[83] Fix | Delete
if Array === @ref && @ref[0] == :DRbObject
[84] Fix | Delete
Marshal.dump([@ref[1], @ref[2]])
[85] Fix | Delete
else
[86] Fix | Delete
Marshal.dump([@uri, @ref]) # ??
[87] Fix | Delete
end
[88] Fix | Delete
else
[89] Fix | Delete
Marshal.dump([DRb.uri, [:DRbObject, @uri, @ref]])
[90] Fix | Delete
end
[91] Fix | Delete
end
[92] Fix | Delete
end
[93] Fix | Delete
end
[94] Fix | Delete
[95] Fix | Delete
=begin
[96] Fix | Delete
DRb.install_id_conv(DRb::GWIdConv.new)
[97] Fix | Delete
[98] Fix | Delete
front = DRb::GW.new
[99] Fix | Delete
[100] Fix | Delete
s1 = DRb::DRbServer.new('drbunix:/tmp/gw_b_a', front)
[101] Fix | Delete
s2 = DRb::DRbServer.new('drbunix:/tmp/gw_b_c', front)
[102] Fix | Delete
[103] Fix | Delete
s1.thread.join
[104] Fix | Delete
s2.thread.join
[105] Fix | Delete
=end
[106] Fix | Delete
[107] Fix | Delete
=begin
[108] Fix | Delete
# foo.rb
[109] Fix | Delete
[110] Fix | Delete
require 'drb/drb'
[111] Fix | Delete
[112] Fix | Delete
class Foo
[113] Fix | Delete
include DRbUndumped
[114] Fix | Delete
def initialize(name, peer=nil)
[115] Fix | Delete
@name = name
[116] Fix | Delete
@peer = peer
[117] Fix | Delete
end
[118] Fix | Delete
[119] Fix | Delete
def ping(obj)
[120] Fix | Delete
puts "#{@name}: ping: #{obj.inspect}"
[121] Fix | Delete
@peer.ping(self) if @peer
[122] Fix | Delete
end
[123] Fix | Delete
end
[124] Fix | Delete
=end
[125] Fix | Delete
[126] Fix | Delete
=begin
[127] Fix | Delete
# gw_a.rb
[128] Fix | Delete
require 'drb/unix'
[129] Fix | Delete
require 'foo'
[130] Fix | Delete
[131] Fix | Delete
obj = Foo.new('a')
[132] Fix | Delete
DRb.start_service("drbunix:/tmp/gw_a", obj)
[133] Fix | Delete
[134] Fix | Delete
robj = DRbObject.new_with_uri('drbunix:/tmp/gw_b_a')
[135] Fix | Delete
robj[:a] = obj
[136] Fix | Delete
[137] Fix | Delete
DRb.thread.join
[138] Fix | Delete
=end
[139] Fix | Delete
[140] Fix | Delete
=begin
[141] Fix | Delete
# gw_c.rb
[142] Fix | Delete
require 'drb/unix'
[143] Fix | Delete
require 'foo'
[144] Fix | Delete
[145] Fix | Delete
foo = Foo.new('c', nil)
[146] Fix | Delete
[147] Fix | Delete
DRb.start_service("drbunix:/tmp/gw_c", nil)
[148] Fix | Delete
[149] Fix | Delete
robj = DRbObject.new_with_uri("drbunix:/tmp/gw_b_c")
[150] Fix | Delete
[151] Fix | Delete
puts "c->b"
[152] Fix | Delete
a = robj[:a]
[153] Fix | Delete
sleep 2
[154] Fix | Delete
[155] Fix | Delete
a.ping(foo)
[156] Fix | Delete
[157] Fix | Delete
DRb.thread.join
[158] Fix | Delete
=end
[159] Fix | Delete
[160] Fix | Delete
[161] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function