Class: DRb::DRbServer
- Inherits:
-
Object
- Object
- DRb::DRbServer
- Defined in:
- lib/drb/drb.rb,
lib/drb/invokemethod.rb
Overview
:nodoc: all
Defined Under Namespace
Modules: InvokeMethod18Mixin Classes: InvokeMethod
Constant Summary collapse
- @@acl =
nil
- @@idconv =
DRbIdConv.new
- @@secondary_server =
nil
- @@argc_limit =
256
- @@load_limit =
0xffffffff
- @@verbose =
false
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
The configuration of this DRbServer.
-
#front ⇒ Object
readonly
The front object of the DRbServer.
-
#thread ⇒ Object
readonly
The main thread of this DRbServer.
-
#uri ⇒ Object
readonly
The URI of this DRbServer.
Class Method Summary collapse
-
.default_acl(acl) ⇒ Object
Set the default access control list to
acl
. -
.default_argc_limit(argc) ⇒ Object
Set the default value for the :argc_limit option.
-
.default_id_conv(idconv) ⇒ Object
Set the default value for the :id_conv option.
-
.default_load_limit(sz) ⇒ Object
Set the default value for the :load_limit option.
-
.make_config(hash = {}) ⇒ Object
:nodoc:.
-
.verbose ⇒ Object
Get the default value of the :verbose option.
-
.verbose=(on) ⇒ Object
Set the default value of the :verbose option.
Instance Method Summary collapse
-
#alive? ⇒ Boolean
Is this server alive?.
-
#check_insecure_method(obj, msg_id) ⇒ Object
Check that a method is callable via dRuby.
-
#here?(uri) ⇒ Boolean
Is
uri
the URI for this server?. -
#initialize(uri = nil, front = nil, config_or_acl = nil) ⇒ DRbServer
constructor
Create a new DRbServer instance.
-
#stop_service ⇒ Object
Stop this server.
-
#to_id(obj) ⇒ Object
Convert a local object to a dRuby reference.
-
#to_obj(ref) ⇒ Object
Convert a dRuby reference to the local object it refers to.
-
#verbose ⇒ Object
Get whether the server is in verbose mode.
-
#verbose=(v) ⇒ Object
Set whether to operate in verbose mode.
Constructor Details
#initialize(uri = nil, front = nil, config_or_acl = nil) ⇒ DRbServer
Create a new DRbServer instance.
uri
is the URI to bind to. This is normally of the form ‘druby://<hostname>:<port>’ where <hostname> is a hostname of the local machine. If nil, then the system’s default hostname will be bound to, on a port selected by the system; these value can be retrieved from the uri
attribute. ‘druby:’ specifies the default dRuby transport protocol: another protocol, such as ‘drbunix:’, can be specified instead.
front
is the front object for the server, that is, the object to which remote method calls on the server will be passed. If nil, then the server will not accept remote method calls.
If config_or_acl
is a hash, it is the configuration to use for this server. The following options are recognised:
- :idconv
-
an id-to-object conversion object. This defaults to an instance of the class DRb::DRbIdConv.
- :verbose
-
if true, all unsuccessful remote calls on objects in the server will be logged to $stdout. false by default.
- :tcp_acl
-
the access control list for this server. See the ACL class from the main dRuby distribution.
- :load_limit
-
the maximum message size in bytes accepted by the server. Defaults to 25 MB (26214400).
- :argc_limit
-
the maximum number of arguments to a remote method accepted by the server. Defaults to 256.
The default values of these options can be modified on a class-wide basis by the class methods #default_argc_limit, #default_load_limit, #default_acl, #default_id_conv, and #verbose=
If config_or_acl
is not a hash, but is not nil, it is assumed to be the access control list for this server. See the :tcp_acl option for more details.
If no other server is currently set as the primary server, this will become the primary server.
The server will immediately start running in its own thread.
1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 |
# File 'lib/drb/drb.rb', line 1450 def initialize(uri=nil, front=nil, config_or_acl=nil) if Hash === config_or_acl config = config_or_acl.dup else acl = config_or_acl || @@acl config = { :tcp_acl => acl } end @config = self.class.make_config(config) @protocol = DRbProtocol.open_server(uri, @config) @uri = @protocol.uri @exported_uri = [@uri] @front = front @idconv = @config[:idconv] @grp = ThreadGroup.new @thread = run DRb.regist_server(self) end |
Instance Attribute Details
#config ⇒ Object (readonly)
The configuration of this DRbServer
1492 1493 1494 |
# File 'lib/drb/drb.rb', line 1492 def config @config end |
#front ⇒ Object (readonly)
The front object of the DRbServer.
This object receives remote method calls made on the server’s URI alone, with an object id.
1489 1490 1491 |
# File 'lib/drb/drb.rb', line 1489 def front @front end |
#thread ⇒ Object (readonly)
The main thread of this DRbServer.
This is the thread that listens for and accepts connections from clients, not that handles each client’s request-response session.
1483 1484 1485 |
# File 'lib/drb/drb.rb', line 1483 def thread @thread end |
#uri ⇒ Object (readonly)
The URI of this DRbServer.
1476 1477 1478 |
# File 'lib/drb/drb.rb', line 1476 def uri @uri end |
Class Method Details
.default_acl(acl) ⇒ Object
Set the default access control list to acl
. The default ACL is nil
.
See also DRb::ACL and #new()
1374 1375 1376 |
# File 'lib/drb/drb.rb', line 1374 def self.default_acl(acl) @@acl = acl end |
.default_argc_limit(argc) ⇒ Object
Set the default value for the :argc_limit option.
See #new(). The initial default value is 256.
1360 1361 1362 |
# File 'lib/drb/drb.rb', line 1360 def self.default_argc_limit(argc) @@argc_limit = argc end |
.default_id_conv(idconv) ⇒ Object
Set the default value for the :id_conv option.
See #new(). The initial default value is a DRbIdConv instance.
1381 1382 1383 |
# File 'lib/drb/drb.rb', line 1381 def self.default_id_conv(idconv) @@idconv = idconv end |
.default_load_limit(sz) ⇒ Object
Set the default value for the :load_limit option.
See #new(). The initial default value is 25 MB.
1367 1368 1369 |
# File 'lib/drb/drb.rb', line 1367 def self.default_load_limit(sz) @@load_limit = sz end |
.make_config(hash = {}) ⇒ Object
:nodoc:
1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 |
# File 'lib/drb/drb.rb', line 1397 def self.make_config(hash={}) # :nodoc: default_config = { :idconv => @@idconv, :verbose => @@verbose, :tcp_acl => @@acl, :load_limit => @@load_limit, :argc_limit => @@argc_limit, } default_config.update(hash) end |
.verbose ⇒ Object
Get the default value of the :verbose option.
1393 1394 1395 |
# File 'lib/drb/drb.rb', line 1393 def self.verbose @@verbose end |
.verbose=(on) ⇒ Object
Set the default value of the :verbose option.
See #new(). The initial default value is false.
1388 1389 1390 |
# File 'lib/drb/drb.rb', line 1388 def self.verbose=(on) @@verbose = on end |
Instance Method Details
#alive? ⇒ Boolean
Is this server alive?
1505 1506 1507 |
# File 'lib/drb/drb.rb', line 1505 def alive? @thread.alive? end |
#check_insecure_method(obj, msg_id) ⇒ Object
Check that a method is callable via dRuby.
obj
is the object we want to invoke the method on. msg_id
is the method name, as a Symbol.
If the method is an insecure method (see #insecure_method?) a SecurityError is thrown. If the method is private or undefined, a NameError is thrown.
1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 |
# File 'lib/drb/drb.rb', line 1593 def check_insecure_method(obj, msg_id) return true if Proc === obj && msg_id == :__drb_yield raise(ArgumentError, "#{any_to_s(msg_id)} is not a symbol") unless Symbol == msg_id.class raise(SecurityError, "insecure method `#{msg_id}'") if insecure_method?(msg_id) case obj when Object if obj.private_methods.include?(msg_id) desc = any_to_s(obj) raise NoMethodError, "private method `#{msg_id}' called for #{desc}" elsif obj.protected_methods.include?(msg_id) desc = any_to_s(obj) raise NoMethodError, "protected method `#{msg_id}' called for #{desc}" else true end else if Kernel.instance_method(:private_methods).bind(obj).call.include?(msg_id) desc = any_to_s(obj) raise NoMethodError, "private method `#{msg_id}' called for #{desc}" elsif Kernel.instance_method(:protected_methods).bind(obj).call.include?(msg_id) desc = any_to_s(obj) raise NoMethodError, "protected method `#{msg_id}' called for #{desc}" else true end end end |
#here?(uri) ⇒ Boolean
Is uri
the URI for this server?
1510 1511 1512 |
# File 'lib/drb/drb.rb', line 1510 def here?(uri) @exported_uri.include?(uri) end |
#stop_service ⇒ Object
Stop this server.
1515 1516 1517 1518 1519 1520 1521 1522 |
# File 'lib/drb/drb.rb', line 1515 def stop_service DRb.remove_server(self) if Thread.current['DRb'] && Thread.current['DRb']['server'] == self Thread.current['DRb']['stop_service'] = true else shutdown end end |
#to_id(obj) ⇒ Object
Convert a local object to a dRuby reference.
1532 1533 1534 1535 |
# File 'lib/drb/drb.rb', line 1532 def to_id(obj) return nil if obj.__id__ == front.__id__ @idconv.to_id(obj) end |
#to_obj(ref) ⇒ Object
Convert a dRuby reference to the local object it refers to.
1525 1526 1527 1528 1529 |
# File 'lib/drb/drb.rb', line 1525 def to_obj(ref) return front if ref.nil? return front[ref.to_s] if DRbURIOption === ref @idconv.to_obj(ref) end |
#verbose ⇒ Object
Get whether the server is in verbose mode.
In verbose mode, failed calls are logged to stdout.
1502 |
# File 'lib/drb/drb.rb', line 1502 def verbose; @config[:verbose]; end |
#verbose=(v) ⇒ Object
Set whether to operate in verbose mode.
In verbose mode, failed calls are logged to stdout.
1497 |
# File 'lib/drb/drb.rb', line 1497 def verbose=(v); @config[:verbose]=v; end |