Class: DRb::DRbServer
Overview
Class representing a drb server instance.
A DRbServer must be running in the local process before any incoming dRuby calls can be accepted, or any local objects can be passed as dRuby references to remote processes, even if those local objects are never actually called remotely. You do not need to start a DRbServer in the local process if you are only making outgoing dRuby calls passing marshalled parameters.
Unless multiple servers are being used, the local DRbServer is normally started by calling DRb.start_service.
Defined Under Namespace
Modules: InvokeMethod18Mixin Classes: InvokeMethod
Constant Summary
- INSECURE_METHOD =
List of insecure methods.
These methods are not callable via dRuby.
[ :__send__ ]
- @@acl =
nil- @@idconv =
DRbIdConv.new
- @@secondary_server =
nil- @@argc_limit =
256- @@load_limit =
256 * 102400
- @@verbose =
false- @@safe_level =
0
Instance Attribute Summary (collapse)
-
- (Object) config
readonly
The configuration of this DRbServer.
-
- (Object) front
readonly
The front object of the DRbServer.
-
- (Object) safe_level
readonly
Returns the value of attribute safe_level.
-
- (Object) thread
readonly
The main thread of this DRbServer.
-
- (Object) uri
readonly
The URI of this DRbServer.
Class Method Summary (collapse)
-
+ (Object) default_acl(acl)
Set the default value for the :acl option.
-
+ (Object) default_argc_limit(argc)
Set the default value for the :argc_limit option.
-
+ (Object) default_id_conv(idconv)
Set the default value for the :id_conv option.
-
+ (Object) default_load_limit(sz)
Set the default value for the :load_limit option.
- + (Object) default_safe_level(level)
-
+ (Object) make_config(hash = {})
:nodoc:.
-
+ (Object) verbose
Get the default value of the :verbose option.
-
+ (Object) verbose=(on)
Set the default value of the :verbose option.
Instance Method Summary (collapse)
-
- (Boolean) alive?
Is this server alive?.
-
- (Object) check_insecure_method(obj, msg_id)
Check that a method is callable via dRuby.
-
- (DRbServer) initialize(uri = nil, front = nil, config_or_acl = nil)
constructor
Create a new DRbServer instance.
-
- (Object) stop_service
Stop this server.
-
- (Object) to_id(obj)
Convert a local object to a dRuby reference.
-
- (Object) to_obj(ref)
Convert a dRuby reference to the local object it refers to.
-
- (Object) verbose
Get whether the server is in verbose mode.
-
- (Object) verbose=(v)
Set whether to operate in verbose mode.
Constructor Details
- (DRbServer) initialize(uri = nil, front = nil, config_or_acl = nil)
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.
1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 |
# File 'lib/drb/drb.rb', line 1330 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 @front = front @idconv = @config[:idconv] @safe_level = @config[:safe_level] @grp = ThreadGroup.new @thread = run DRb.regist_server(self) end |
Instance Attribute Details
- (Object) config (readonly)
The configuration of this DRbServer
1372 1373 1374 |
# File 'lib/drb/drb.rb', line 1372 def config @config end |
- (Object) front (readonly)
The front object of the DRbServer.
This object receives remote method calls made on the server's URI alone, with an object id.
1369 1370 1371 |
# File 'lib/drb/drb.rb', line 1369 def front @front end |
- (Object) safe_level (readonly)
Returns the value of attribute safe_level
1374 1375 1376 |
# File 'lib/drb/drb.rb', line 1374 def safe_level @safe_level end |
- (Object) thread (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.
1363 1364 1365 |
# File 'lib/drb/drb.rb', line 1363 def thread @thread end |
- (Object) uri (readonly)
The URI of this DRbServer.
1356 1357 1358 |
# File 'lib/drb/drb.rb', line 1356 def uri @uri end |
Class Method Details
+ (Object) default_acl(acl)
Set the default value for the :acl option.
See #new(). The initial default value is nil.
1248 1249 1250 |
# File 'lib/drb/drb.rb', line 1248 def self.default_acl(acl) @@acl = acl end |
+ (Object) default_argc_limit(argc)
Set the default value for the :argc_limit option.
See #new(). The initial default value is 256.
1234 1235 1236 |
# File 'lib/drb/drb.rb', line 1234 def self.default_argc_limit(argc) @@argc_limit = argc end |
+ (Object) default_id_conv(idconv)
Set the default value for the :id_conv option.
See #new(). The initial default value is a DRbIdConv instance.
1255 1256 1257 |
# File 'lib/drb/drb.rb', line 1255 def self.default_id_conv(idconv) @@idconv = idconv end |
+ (Object) default_load_limit(sz)
Set the default value for the :load_limit option.
See #new(). The initial default value is 25 MB.
1241 1242 1243 |
# File 'lib/drb/drb.rb', line 1241 def self.default_load_limit(sz) @@load_limit = sz end |
+ (Object) default_safe_level(level)
1259 1260 1261 |
# File 'lib/drb/drb.rb', line 1259 def self.default_safe_level(level) @@safe_level = level end |
+ (Object) make_config(hash = {})
:nodoc:
1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 |
# File 'lib/drb/drb.rb', line 1275 def self.make_config(hash={}) # :nodoc: default_config = { :idconv => @@idconv, :verbose => @@verbose, :tcp_acl => @@acl, :load_limit => @@load_limit, :argc_limit => @@argc_limit, :safe_level => @@safe_level } default_config.update(hash) end |
+ (Object) verbose
Get the default value of the :verbose option.
1271 1272 1273 |
# File 'lib/drb/drb.rb', line 1271 def self.verbose @@verbose end |
+ (Object) verbose=(on)
Set the default value of the :verbose option.
See #new(). The initial default value is false.
1266 1267 1268 |
# File 'lib/drb/drb.rb', line 1266 def self.verbose=(on) @@verbose = on end |
Instance Method Details
- (Boolean) alive?
Is this server alive?
1387 1388 1389 |
# File 'lib/drb/drb.rb', line 1387 def alive? @thread.alive? end |
- (Object) check_insecure_method(obj, msg_id)
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.
1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 |
# File 'lib/drb/drb.rb', line 1470 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) 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 end |
- (Object) stop_service
Stop this server.
1392 1393 1394 1395 1396 1397 1398 1399 |
# File 'lib/drb/drb.rb', line 1392 def stop_service DRb.remove_server(self) if Thread.current['DRb'] && Thread.current['DRb']['server'] == self Thread.current['DRb']['stop_service'] = true else @thread.kill.join end end |
- (Object) to_id(obj)
Convert a local object to a dRuby reference.
1409 1410 1411 1412 |
# File 'lib/drb/drb.rb', line 1409 def to_id(obj) return nil if obj.__id__ == front.__id__ @idconv.to_id(obj) end |
- (Object) to_obj(ref)
Convert a dRuby reference to the local object it refers to.
1402 1403 1404 1405 1406 |
# File 'lib/drb/drb.rb', line 1402 def to_obj(ref) return front if ref.nil? return front[ref.to_s] if DRbURIOption === ref @idconv.to_obj(ref) end |
- (Object) verbose
Get whether the server is in verbose mode.
In verbose mode, failed calls are logged to stdout.
1384 |
# File 'lib/drb/drb.rb', line 1384 def verbose; @config[:verbose]; end |
- (Object) verbose=(v)
Set whether to operate in verbose mode.
In verbose mode, failed calls are logged to stdout.
1379 |
# File 'lib/drb/drb.rb', line 1379 def verbose=(v); @config[:verbose]=v; end |