HEX
Server: Apache
System: Windows NT MAGNETO-ARM 10.0 build 22000 (Windows 10) AMD64
User: Michel (0)
PHP: 7.4.7
Disabled: NONE
Upload Files
File: C:/Ruby27-x64/share/doc/ruby/html/DRb.html
<!DOCTYPE html>

<html>
<head>
<meta charset="UTF-8">

<title>module DRb - RDoc Documentation</title>

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
</script>

<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<link href="./css/fonts.css" rel="stylesheet">
<link href="./css/rdoc.css" rel="stylesheet">




<body id="top" role="document" class="module">
<nav role="navigation">
  <div id="project-navigation">
    <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2>
    <a href="./index.html" rel="home">Home</a>
  </h2>

  <div id="table-of-contents-navigation">
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

    <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

  </div>

  
<div class="nav-section">
  <h3>Table of Contents</h3>

  <ul class="link-list" role="directory">
    <li><a href="#module-DRb-label-Overview">Overview</a>
    <li><a href="#module-DRb-label-Examples+of+usage">Examples of usage</a>
    <li><a href="#module-DRb-label-dRuby+in+client-2Fserver+mode">dRuby in client/server mode</a>
    <li><a href="#module-DRb-label-Server+code">Server code</a>
    <li><a href="#module-DRb-label-Client+code">Client code</a>
    <li><a href="#module-DRb-label-Remote+objects+under+dRuby">Remote objects under dRuby</a>
    <li><a href="#module-DRb-label-Server+code">Server code</a>
    <li><a href="#module-DRb-label-Client+code">Client code</a>
    <li><a href="#module-DRb-label-Security">Security</a>
    <li><a href="#module-DRb-label-dRuby+internals">dRuby internals</a>
  </ul>
</div>


  <div id="class-metadata">
    
    
    
    
    <!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    
    <li ><a href="#method-c-config">::config</a>
    
    <li ><a href="#method-c-current_server">::current_server</a>
    
    <li ><a href="#method-c-fetch_server">::fetch_server</a>
    
    <li ><a href="#method-c-front">::front</a>
    
    <li ><a href="#method-c-here-3F">::here?</a>
    
    <li ><a href="#method-c-install_acl">::install_acl</a>
    
    <li ><a href="#method-c-install_id_conv">::install_id_conv</a>
    
    <li ><a href="#method-c-regist_server">::regist_server</a>
    
    <li ><a href="#method-c-remove_server">::remove_server</a>
    
    <li ><a href="#method-c-start_service">::start_service</a>
    
    <li ><a href="#method-c-stop_service">::stop_service</a>
    
    <li ><a href="#method-c-thread">::thread</a>
    
    <li ><a href="#method-c-to_id">::to_id</a>
    
    <li ><a href="#method-c-to_obj">::to_obj</a>
    
    <li ><a href="#method-c-uri">::uri</a>
    
    <li ><a href="#method-i-config">#config</a>
    
    <li ><a href="#method-i-current_server">#current_server</a>
    
    <li ><a href="#method-i-fetch_server">#fetch_server</a>
    
    <li ><a href="#method-i-front">#front</a>
    
    <li ><a href="#method-i-here-3F">#here?</a>
    
    <li ><a href="#method-i-install_acl">#install_acl</a>
    
    <li ><a href="#method-i-install_id_conv">#install_id_conv</a>
    
    <li ><a href="#method-i-regist_server">#regist_server</a>
    
    <li ><a href="#method-i-remove_server">#remove_server</a>
    
    <li ><a href="#method-i-start_service">#start_service</a>
    
    <li ><a href="#method-i-stop_service">#stop_service</a>
    
    <li ><a href="#method-i-thread">#thread</a>
    
    <li ><a href="#method-i-to_id">#to_id</a>
    
    <li ><a href="#method-i-to_obj">#to_obj</a>
    
    <li ><a href="#method-i-uri">#uri</a>
    
  </ul>
</div>

  </div>
</nav>

<main role="main" aria-labelledby="module-DRb">
  <h1 id="module-DRb" class="module">
    module DRb
  </h1>

  <section class="description">
    
<h2 id="module-DRb-label-Overview">Overview<span><a href="#module-DRb-label-Overview">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>dRuby is a distributed object system for Ruby.  It is written in pure Ruby and uses its own protocol.  No add-in services are needed beyond those provided by the Ruby runtime, such as TCP sockets.  It does not rely on or interoperate with other distributed object systems such as CORBA, RMI, or .NET.</p>

<p>dRuby allows methods to be called in one Ruby process upon a Ruby object located in another Ruby process, even on another machine. References to objects can be passed between processes.  <a href="Method.html"><code>Method</code></a> arguments and return values are dumped and loaded in marshalled format.  All of this is done transparently to both the caller of the remote method and the object that it is called upon.</p>

<p>An object in a remote process is locally represented by a <a href="DRb/DRbObject.html"><code>DRb::DRbObject</code></a> instance.  This acts as a sort of proxy for the remote object.  Methods called upon this <a href="DRb/DRbObject.html"><code>DRbObject</code></a> instance are forwarded to its remote object.  This is arranged dynamically at run time.  There are no statically declared interfaces for remote objects, such as CORBA&#39;s IDL.</p>

<p>dRuby calls made into a process are handled by a DRb::DRbServer instance within that process.  This reconstitutes the method call, invokes it upon the specified local object, and returns the value to the remote caller.  Any object can receive calls over dRuby.  There is no need to implement a special interface, or mixin special functionality.  Nor, in the general case, does an object need to explicitly register itself with a DRbServer in order to receive dRuby calls.</p>

