Sha256: 3cf9d088b3cc477b287e03678cca0a8af153192e476f0bb0eaf56b8418664db5

Contents?: true

Size: 963 Bytes

Versions: 20

Compression:

Stored size: 963 Bytes

Contents

#this resource is used to control applications frisbee/frisbeed and imagezip_server/imagezip_client.

$ports = []
module OmfRc::ResourceProxy::FrisbeeFactory
  include OmfRc::ResourceProxyDSL

  @config = YAML.load_file('/etc/nitos_testbed_rc/frisbee_proxy_conf.yaml')
  # @config = YAML.load_file(File.join(File.dirname(File.expand_path(__FILE__)), '../etc/frisbee_proxy_conf.yaml'))
  @fconf = @config[:frisbee]

  register_proxy :frisbee_factory

  request :ports do |res|
    port = @fconf[:startPort]
    loop do
      if $ports.include?(port)
        port +=1
      elsif !res.port_open?(port)
        port +=1
      else
        $ports << port
        break
      end
    end
    debug "port chosen: '#{port}'"
    port
  end

  def port_open?(port, seconds=1)
    Timeout::timeout(seconds) do
      begin
        TCPServer.new('localhost', port) rescue return false
        return true
      end
    end
  rescue Timeout::Error
    return false
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
nitos_testbed_rc-2.0.4 lib/nitos_testbed_rc/frisbee_factory.rb
nitos_testbed_rc-2.0.3 lib/nitos_testbed_rc/frisbee_factory.rb
nitos_testbed_rc-2.0.2 lib/nitos_testbed_rc/frisbee_factory.rb
nitos_testbed_rc-2.0.1 lib/nitos_testbed_rc/frisbee_factory.rb
nitos_testbed_rc-1.0.2 lib/nitos_testbed_rc/frisbee_factory.rb
nitos_testbed_rc-2.0.0 lib/nitos_testbed_rc/frisbee_factory.rb
nitos_testbed_rc-1.0.1 lib/nitos_testbed_rc/frisbee_factory.rb
nitos_testbed_rc-1.0.0.pre.14 lib/nitos_testbed_rc/frisbee_factory.rb
nitos_testbed_rc-1.0.0.pre.13 lib/nitos_testbed_rc/frisbee_factory.rb
nitos_testbed_rc-1.0.0.pre.12 lib/nitos_testbed_rc/frisbee_factory.rb
nitos_testbed_rc-1.0.0.pre.11 lib/nitos_testbed_rc/frisbee_factory.rb
nitos_testbed_rc-1.0.0.pre.10 lib/nitos_testbed_rc/frisbee_factory.rb
nitos_testbed_rc-1.0.0.pre.9 lib/nitos_testbed_rc/frisbee_factory.rb
nitos_testbed_rc-1.0.0.pre.8 lib/nitos_testbed_rc/frisbee_factory.rb
nitos_testbed_rc-1.0.0.pre.7 lib/nitos_testbed_rc/frisbee_factory.rb
nitos_testbed_rc-1.0.0.pre.6 lib/nitos_testbed_rc/frisbee_factory.rb
nitos_testbed_rc-1.0.0.pre.5 lib/nitos_testbed_rc/frisbee_factory.rb
nitos_testbed_rc-1.0.0.pre.4 lib/nitos_testbed_rc/frisbee_factory.rb
nitos_testbed_rc-1.0.0.pre.2 lib/nitos_testbed_rc/frisbee_factory.rb
nitos_testbed_rc-1.0.0.pre.1 lib/nitos_testbed_rc/frisbee_factory.rb