Sha256: 05e4da6fdbb0c658e15fe67071ac6653d9c3b9d9328cb0cf5893d7f9bc723f31

Contents?: true

Size: 1.72 KB

Versions: 9

Compression:

Stored size: 1.72 KB

Contents

# Sample client support
#

require 'rubygems'
case RUBY_PLATFORM
when /java/i
  gem 'spoon'; require 'spoon'
end

$: << File.expand_path("../../lib", __FILE__)
require 'asir'
require 'asir/transport/file'
require 'asir/transport/local'
require 'asir/transport/subprocess'
require 'asir/transport/thread'
require 'asir/transport/tcp_socket'
require 'asir/transport/fallback'
require 'asir/transport/broadcast'
require 'asir/coder/marshal'
require 'asir/coder/yaml'
require 'asir/coder/sign'
require 'asir/coder/chain'
ASIR::Log.enabled = true unless ENV['ASIR_EXAMPLE_SILENT']
require 'sample_service'
require 'delayed_service'
require 'unsafe_service'

require 'pp'
require 'timeout'
require File.expand_path('../../spec/debug_helper', __FILE__)

@customer = 123

class ::Object

def pr result
  $stdout.puts "*** #{$$}: pr: #{PP.pp(result, '')}"
end

# Work-around lack of fork in JRuby.
require 'asir/application'
$asir_app = ASIR::Application.new
$asir_app.inc = [ 'example', 'lib' ]
$asir_server = nil

def server_process &blk
  $asir_server = $asir_app.spawn :server do
    puts "*** #{$$}: server process"; $stdout.flush
    begin
      Timeout.timeout(20, ASIR::Error::Fatal) do
        yield
      end
    rescue ::Exception => exc
      $stderr.puts "*** #{$$}: service ERROR: #{exc.inspect}\n  #{exc.backtrace * "  \n"}"
      raise exc
    end
  end
  $asir_app.main do
    $asir_server.go!
    $server_pid = $asir_server.pid
    sleep 1 # wait for server to be ready.
  end
  return false # do client.
end

def server_kill
  if $server_pid
    $asir_server.kill
  end
ensure
  $server_pid = nil
end

end # class Object

module Process
  include ASIR::Client
end

unless $asir_app.in_spawn?
  puts "*** #{$$}: client process"; $stdout.flush
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
asir-1.2.11 example/example_helper.rb
asir-1.2.10 example/example_helper.rb
asir-1.2.9 example/example_helper.rb
asir-1.2.8 example/example_helper.rb
asir-1.2.7 example/example_helper.rb
asir-1.2.6 example/example_helper.rb
asir-1.2.5 example/example_helper.rb
asir-1.2.3 example/example_helper.rb
asir-1.2.2 example/example_helper.rb