<p>One process wishing to make dRuby calls upon another process must somehow obtain an initial reference to an object in the remote process by some means other than as the return value of a remote method call, as there is initially no remote object reference it can invoke a method upon.  This is done by attaching to the server by <a href="URI.html"><code>URI</code></a>.  Each DRbServer binds itself to a <a href="URI.html"><code>URI</code></a> such as &#39;druby://example.com:8787&#39;.  A DRbServer can have an object attached to it that acts as the server&#39;s <strong>front</strong> <strong>object</strong>.  A <a href="DRb/DRbObject.html"><code>DRbObject</code></a> can be explicitly created from the server&#39;s <a href="URI.html"><code>URI</code></a>.  This DRbObject&#39;s remote object will be the server&#39;s front object.  This front object can then return references to other Ruby objects in the DRbServer&#39;s process.</p>

<p><a href="Method.html"><code>Method</code></a> calls made over dRuby behave largely the same as normal Ruby method calls made within a process.  <a href="Method.html"><code>Method</code></a> calls with blocks are supported, as are raising exceptions.  In addition to a method&#39;s standard errors, a dRuby call may also raise one of the dRuby-specific errors, all of which are subclasses of <a href="DRb/DRbError.html"><code>DRb::DRbError</code></a>.</p>

<p>Any type of object can be passed as an argument to a dRuby call or returned as its return value.  By default, such objects are dumped or marshalled at the local end, then loaded or unmarshalled at the remote end.  The remote end therefore receives a copy of the local object, not a distributed reference to it; methods invoked upon this copy are executed entirely in the remote process, not passed on to the local original.  This has semantics similar to pass-by-value.</p>

<p>However, if an object cannot be marshalled, a dRuby reference to it is passed or returned instead.  This will turn up at the remote end as a <a href="DRb/DRbObject.html"><code>DRbObject</code></a> instance.  All methods invoked upon this remote proxy are forwarded to the local object, as described in the discussion of DRbObjects.  This has semantics similar to the normal Ruby pass-by-reference.</p>

<p>The easiest way to signal that we want an otherwise marshallable object to be passed or returned as a <a href="DRb/DRbObject.html"><code>DRbObject</code></a> reference, rather than marshalled and sent as a copy, is to include the <a href="DRb/DRbUndumped.html"><code>DRb::DRbUndumped</code></a> mixin module.</p>

<p>dRuby supports calling remote methods with blocks.  As blocks (or rather the <a href="Proc.html"><code>Proc</code></a> objects that represent them) are not marshallable, the block executes in the local, not the remote, context.  Each value yielded to the block is passed from the remote object to the local block, then the value returned by each block invocation is passed back to the remote execution context to be collected, before the collected values are finally returned to the local context as the return value of the method invocation.</p>

<h2 id="module-DRb-label-Examples+of+usage">Examples of usage<span><a href="#module-DRb-label-Examples+of+usage">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>For more dRuby samples, see the <code>samples</code> directory in the full dRuby distribution.</p>

<h3 id="module-DRb-label-dRuby+in+client-2Fserver+mode">dRuby in client/server mode<span><a href="#module-DRb-label-dRuby+in+client-2Fserver+mode">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>This illustrates setting up a simple client-server drb system.  Run the server and client code in different terminals, starting the server code first.</p>

<h4 id="module-DRb-label-Server+code">Server code<span><a href="#module-DRb-label-Server+code">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;drb/drb&#39;</span>

<span class="ruby-comment"># The URI for the server to connect to</span>
<span class="ruby-constant">URI</span>=<span class="ruby-string">&quot;druby://localhost:8787&quot;</span>

<span class="ruby-keyword">class</span> <span class="ruby-constant">TimeServer</span>

  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">get_current_time</span>
    <span class="ruby-keyword">return</span> <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>
  <span class="ruby-keyword">end</span>

<span class="ruby-keyword">end</span>

<span class="ruby-comment"># The object that handles requests on the server</span>
<span class="ruby-constant">FRONT_OBJECT</span>=<span class="ruby-constant">TimeServer</span>.<span class="ruby-identifier">new</span>

<span class="ruby-constant">DRb</span>.<span class="ruby-identifier">start_service</span>(<span class="ruby-constant">URI</span>, <span class="ruby-constant">FRONT_OBJECT</span>)
<span class="ruby-comment"># Wait for the drb server thread to finish before exiting.</span>
<span class="ruby-constant">DRb</span>.<span class="ruby-identifier">thread</span>.<span class="ruby-identifier">join</span>
</pre>

<h4 id="module-DRb-label-Client+code">Client code<span><a href="#module-DRb-label-Client+code">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;drb/drb&#39;</span>

<span class="ruby-comment"># The URI to connect to</span>
<span class="ruby-constant">SERVER_URI</span>=<span class="ruby-string">&quot;druby://localhost:8787&quot;</span>

<span class="ruby-comment"># Start a local DRbServer to handle callbacks.</span>
<span class="ruby-comment">#</span>
<span class="ruby-comment"># Not necessary for this small example, but will be required</span>
<span class="ruby-comment"># as soon as we pass a non-marshallable object as an argument</span>
<span class="ruby-comment"># to a dRuby call.</span>
<span class="ruby-comment">#</span>
<span class="ruby-comment"># Note: this must be called at least once per process to take any effect.</span>
<span class="ruby-comment"># This is particularly important if your application forks.</span>
<span class="ruby-constant">DRb</span>.<span class="ruby-identifier">start_service</span>

<span class="ruby-identifier">timeserver</span> = <span class="ruby-constant">DRbObject</span>.<span class="ruby-identifier">new_with_uri</span>(<span class="ruby-constant">SERVER_URI</span>)
<span class="ruby-identifier">puts</span> <span class="ruby-identifier">timeserver</span>.<span class="ruby-identifier">get_current_time</span>
</pre>

