Class: Cuboid::RPC::Server::ApplicationWrapper

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Utilities
Defined in:
lib/cuboid/rpc/server/application_wrapper.rb

Overview

Author:

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utilities

#available_port, available_port_mutex, #bytes_to_kilobytes, #bytes_to_megabytes, #caller_name, #caller_path, #exception_jail, #generate_token, #hms_to_seconds, #port_available?, #rand_port, #random_seed, #regexp_array_match, #remove_constants, #seconds_to_hms

Constructor Details

#initialize(application) ⇒ ApplicationWrapper

Returns a new instance of ApplicationWrapper.



32
33
34
35
36
37
# File 'lib/cuboid/rpc/server/application_wrapper.rb', line 32

def initialize( application )
    super()

    @application = application.instance
    @extended_running = false
end

Instance Attribute Details

#applicationObject (readonly)

Returns the value of attribute application.



16
17
18
# File 'lib/cuboid/rpc/server/application_wrapper.rb', line 16

def application
  @application
end

Instance Method Details

#busy?Bool

Returns ‘true` If the system is scanning, `false` if #run hasn’t been called yet or if the scan has finished.

Returns:

  • (Bool)

    ‘true` If the system is scanning, `false` if #run hasn’t been called yet or if the scan has finished.



46
47
48
49
# File 'lib/cuboid/rpc/server/application_wrapper.rb', line 46

def busy?
    ![:ready, :done, :suspended].include?( @application.status ) &&
      !!@extended_running
end

#clean_upObject



66
67
68
69
70
71
72
73
# File 'lib/cuboid/rpc/server/application_wrapper.rb', line 66

def clean_up
    return false if @rpc_cleaned_up

    @rpc_cleaned_up   = true
    @extended_running = false

    @application.clean_up
end

#error_test(str) ⇒ Object



132
133
134
# File 'lib/cuboid/rpc/server/application_wrapper.rb', line 132

def error_test( str )
    @application.print_error str.to_s
end

#errors(starting_line = 0) ⇒ Array<String>

Parameters:

  • starting_line (Integer) (defaults to: 0)

    Sets the starting line for the range of errors to return.

Returns:



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/cuboid/rpc/server/application_wrapper.rb', line 79

def errors( starting_line = 0 )
    return [] if UI::Output.error_buffer.empty?

    error_strings = UI::Output.error_buffer

    if starting_line != 0
        error_strings = error_strings[starting_line..-1]
    end

    error_strings
end

#progress(opts = {}) ⇒ Hash

Provides aggregated progress data.

Parameters:

  • opts (Hash) (defaults to: {})

    Options about what data to include:

Options Hash (opts):

  • :statistics (Bool) — default: true

    Master/merged statistics.

  • :errors (Bool, Integer) — default: false

    Logged errors. If an integer is provided it will return errors past that index.

Returns:

  • (Hash)

    Progress data.



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/cuboid/rpc/server/application_wrapper.rb', line 103

def progress( opts = {} )
    opts = opts.my_symbolize_keys

    include_statistics = opts[:statistics].nil? ? true : opts[:statistics]
    include_errors     = opts.include?( :errors ) ?
        (opts[:errors] || 0) : false

    data = {
        status:         status,
        busy:           running?,
        application:    @application.class.to_s,
        seed:           Utilities.random_seed,
        agent_url: Cuboid::Options.agent.url,
        scheduler_url:  Cuboid::Options.scheduler.url
    }

    if include_statistics
        data[:statistics] = @application.statistics
    end

    if include_errors
        data[:errors] =
            errors( include_errors.is_a?( Integer ) ? include_errors : 0 )
    end

    data.merge( messages: status_messages )
end

#runBool

Returns ‘false` if already running, `true` otherwise.

Returns:

  • (Bool)

    ‘false` if already running, `true` otherwise.



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/cuboid/rpc/server/application_wrapper.rb', line 53

def run
    # Return if we're already running.
    return false if busy?
    @extended_running = true

    # Start the scan  -- we can't block the RPC server so we're using a Thread.
    Thread.new do
        @application.run
    end

    true
end

#valid_options?(options) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/cuboid/rpc/server/application_wrapper.rb', line 39

def valid_options?( options )
    @application.class.valid_options?( options )
end