Sha256: 26ad1a46a6dcbc609f5b9ad464adc7cf2aeff53ad09898fe6ee57afa3046d005

Contents?: true

Size: 1.37 KB

Versions: 4

Compression:

Stored size: 1.37 KB

Contents

require "pathname"
require "drb/drb"
require "akephalos/client"

# In ruby-1.8.7 and later, the message for a NameError exception is lazily
# evaluated. There are, however, different implementations of this between ruby
# and jruby, so we realize these messages when sending over DRb.
class NameError::Message
  # @note This method is called by DRb before sending the error to the remote
  # connection.
  # @return [String] the inner message.
  def _dump
    to_s
  end
end

[
  Akephalos::Page,
  Akephalos::Node,
  Akephalos::Client::Cookies,
  Akephalos::Client::Cookies::Cookie
].each { |klass| klass.send(:include, DRbUndumped) }

module Akephalos

  # Akephalos::Server is used by `akephalos --server` to start a DRb server
  # serving an instance of Akephalos::Client.
  class Server
    # Start DRb service for an Akephalos::Client.
    #
    # @param [String] port attach server to
    def self.start!(port)
      abort_on_parent_exit!
      client = Client.new
      DRb.start_service("druby://127.0.0.1:#{port}", client)
      DRb.thread.join
    end

    private

    # Exit if STDIN is no longer readable, which corresponds to the process
    # which started the server exiting prematurely.
    #
    # @api private
    def self.abort_on_parent_exit!
      Thread.new do
        begin
          STDIN.read
        rescue IOError
          exit
        end
      end
    end
  end

end

Version data entries

4 entries across 4 versions & 3 rubygems

Version Path
akephalos-nerian-0.2.4-java lib/akephalos/server.rb
akephalos-nerian-0.2.4 lib/akephalos/server.rb
akephalos-2s-0.2.4 lib/akephalos/server.rb
brentgreeff_akephalos-0.2.4 lib/akephalos/server.rb