<h3 id="module-DRb-label-Remote+objects+under+dRuby">Remote objects under dRuby<span><a href="#module-DRb-label-Remote+objects+under+dRuby">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>This example illustrates returning a reference to an object from a dRuby call.  The <a href="Logger.html"><code>Logger</code></a> instances live in the server process.  References to them are returned to the client process, where methods can be invoked upon them.  These methods are executed in the server process.</p>

<h4 id="module-DRb-label-Server+code">Server code<span><a href="#module-DRb-label-Server+code">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;drb/drb&#39;</span>

<span class="ruby-constant">URI</span>=<span class="ruby-string">&quot;druby://localhost:8787&quot;</span>

<span class="ruby-keyword">class</span> <span class="ruby-constant">Logger</span>

    <span class="ruby-comment"># Make dRuby send Logger instances as dRuby references,</span>
    <span class="ruby-comment"># not copies.</span>
    <span class="ruby-identifier">include</span> <span class="ruby-constant">DRb</span><span class="ruby-operator">::</span><span class="ruby-constant">DRbUndumped</span>

    <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-identifier">n</span>, <span class="ruby-identifier">fname</span>)
        <span class="ruby-ivar">@name</span> = <span class="ruby-identifier">n</span>
        <span class="ruby-ivar">@filename</span> = <span class="ruby-identifier">fname</span>
    <span class="ruby-keyword">end</span>

    <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">log</span>(<span class="ruby-identifier">message</span>)
        <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-ivar">@filename</span>, <span class="ruby-string">&quot;a&quot;</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
            <span class="ruby-identifier">f</span>.<span class="ruby-identifier">puts</span>(<span class="ruby-node">&quot;#{Time.now}: #{@name}: #{message}&quot;</span>)
        <span class="ruby-keyword">end</span>
    <span class="ruby-keyword">end</span>

<span class="ruby-keyword">end</span>

<span class="ruby-comment"># We have a central object for creating and retrieving loggers.</span>
<span class="ruby-comment"># This retains a local reference to all loggers created.  This</span>
<span class="ruby-comment"># is so an existing logger can be looked up by name, but also</span>
<span class="ruby-comment"># to prevent loggers from being garbage collected.  A dRuby</span>
<span class="ruby-comment"># reference to an object is not sufficient to prevent it being</span>
<span class="ruby-comment"># garbage collected!</span>
<span class="ruby-keyword">class</span> <span class="ruby-constant">LoggerFactory</span>

    <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-identifier">bdir</span>)
        <span class="ruby-ivar">@basedir</span> = <span class="ruby-identifier">bdir</span>
        <span class="ruby-ivar">@loggers</span> = {}
    <span class="ruby-keyword">end</span>

    <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">get_logger</span>(<span class="ruby-identifier">name</span>)
        <span class="ruby-keyword">if</span> <span class="ruby-operator">!</span><span class="ruby-ivar">@loggers</span>.<span class="ruby-identifier">has_key?</span> <span class="ruby-identifier">name</span>
            <span class="ruby-comment"># make the filename safe, then declare it to be so</span>
            <span class="ruby-identifier">fname</span> = <span class="ruby-identifier">name</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-regexp">/[.\/\\\:]/</span>, <span class="ruby-string">&quot;_&quot;</span>)
            <span class="ruby-ivar">@loggers</span>[<span class="ruby-identifier">name</span>] = <span class="ruby-constant">Logger</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">name</span>, <span class="ruby-ivar">@basedir</span> <span class="ruby-operator">+</span> <span class="ruby-string">&quot;/&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">fname</span>)
        <span class="ruby-keyword">end</span>
        <span class="ruby-keyword">return</span> <span class="ruby-ivar">@loggers</span>[<span class="ruby-identifier">name</span>]
    <span class="ruby-keyword">end</span>

<span class="ruby-keyword">end</span>

<span class="ruby-constant">FRONT_OBJECT</span>=<span class="ruby-constant">LoggerFactory</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;/tmp/dlog&quot;</span>)

<span class="ruby-constant">DRb</span>.<span class="ruby-identifier">start_service</span>(<span class="ruby-constant">URI</span>, <span class="ruby-constant">FRONT_OBJECT</span>)
<span class="ruby-constant">DRb</span>.<span class="ruby-identifier">thread</span>.<span class="ruby-identifier">join</span>
</pre>

<h4 id="module-DRb-label-Client+code">Client code<span><a href="#module-DRb-label-Client+code">&para;</a> <a href="#top">&uarr;</a></span></h4>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;drb/drb&#39;</span>

<span class="ruby-constant">SERVER_URI</span>=<span class="ruby-string">&quot;druby://localhost:8787&quot;</span>

<span class="ruby-constant">DRb</span>.<span class="ruby-identifier">start_service</span>

<span class="ruby-identifier">log_service</span>=<span class="ruby-constant">DRbObject</span>.<span class="ruby-identifier">new_with_uri</span>(<span class="ruby-constant">SERVER_URI</span>)

