Module: DRb

Defined in:
lib/drb/drb.rb,
lib/drb/eq.rb,
lib/drb/gw.rb,
lib/drb/ssl.rb,
lib/drb/unix.rb,
lib/drb/extserv.rb,
lib/drb/extservm.rb,
lib/drb/observer.rb,
lib/drb/timeridconv.rb,
lib/drb/invokemethod.rb

Overview

for ruby-1.8.0

Defined Under Namespace

Modules: DRbObservable, DRbProtocol, DRbUndumped Classes: DRbArray, DRbBadScheme, DRbBadURI, DRbConn, DRbConnError, DRbError, DRbIdConv, DRbMessage, DRbObject, DRbRemoteError, DRbSSLSocket, DRbServer, DRbServerNotFound, DRbTCPSocket, DRbUNIXSocket, DRbURIOption, DRbUnknown, DRbUnknownError, ExtServ, ExtServManager, GW, GWIdConv, TimerIdConv

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (Object) primary_server

The primary local dRuby server.

This is the server created by the #start_service call.



1637
1638
1639
# File 'lib/drb/drb.rb', line 1637

def primary_server
  @primary_server
end

Instance Method Details

- (Object) config

Get the configuration of the current server.

If there is no current server, this returns the default configuration. See #current_server and DRbServer::make_config.



1692
1693
1694
1695
1696
# File 'lib/drb/drb.rb', line 1692

def config
  current_server.config
rescue
  DRbServer.make_config
end

- (Object) current_server

Get the 'current' server.

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.

If the above rule fails to find a server, a DRbServerNotFound error is raised.

Raises:



1650
1651
1652
1653
1654
1655
# File 'lib/drb/drb.rb', line 1650

def current_server
  drb = Thread.current['DRb']
  server = (drb && drb['server']) ? drb['server'] : @primary_server
  raise DRbServerNotFound unless server
  return server
end

- (Object) fetch_server(uri)



1770
1771
1772
# File 'lib/drb/drb.rb', line 1770

def fetch_server(uri)
  @server[uri]
end

- (Object) front

Get the front object of the current server.

This raises a DRbServerNotFound error if there is no current server. See #current_server.



1703
1704
1705
# File 'lib/drb/drb.rb', line 1703

def front
  current_server.front
end

- (Boolean) here?(uri)

Is uri the URI for the current local server?

Returns:

  • (Boolean)


1683
1684
1685
# File 'lib/drb/drb.rb', line 1683

def here?(uri)
  (current_server.uri rescue nil) == uri
end

- (Object) install_acl(acl)

Set the default acl.

See DRb::DRbServer.default_acl.



1745
1746
1747
# File 'lib/drb/drb.rb', line 1745

def install_acl(acl)
  DRbServer.default_acl(acl)
end

- (Object) install_id_conv(idconv)

Set the default id conv object.

See DRbServer#default_id_conv.



1737
1738
1739
# File 'lib/drb/drb.rb', line 1737

def install_id_conv(idconv)
  DRbServer.default_id_conv(idconv)
end

- (Object) mutex



1751
1752
1753
# File 'lib/drb/drb.rb', line 1751

def mutex
  @mutex
end

- (Object) regist_server(server)



1757
1758
1759
1760
1761
1762
# File 'lib/drb/drb.rb', line 1757

def regist_server(server)
  @server[server.uri] = server
  mutex.synchronize do
    @primary_server = server unless @primary_server
  end
end

- (Object) remove_server(server)



1765
1766
1767
# File 'lib/drb/drb.rb', line 1765

def remove_server(server)
  @server.delete(server.uri)
end

- (Object) start_service(uri = nil, front = nil, config = nil)

Start a dRuby server locally.

The new dRuby server will become the primary server, even if another server is currently the primary server.

uri is the URI 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.

front is the server's front object. This may be nil.

config is the configuration for the new server. This may be nil.

See DRbServer::new.



1629
1630
1631
# File 'lib/drb/drb.rb', line 1629

def start_service(uri=nil, front=nil, config=nil)
  @primary_server = DRbServer.new(uri, front, config)
end

- (Object) stop_service

Stop the local dRuby server.

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



1662
1663
1664
1665
# File 'lib/drb/drb.rb', line 1662

def stop_service
  @primary_server.stop_service if @primary_server
  @primary_server = nil
end

- (Object) thread

Get the thread of the primary server.

This returns nil if there is no primary server. See #primary_server.



1729
1730
1731
# File 'lib/drb/drb.rb', line 1729

def thread
  @primary_server ? @primary_server.thread : nil
end

- (Object) to_id(obj)

Get a reference id for an object using the current server.

This raises a DRbServerNotFound error if there is no current server. See #current_server.



1720
1721
1722
# File 'lib/drb/drb.rb', line 1720

def to_id(obj)
  current_server.to_id(obj)
end

- (Object) to_obj(ref)

Convert a reference into an object using the current server.

This raises a DRbServerNotFound error if there is no current server. See #current_server.



1712
1713
1714
# File 'lib/drb/drb.rb', line 1712

def to_obj(ref)
  current_server.to_obj(ref)
end

- (Object) uri

Get the URI defining the local dRuby space.

This is the URI of the current server. See #current_server.



1671
1672
1673
1674
1675
1676
1677
1678
1679
# File 'lib/drb/drb.rb', line 1671

def uri
  drb = Thread.current['DRb']
  client = (drb && drb['client'])
  if client
    uri = client.uri
    return uri if uri
  end
  current_server.uri
end