# DRb::DRbServer (Class)

In: | drb/invokemethod.rb drb/drb.rb
Parent: | Object

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.

## Methods

alive? check_insecure_method default_acl default_argc_limit default_id_conv default_load_limit new stop_service to_id to_obj verbose verbose verbose= verbose=

## Constants

INSECURE_METHOD | = | [ :__send__
| List of insecure methods. These methods are not callable via dRuby.

## Attributes

config | [R] | The configuration of this DRbServer
front | [R] | The front object of the DRbServer. This object receives remote method calls made on the server’s URI alone, with an object id.
thread | [R] | 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.
uri | [R] | The URI of this DRbServer.

## Classes and Modules

Module DRb::DRbServer::InvokeMethod18Mixin

## Public Class methods

default_argc_limit(argc)

Set the default value for the :argc_limit option.

See new(). The initial default value is 256.

[Source]

    # File drb/drb.rb, line 1125
        def self.default_argc_limit(argc)
          @@argc_limit = argc
        end

default_load_limit(sz)

Set the default value for the :load_limit option.

See new(). The initial default value is 25 MB.

[Source]

    # File drb/drb.rb, line 1132
        def self.default_load_limit(sz)
          @@load_limit = sz
        end

default_acl(acl)

Set the default value for the :acl option.

See new(). The initial default value is nil.

[Source]

    # File drb/drb.rb, line 1139
        def self.default_acl(acl)
          @@acl = acl
        end

default_id_conv(idconv)

Set the default value for the :id_conv option.

See new(). The initial default value is a DRbIdConv instance.

[Source]

    # File drb/drb.rb, line 1146
        def self.default_id_conv(idconv)
          @@idconv = idconv
        end

verbose=(on)

Set the default value of the :verbose option.

See new(). The initial default value is false.

[Source]

    # File drb/drb.rb, line 1153
        def self.verbose=(on)
          @@verbose = on
        end

verbose()

Get the default value of the :verbose option.

[Source]

    # File drb/drb.rb, line 1158
        def self.verbose
          @@verbose
        end

new(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 unsucessful 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.

[Source]

    # File drb/drb.rb, line 1216
        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]

          @grp = ThreadGroup.new
          @thread = run

          Thread.exclusive do
            DRb.primary_server = self unless DRb.primary_server
          end
        end

## Public Instance methods

verbose=(v)

Set whether to operate in verbose mode.

In verbose mode, failed calls are logged to stdout.

[Source]

    # File drb/drb.rb, line 1264
        def verbose=(v); @config[:verbose]=v; end

verbose()

Get whether the server is in verbose mode.

In verbose mode, failed calls are logged to stdout.

[Source]

    # File drb/drb.rb, line 1269
        def verbose; @config[:verbose]; end

alive?()

Is this server alive?

[Source]

    # File drb/drb.rb, line 1272
        def alive?
          @thread.alive?
        end

stop_service()

Stop this server.

[Source]

    # File drb/drb.rb, line 1277
        def stop_service
          @thread.kill
        end

to_obj(ref)

Convert a dRuby reference to the local object it refers to.

[Source]

    # File drb/drb.rb, line 1282
        def to_obj(ref)
          return front if ref.nil?
          return front[ref.to_s] if DRbURIOption === ref
          @idconv.to_obj(ref)
        end

to_id(obj)

Convert a local object to a dRuby reference.

[Source]

    # File drb/drb.rb, line 1289
        def to_id(obj)
          return nil if obj.__id__ == front.__id__
          @idconv.to_id(obj)
        end

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.

[Source]

    # File drb/drb.rb, line 1348
        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)
          unless obj.respond_to?(msg_id)
            desc = any_to_s(obj)
            if desc.nil? || desc[0] == '#'
              desc << ":#{obj.class}"
            end

            if obj.private_methods.include?(msg_id.to_s)
              raise NameError, "private method `#{msg_id}' called for #{desc}"
            else
              raise NameError, "undefined method `#{msg_id}' called for #{desc}"
            end
          end
          true
        end

[Validate]