[<span class="ruby-string">&quot;loga&quot;</span>, <span class="ruby-string">&quot;logb&quot;</span>, <span class="ruby-string">&quot;logc&quot;</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">logname</span><span class="ruby-operator">|</span>

    <span class="ruby-identifier">logger</span>=<span class="ruby-identifier">log_service</span>.<span class="ruby-identifier">get_logger</span>(<span class="ruby-identifier">logname</span>)

    <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">log</span>(<span class="ruby-string">&quot;Hello, world!&quot;</span>)
    <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">log</span>(<span class="ruby-string">&quot;Goodbye, world!&quot;</span>)
    <span class="ruby-identifier">logger</span>.<span class="ruby-identifier">log</span>(<span class="ruby-string">&quot;=== EOT ===&quot;</span>)

<span class="ruby-keyword">end</span>
</pre>

<h2 id="module-DRb-label-Security">Security<span><a href="#module-DRb-label-Security">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>As with all network services, security needs to be considered when using dRuby.  By allowing external access to a Ruby object, you are not only allowing outside clients to call the methods you have defined for that object, but by default to execute arbitrary Ruby code on your server.  Consider the following:</p>

<pre class="ruby"><span class="ruby-comment"># !!! UNSAFE CODE !!!</span>
<span class="ruby-identifier">ro</span> = <span class="ruby-constant">DRbObject</span><span class="ruby-operator">::</span><span class="ruby-identifier">new_with_uri</span>(<span class="ruby-string">&quot;druby://your.server.com:8989&quot;</span>)
<span class="ruby-keyword">class</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">ro</span>
  <span class="ruby-keyword">undef</span> <span class="ruby-value">:instance_eval</span>  <span class="ruby-comment"># force call to be passed to remote object</span>
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">ro</span>.<span class="ruby-identifier">instance_eval</span>(<span class="ruby-string">&quot;`rm -rf *`&quot;</span>)
</pre>

<p>The dangers posed by instance_eval and friends are such that a DRbServer should only be used when clients are trusted.</p>

<p>A DRbServer can be configured with an access control list to selectively allow or deny access from specified IP addresses.  The main druby distribution provides the <a href="ACL.html"><code>ACL</code></a> class for this purpose.  In general, this mechanism should only be used alongside, rather than as a replacement for, a good firewall.</p>

<h2 id="module-DRb-label-dRuby+internals">dRuby internals<span><a href="#module-DRb-label-dRuby+internals">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>dRuby is implemented using three main components: a remote method call marshaller/unmarshaller; a transport protocol; and an ID-to-object mapper.  The latter two can be directly, and the first indirectly, replaced, in order to provide different behaviour and capabilities.</p>

<p>Marshalling and unmarshalling of remote method calls is performed by a <a href="DRb/DRbMessage.html"><code>DRb::DRbMessage</code></a> instance.  This uses the <a href="Marshal.html"><code>Marshal</code></a> module to dump the method call before sending it over the transport layer, then reconstitute it at the other end.  There is normally no need to replace this component, and no direct way is provided to do so. However, it is possible to implement an alternative marshalling scheme as part of an implementation of the transport layer.</p>

<p>The transport layer is responsible for opening client and server network connections and forwarding dRuby request across them. Normally, it uses <a href="DRb/DRbMessage.html"><code>DRb::DRbMessage</code></a> internally to manage marshalling and unmarshalling.  The transport layer is managed by <a href="DRb/DRbProtocol.html"><code>DRb::DRbProtocol</code></a>.  Multiple protocols can be installed in <a href="DRb/DRbProtocol.html"><code>DRbProtocol</code></a> at the one time; selection between them is determined by the scheme of a dRuby <a href="URI.html"><code>URI</code></a>.  The default transport protocol is selected by the scheme &#39;druby:&#39;, and implemented by <a href="DRb/DRbTCPSocket.html"><code>DRb::DRbTCPSocket</code></a>.  This uses plain TCP/IP sockets for communication.  An alternative protocol, using UNIX domain sockets, is implemented by <a href="DRb/DRbUNIXSocket.html"><code>DRb::DRbUNIXSocket</code></a> in the file drb/unix.rb, and selected by the scheme &#39;drbunix:&#39;.  A sample implementation over HTTP can be found in the samples accompanying the main dRuby distribution.</p>

<p>The ID-to-object mapping component maps dRuby object ids to the objects they refer to, and vice versa.  The implementation to use can be specified as part of a DRb::DRbServer&#39;s configuration.  The default implementation is provided by <a href="DRb/DRbIdConv.html"><code>DRb::DRbIdConv</code></a>.  It uses an object&#39;s <a href="ObjectSpace.html"><code>ObjectSpace</code></a> id as its dRuby id.  This means that the dRuby reference to that object only remains meaningful for the lifetime of the object&#39;s process and the lifetime of the object within that process.  A modified implementation is provided by <a href="DRb/TimerIdConv.html"><code>DRb::TimerIdConv</code></a> in the file drb/timeridconv.rb.  This implementation retains a local reference to all objects exported over dRuby for a configurable period of time (defaulting to ten minutes), to prevent them being garbage-collected within this time.  Another sample implementation is provided in sample/name.rb in the main dRuby distribution.  This allows objects to specify their own id or “name”.  A dRuby reference can be made persistent across processes by having each process register an object using the same dRuby name.</p>

  </section>

  
  <section id="5Buntitled-5D" class="documentation-section">
    

    

    

    
    <section class="attribute-method-details" class="method-section">
      <header>
        <h3>Attributes</h3>
      </header>

      
      <div id="attribute-c-primary_server" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">primary_server</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>The primary local dRuby server.</p>

<p>This is the server created by the <a href="DRb.html#method-i-start_service"><code>start_service</code></a> call.</p>
        
        </div>
      </div>
      
      <div id="attribute-i-primary_server" class="method-detail">
        <div class="method-heading attribute-method-heading">
          <span class="method-name">primary_server</span><span
            class="attribute-access-type">[RW]</span>
        </div>

        <div class="method-description">
        
        <p>The primary local dRuby server.</p>

<p>This is the server created by the <a href="DRb.html#method-i-start_service"><code>start_service</code></a> call.</p>
        
        </div>
      </div>
      
    </section>
    

    
     <section id="public-class-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Public Class Methods</h3>
       </header>

    
      <div id="method-c-config" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">config</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Get the configuration of the current server.</p>

<p>If there is no current server, this returns the default configuration. See <a href="DRb.html#method-i-current_server"><code>current_server</code></a> and DRbServer::make_config.</p>
          
          

          
          <div class="method-source-code" id="config-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1835</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">config</span>
  <span class="ruby-identifier">current_server</span>.<span class="ruby-identifier">config</span>
<span class="ruby-keyword">rescue</span>
  <span class="ruby-constant">DRbServer</span>.<span class="ruby-identifier">make_config</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-current_server" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">current_server</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Get the &#39;current&#39; server.</p>

<p>In the context of execution taking place within the main thread of a dRuby server (typically, as a result of a remote call on the server or one of its objects), the current server is that server.  Otherwise, the current server is the primary server.</p>

<p>If the above rule fails to find a server, a <a href="DRb/DRbServerNotFound.html"><code>DRbServerNotFound</code></a> error is raised.</p>
          
          

          
          <div class="method-source-code" id="current_server-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1792</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">current_server</span>
  <span class="ruby-identifier">drb</span> = <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-string">&#39;DRb&#39;</span>]
  <span class="ruby-identifier">server</span> = (<span class="ruby-identifier">drb</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">drb</span>[<span class="ruby-string">&#39;server&#39;</span>]) <span class="ruby-operator">?</span> <span class="ruby-identifier">drb</span>[<span class="ruby-string">&#39;server&#39;</span>] <span class="ruby-operator">:</span> <span class="ruby-ivar">@primary_server</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">DRbServerNotFound</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">server</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">server</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-fetch_server" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">fetch_server</span><span
            class="method-args">(uri)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Retrieves the server with the given <code>uri</code>.</p>

<p>See also <a href="DRb.html#method-i-regist_server"><code>regist_server</code></a> and remove_server.</p>
          
          

          
          <div class="method-source-code" id="fetch_server-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1937</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">fetch_server</span>(<span class="ruby-identifier">uri</span>)
  <span class="ruby-ivar">@server</span>[<span class="ruby-identifier">uri</span>]
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-front" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">front</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Get the front object of the current server.</p>

<p>This raises a <a href="DRb/DRbServerNotFound.html"><code>DRbServerNotFound</code></a> error if there is no current server. See <a href="DRb.html#method-i-current_server"><code>current_server</code></a>.</p>
          
          

          
          <div class="method-source-code" id="front-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1846</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">front</span>
  <span class="ruby-identifier">current_server</span>.<span class="ruby-identifier">front</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-here-3F" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">here?</span><span
            class="method-args">(uri)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Is <code>uri</code> the <a href="URI.html"><code>URI</code></a> for the current local server?</p>
          
          

          
          <div class="method-source-code" id="here-3F-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1825</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">here?</span>(<span class="ruby-identifier">uri</span>)
  <span class="ruby-identifier">current_server</span>.<span class="ruby-identifier">here?</span>(<span class="ruby-identifier">uri</span>) <span class="ruby-keyword">rescue</span> <span class="ruby-keyword">false</span>
  <span class="ruby-comment"># (current_server.uri rescue nil) == uri</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-install_acl" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">install_acl</span><span
            class="method-args">(acl)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p><a href="Set.html"><code>Set</code></a> the default <a href="ACL.html"><code>ACL</code></a> to <code>acl</code>.</p>

<p>See <a href="DRb/DRbServer.html#method-c-default_acl"><code>DRb::DRbServer.default_acl</code></a>.</p>
          
          

          
          <div class="method-source-code" id="install_acl-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1891</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">install_acl</span>(<span class="ruby-identifier">acl</span>)
  <span class="ruby-constant">DRbServer</span>.<span class="ruby-identifier">default_acl</span>(<span class="ruby-identifier">acl</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-install_id_conv" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">install_id_conv</span><span
            class="method-args">(idconv)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p><a href="Set.html"><code>Set</code></a> the default id conversion object.</p>

<p>This is expected to be an instance such as <a href="DRb/DRbIdConv.html"><code>DRb::DRbIdConv</code></a> that responds to <a href="DRb.html#method-i-to_id"><code>to_id</code></a> and <a href="DRb.html#method-i-to_obj"><code>to_obj</code></a> that can convert objects to and from <a href="DRb.html"><code>DRb</code></a> references.</p>

<p>See DRbServer#default_id_conv.</p>
          
          

          
          <div class="method-source-code" id="install_id_conv-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1883</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">install_id_conv</span>(<span class="ruby-identifier">idconv</span>)
  <span class="ruby-constant">DRbServer</span>.<span class="ruby-identifier">default_id_conv</span>(<span class="ruby-identifier">idconv</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-regist_server" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">regist_server</span><span
            class="method-args">(server)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Registers <code>server</code> with <a href="DRb.html"><code>DRb</code></a>.</p>

<p>This is called when a new DRb::DRbServer is created.</p>

<p>If there is no primary server then <code>server</code> becomes the primary server.</p>

<p>Example:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;drb&#39;</span>

<span class="ruby-identifier">s</span> = <span class="ruby-constant">DRb</span><span class="ruby-operator">::</span><span class="ruby-constant">DRbServer</span>.<span class="ruby-identifier">new</span> <span class="ruby-comment"># automatically calls regist_server</span>
<span class="ruby-constant">DRb</span>.<span class="ruby-identifier">fetch_server</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">uri</span> <span class="ruby-comment">#=&gt; #&lt;DRb::DRbServer:0x...&gt;</span>
</pre>
          
          

          
          <div class="method-source-code" id="regist_server-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1915</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">regist_server</span>(<span class="ruby-identifier">server</span>)
  <span class="ruby-ivar">@server</span>[<span class="ruby-identifier">server</span>.<span class="ruby-identifier">uri</span>] = <span class="ruby-identifier">server</span>
  <span class="ruby-identifier">mutex</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword">do</span>
    <span class="ruby-ivar">@primary_server</span> = <span class="ruby-identifier">server</span> <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@primary_server</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-remove_server" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">remove_server</span><span
            class="method-args">(server)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Removes <code>server</code> from the list of registered servers.</p>
          
          

          
          <div class="method-source-code" id="remove_server-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1924</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">remove_server</span>(<span class="ruby-identifier">server</span>)
  <span class="ruby-ivar">@server</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">server</span>.<span class="ruby-identifier">uri</span>)
  <span class="ruby-identifier">mutex</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword">do</span>
    <span class="ruby-keyword">if</span> <span class="ruby-ivar">@primary_server</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">server</span>
      <span class="ruby-ivar">@primary_server</span> = <span class="ruby-keyword">nil</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-start_service" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">start_service</span><span
            class="method-args">(uri=nil, front=nil, config=nil)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Start a dRuby server locally.</p>

<p>The new dRuby server will become the primary server, even if another server is currently the primary server.</p>

<p><code>uri</code> is the <a href="URI.html"><code>URI</code></a> for the server to bind to.  If nil, the server will bind to random port on the default local host name and use the default dRuby protocol.</p>

<p><code>front</code> is the server&#39;s front object.  This may be nil.</p>

<p><code>config</code> is the configuration for the new server.  This may be nil.</p>

<p>See <a href="DRb/DRbServer.html#method-c-new"><code>DRbServer::new</code></a>.</p>
          
          

          
          <div class="method-source-code" id="start_service-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1771</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">start_service</span>(<span class="ruby-identifier">uri</span>=<span class="ruby-keyword">nil</span>, <span class="ruby-identifier">front</span>=<span class="ruby-keyword">nil</span>, <span class="ruby-identifier">config</span>=<span class="ruby-keyword">nil</span>)
  <span class="ruby-ivar">@primary_server</span> = <span class="ruby-constant">DRbServer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">uri</span>, <span class="ruby-identifier">front</span>, <span class="ruby-identifier">config</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-stop_service" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">stop_service</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Stop the local dRuby server.</p>

<p>This operates on the primary server.  If there is no primary server currently running, it is a noop.</p>
          
          

          
          <div class="method-source-code" id="stop_service-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1804</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">stop_service</span>
  <span class="ruby-ivar">@primary_server</span>.<span class="ruby-identifier">stop_service</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@primary_server</span>
  <span class="ruby-ivar">@primary_server</span> = <span class="ruby-keyword">nil</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-thread" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">thread</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Get the thread of the primary server.</p>

<p>This returns nil if there is no primary server.  See <a href="DRb.html#attribute-i-primary_server"><code>primary_server</code></a>.</p>
          
          

          
          <div class="method-source-code" id="thread-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1872</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">thread</span>
  <span class="ruby-ivar">@primary_server</span> <span class="ruby-operator">?</span> <span class="ruby-ivar">@primary_server</span>.<span class="ruby-identifier">thread</span> <span class="ruby-operator">:</span> <span class="ruby-keyword">nil</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-to_id" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">to_id</span><span
            class="method-args">(obj)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Get a reference id for an object using the current server.</p>

<p>This raises a <a href="DRb/DRbServerNotFound.html"><code>DRbServerNotFound</code></a> error if there is no current server. See <a href="DRb.html#method-i-current_server"><code>current_server</code></a>.</p>
          
          

          
          <div class="method-source-code" id="to_id-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1863</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_id</span>(<span class="ruby-identifier">obj</span>)
  <span class="ruby-identifier">current_server</span>.<span class="ruby-identifier">to_id</span>(<span class="ruby-identifier">obj</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-to_obj" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">to_obj</span><span
            class="method-args">(ref)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Convert a reference into an object using the current server.</p>

<p>This raises a <a href="DRb/DRbServerNotFound.html"><code>DRbServerNotFound</code></a> error if there is no current server. See <a href="DRb.html#method-i-current_server"><code>current_server</code></a>.</p>
          
          

          
          <div class="method-source-code" id="to_obj-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1855</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_obj</span>(<span class="ruby-identifier">ref</span>)
  <span class="ruby-identifier">current_server</span>.<span class="ruby-identifier">to_obj</span>(<span class="ruby-identifier">ref</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-c-uri" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">uri</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Get the <a href="URI.html"><code>URI</code></a> defining the local dRuby space.</p>

<p>This is the <a href="URI.html"><code>URI</code></a> of the current server.  See <a href="DRb.html#method-i-current_server"><code>current_server</code></a>.</p>
          
          

          
          <div class="method-source-code" id="uri-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1813</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">uri</span>
  <span class="ruby-identifier">drb</span> = <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-string">&#39;DRb&#39;</span>]
  <span class="ruby-identifier">client</span> = (<span class="ruby-identifier">drb</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">drb</span>[<span class="ruby-string">&#39;client&#39;</span>])
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">client</span>
    <span class="ruby-identifier">uri</span> = <span class="ruby-identifier">client</span>.<span class="ruby-identifier">uri</span>
    <span class="ruby-keyword">return</span> <span class="ruby-identifier">uri</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">uri</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">current_server</span>.<span class="ruby-identifier">uri</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
    </section>
  
     <section id="private-instance-5Buntitled-5D-method-details" class="method-section">
       <header>
         <h3>Private Instance Methods</h3>
       </header>

    
      <div id="method-i-config" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">config</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Get the configuration of the current server.</p>

<p>If there is no current server, this returns the default configuration. See <a href="DRb.html#method-i-current_server"><code>current_server</code></a> and DRbServer::make_config.</p>
          
          

          
          <div class="method-source-code" id="config-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1835</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">config</span>
  <span class="ruby-identifier">current_server</span>.<span class="ruby-identifier">config</span>
<span class="ruby-keyword">rescue</span>
  <span class="ruby-constant">DRbServer</span>.<span class="ruby-identifier">make_config</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-current_server" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">current_server</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Get the &#39;current&#39; server.</p>

<p>In the context of execution taking place within the main thread of a dRuby server (typically, as a result of a remote call on the server or one of its objects), the current server is that server.  Otherwise, the current server is the primary server.</p>

<p>If the above rule fails to find a server, a <a href="DRb/DRbServerNotFound.html"><code>DRbServerNotFound</code></a> error is raised.</p>
          
          

          
          <div class="method-source-code" id="current_server-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1792</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">current_server</span>
  <span class="ruby-identifier">drb</span> = <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-string">&#39;DRb&#39;</span>]
  <span class="ruby-identifier">server</span> = (<span class="ruby-identifier">drb</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">drb</span>[<span class="ruby-string">&#39;server&#39;</span>]) <span class="ruby-operator">?</span> <span class="ruby-identifier">drb</span>[<span class="ruby-string">&#39;server&#39;</span>] <span class="ruby-operator">:</span> <span class="ruby-ivar">@primary_server</span>
  <span class="ruby-identifier">raise</span> <span class="ruby-constant">DRbServerNotFound</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">server</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">server</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-fetch_server" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">fetch_server</span><span
            class="method-args">(uri)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Retrieves the server with the given <code>uri</code>.</p>

<p>See also <a href="DRb.html#method-i-regist_server"><code>regist_server</code></a> and remove_server.</p>
          
          

          
          <div class="method-source-code" id="fetch_server-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1937</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">fetch_server</span>(<span class="ruby-identifier">uri</span>)
  <span class="ruby-ivar">@server</span>[<span class="ruby-identifier">uri</span>]
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-front" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">front</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Get the front object of the current server.</p>

<p>This raises a <a href="DRb/DRbServerNotFound.html"><code>DRbServerNotFound</code></a> error if there is no current server. See <a href="DRb.html#method-i-current_server"><code>current_server</code></a>.</p>
          
          

          
          <div class="method-source-code" id="front-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1846</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">front</span>
  <span class="ruby-identifier">current_server</span>.<span class="ruby-identifier">front</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-here-3F" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">here?</span><span
            class="method-args">(uri)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Is <code>uri</code> the <a href="URI.html"><code>URI</code></a> for the current local server?</p>
          
          

          
          <div class="method-source-code" id="here-3F-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1825</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">here?</span>(<span class="ruby-identifier">uri</span>)
  <span class="ruby-identifier">current_server</span>.<span class="ruby-identifier">here?</span>(<span class="ruby-identifier">uri</span>) <span class="ruby-keyword">rescue</span> <span class="ruby-keyword">false</span>
  <span class="ruby-comment"># (current_server.uri rescue nil) == uri</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-install_acl" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">install_acl</span><span
            class="method-args">(acl)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p><a href="Set.html"><code>Set</code></a> the default <a href="ACL.html"><code>ACL</code></a> to <code>acl</code>.</p>

<p>See <a href="DRb/DRbServer.html#method-c-default_acl"><code>DRb::DRbServer.default_acl</code></a>.</p>
          
          

          
          <div class="method-source-code" id="install_acl-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1891</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">install_acl</span>(<span class="ruby-identifier">acl</span>)
  <span class="ruby-constant">DRbServer</span>.<span class="ruby-identifier">default_acl</span>(<span class="ruby-identifier">acl</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-install_id_conv" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">install_id_conv</span><span
            class="method-args">(idconv)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p><a href="Set.html"><code>Set</code></a> the default id conversion object.</p>

<p>This is expected to be an instance such as <a href="DRb/DRbIdConv.html"><code>DRb::DRbIdConv</code></a> that responds to <a href="DRb.html#method-i-to_id"><code>to_id</code></a> and <a href="DRb.html#method-i-to_obj"><code>to_obj</code></a> that can convert objects to and from <a href="DRb.html"><code>DRb</code></a> references.</p>

<p>See DRbServer#default_id_conv.</p>
          
          

          
          <div class="method-source-code" id="install_id_conv-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1883</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">install_id_conv</span>(<span class="ruby-identifier">idconv</span>)
  <span class="ruby-constant">DRbServer</span>.<span class="ruby-identifier">default_id_conv</span>(<span class="ruby-identifier">idconv</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-regist_server" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">regist_server</span><span
            class="method-args">(server)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Registers <code>server</code> with <a href="DRb.html"><code>DRb</code></a>.</p>

<p>This is called when a new DRb::DRbServer is created.</p>

<p>If there is no primary server then <code>server</code> becomes the primary server.</p>

<p>Example:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&#39;drb&#39;</span>

<span class="ruby-identifier">s</span> = <span class="ruby-constant">DRb</span><span class="ruby-operator">::</span><span class="ruby-constant">DRbServer</span>.<span class="ruby-identifier">new</span> <span class="ruby-comment"># automatically calls regist_server</span>
<span class="ruby-constant">DRb</span>.<span class="ruby-identifier">fetch_server</span> <span class="ruby-identifier">s</span>.<span class="ruby-identifier">uri</span> <span class="ruby-comment">#=&gt; #&lt;DRb::DRbServer:0x...&gt;</span>
</pre>
          
          

          
          <div class="method-source-code" id="regist_server-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1915</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">regist_server</span>(<span class="ruby-identifier">server</span>)
  <span class="ruby-ivar">@server</span>[<span class="ruby-identifier">server</span>.<span class="ruby-identifier">uri</span>] = <span class="ruby-identifier">server</span>
  <span class="ruby-identifier">mutex</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword">do</span>
    <span class="ruby-ivar">@primary_server</span> = <span class="ruby-identifier">server</span> <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@primary_server</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-remove_server" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">remove_server</span><span
            class="method-args">(server)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Removes <code>server</code> from the list of registered servers.</p>
          
          

          
          <div class="method-source-code" id="remove_server-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1924</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">remove_server</span>(<span class="ruby-identifier">server</span>)
  <span class="ruby-ivar">@server</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">server</span>.<span class="ruby-identifier">uri</span>)
  <span class="ruby-identifier">mutex</span>.<span class="ruby-identifier">synchronize</span> <span class="ruby-keyword">do</span>
    <span class="ruby-keyword">if</span> <span class="ruby-ivar">@primary_server</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">server</span>
      <span class="ruby-ivar">@primary_server</span> = <span class="ruby-keyword">nil</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-start_service" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">start_service</span><span
            class="method-args">(uri=nil, front=nil, config=nil)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Start a dRuby server locally.</p>

<p>The new dRuby server will become the primary server, even if another server is currently the primary server.</p>

<p><code>uri</code> is the <a href="URI.html"><code>URI</code></a> for the server to bind to.  If nil, the server will bind to random port on the default local host name and use the default dRuby protocol.</p>

<p><code>front</code> is the server&#39;s front object.  This may be nil.</p>

<p><code>config</code> is the configuration for the new server.  This may be nil.</p>

<p>See <a href="DRb/DRbServer.html#method-c-new"><code>DRbServer::new</code></a>.</p>
          
          

          
          <div class="method-source-code" id="start_service-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1771</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">start_service</span>(<span class="ruby-identifier">uri</span>=<span class="ruby-keyword">nil</span>, <span class="ruby-identifier">front</span>=<span class="ruby-keyword">nil</span>, <span class="ruby-identifier">config</span>=<span class="ruby-keyword">nil</span>)
  <span class="ruby-ivar">@primary_server</span> = <span class="ruby-constant">DRbServer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">uri</span>, <span class="ruby-identifier">front</span>, <span class="ruby-identifier">config</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-stop_service" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">stop_service</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Stop the local dRuby server.</p>

<p>This operates on the primary server.  If there is no primary server currently running, it is a noop.</p>
          
          

          
          <div class="method-source-code" id="stop_service-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1804</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">stop_service</span>
  <span class="ruby-ivar">@primary_server</span>.<span class="ruby-identifier">stop_service</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@primary_server</span>
  <span class="ruby-ivar">@primary_server</span> = <span class="ruby-keyword">nil</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-thread" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">thread</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Get the thread of the primary server.</p>

<p>This returns nil if there is no primary server.  See <a href="DRb.html#attribute-i-primary_server"><code>primary_server</code></a>.</p>
          
          

          
          <div class="method-source-code" id="thread-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1872</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">thread</span>
  <span class="ruby-ivar">@primary_server</span> <span class="ruby-operator">?</span> <span class="ruby-ivar">@primary_server</span>.<span class="ruby-identifier">thread</span> <span class="ruby-operator">:</span> <span class="ruby-keyword">nil</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-to_id" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">to_id</span><span
            class="method-args">(obj)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Get a reference id for an object using the current server.</p>

<p>This raises a <a href="DRb/DRbServerNotFound.html"><code>DRbServerNotFound</code></a> error if there is no current server. See <a href="DRb.html#method-i-current_server"><code>current_server</code></a>.</p>
          
          

          
          <div class="method-source-code" id="to_id-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1863</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_id</span>(<span class="ruby-identifier">obj</span>)
  <span class="ruby-identifier">current_server</span>.<span class="ruby-identifier">to_id</span>(<span class="ruby-identifier">obj</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-to_obj" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">to_obj</span><span
            class="method-args">(ref)</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Convert a reference into an object using the current server.</p>

<p>This raises a <a href="DRb/DRbServerNotFound.html"><code>DRbServerNotFound</code></a> error if there is no current server. See <a href="DRb.html#method-i-current_server"><code>current_server</code></a>.</p>
          
          

          
          <div class="method-source-code" id="to_obj-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1855</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_obj</span>(<span class="ruby-identifier">ref</span>)
  <span class="ruby-identifier">current_server</span>.<span class="ruby-identifier">to_obj</span>(<span class="ruby-identifier">ref</span>)
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
      <div id="method-i-uri" class="method-detail ">
        
        <div class="method-heading">
          <span class="method-name">uri</span><span
            class="method-args">()</span>
          
          <span class="method-click-advice">click to toggle source</span>
          
        </div>
        

        <div class="method-description">
          
          <p>Get the <a href="URI.html"><code>URI</code></a> defining the local dRuby space.</p>

<p>This is the <a href="URI.html"><code>URI</code></a> of the current server.  See <a href="DRb.html#method-i-current_server"><code>current_server</code></a>.</p>
          
          

          
          <div class="method-source-code" id="uri-source">
            <pre><span class="ruby-comment"># File lib/drb/drb.rb, line 1813</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">uri</span>
  <span class="ruby-identifier">drb</span> = <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-string">&#39;DRb&#39;</span>]
  <span class="ruby-identifier">client</span> = (<span class="ruby-identifier">drb</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">drb</span>[<span class="ruby-string">&#39;client&#39;</span>])
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">client</span>
    <span class="ruby-identifier">uri</span> = <span class="ruby-identifier">client</span>.<span class="ruby-identifier">uri</span>
    <span class="ruby-keyword">return</span> <span class="ruby-identifier">uri</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">uri</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">current_server</span>.<span class="ruby-identifier">uri</span>
<span class="ruby-keyword">end</span></pre>
          </div>
          
        </div>

        

        
      </div>

    
    </section>
  
  </section>

</main>


<footer id="validator-badges" role="contentinfo">
  <p><a href="https://validator.w3.org/check/referer">Validate</a>
  <p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.2.1.1.
  <p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
</footer>