Class: Cuboid::Application

Inherits:
Object show all
Includes:
Support::Mixins::Observable, Support::Mixins::Parts, Support::Mixins::SpecInstances, UI::Output, Utilities, Singleton
Defined in:
lib/cuboid/application.rb,
lib/cuboid/application/runtime.rb,
lib/cuboid/application/parts/data.rb,
lib/cuboid/application/parts/state.rb,
lib/cuboid/application/parts/report.rb

Overview

Author:

Defined Under Namespace

Modules: Parts, PrependMethods Classes: Error, Runtime

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Support::Mixins::Parts

included

Methods included from Support::Mixins::Observable

included

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

Methods included from UI::Output

#error_buffer, initialize, #log_error, #output_provider_file, #print_bad, #print_debug, #print_error, #print_info, #print_line, #print_ok, #print_status, #print_verbose, #reroute_to_file, #reroute_to_file?

Methods included from UI::OutputInterface

initialize

Methods included from UI::OutputInterface::Personalization

#included

Methods included from UI::OutputInterface::Controls

#debug?, #debug_level, #debug_level_1?, #debug_level_2?, #debug_level_3?, #debug_level_4?, #debug_off, #debug_on, initialize, #verbose?, #verbose_off, #verbose_on

Methods included from UI::OutputInterface::ErrorLogging

#error_logfile, #has_error_log?, initialize, #set_error_logfile

Methods included from UI::OutputInterface::Implemented

#print_debug_backtrace, #print_debug_exception, #print_debug_level_1, #print_debug_level_2, #print_debug_level_3, #print_debug_level_4, #print_error_backtrace, #print_exception

Methods included from UI::OutputInterface::Abstract

#output_provider_file, #print_bad, #print_debug, #print_error, #print_info, #print_line, #print_ok, #print_status, #print_verbose

Methods included from Support::Mixins::SpecInstances

prepended

Constructor Details

#initializeApplication

Returns a new instance of Application.



260
261
262
263
264
# File 'lib/cuboid/application.rb', line 260

def initialize
    super

    @runtime = Runtime.new
end

Class Method Details

._spec_instance_cleanup(i) ⇒ Object



303
304
305
306
# File 'lib/cuboid/application.rb', line 303

def self._spec_instance_cleanup( i )
    # i.clean_up
    i.reset
end

.agent_service_for(name, service) ⇒ Object



134
135
136
# File 'lib/cuboid/application.rb', line 134

def agent_service_for( name, service )
    agent_services[name] = service
end

.agent_servicesObject



138
139
140
# File 'lib/cuboid/application.rb', line 138

def agent_services
    @agent_services ||= {}
end

.applicationObject



220
221
222
# File 'lib/cuboid/application.rb', line 220

def application
    @application
end

.application=(app) ⇒ Object



224
225
226
# File 'lib/cuboid/application.rb', line 224

def application=( app )
    @application = app
end

.connect(info) ⇒ Object



208
209
210
211
# File 'lib/cuboid/application.rb', line 208

def connect( info )
    info = info.my_symbolize_keys
    Processes::Instances.connect( info[:url], info[:token] )
end

.handler_for(signal, handler) ⇒ Object



142
143
144
# File 'lib/cuboid/application.rb', line 142

def handler_for( signal, handler )
    signal_handlers[signal] = handler
end

.inherited(application) ⇒ Object



213
214
215
216
217
218
# File 'lib/cuboid/application.rb', line 213

def inherited( application )
    super

    application.prepend PrependMethods
    self.application = application
end

.instance_service_for(name, service) ⇒ Object



118
119
120
# File 'lib/cuboid/application.rb', line 118

def instance_service_for( name, service )
    instance_services[name] = service
end

.instance_servicesObject



122
123
124
# File 'lib/cuboid/application.rb', line 122

def instance_services
    @instance_services ||= {}
end

.max_coresObject



98
99
100
# File 'lib/cuboid/application.rb', line 98

def max_cores
    @max_cores ||= 0
end

.max_diskObject



114
115
116
# File 'lib/cuboid/application.rb', line 114

def max_disk
    @max_disk ||= 0
end

.max_memoryObject



106
107
108
# File 'lib/cuboid/application.rb', line 106

def max_memory
    @max_memory ||= 0
end

.method_missing(sym, *args, &block) ⇒ Object



228
229
230
231
232
233
234
# File 'lib/cuboid/application.rb', line 228

def method_missing( sym, *args, &block )
    if instance.respond_to?( sym )
        instance.send( sym, *args, &block )
    else
        super( sym, *args, &block )
    end
end

.provision_cores(cores) ⇒ Object



94
95
96
# File 'lib/cuboid/application.rb', line 94

def provision_cores( cores )
    @max_cores = cores
end

.provision_disk(disk) ⇒ Object



110
111
112
# File 'lib/cuboid/application.rb', line 110

def provision_disk( disk )
    @max_disk = disk
end

.provision_memory(ram) ⇒ Object



102
103
104
# File 'lib/cuboid/application.rb', line 102

def provision_memory( ram )
    @max_memory = ram
end

.respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


236
237
238
# File 'lib/cuboid/application.rb', line 236

def respond_to?( *args )
    super || instance.respond_to?( *args )
end

.rest_service_for(name, service) ⇒ Object



126
127
128
# File 'lib/cuboid/application.rb', line 126

def rest_service_for( name, service )
    rest_services[name] = service
end

.rest_servicesObject



130
131
132
# File 'lib/cuboid/application.rb', line 130

def rest_services
    @rest_services ||= {}
end

.serialize_with(serializer) ⇒ Object



150
151
152
# File 'lib/cuboid/application.rb', line 150

def serialize_with( serializer)
    @serializer = serializer
end

.serializerObject



154
155
156
157
# File 'lib/cuboid/application.rb', line 154

def serializer
    @serializer ||= nil
    @serializer || RPC::Serializer
end

.signal_handlersObject



146
147
148
# File 'lib/cuboid/application.rb', line 146

def signal_handlers
    @signal_handlers ||= {}
end

.source_locationObject



172
173
174
175
176
177
178
179
180
181
182
# File 'lib/cuboid/application.rb', line 172

def source_location
    splits = self.to_s.split ( '::' )
    app    = splits.pop

    last_const = Object
    splits.each do |const_name|
        last_const = last_const.const_get( const_name.to_sym )
    end

    File.expand_path last_const.const_source_location( app.to_sym ).first
end

.spawn(type, options = {}, &block) ⇒ Object



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/cuboid/application.rb', line 184

def spawn( type, options = {}, &block )
    const = nil

    case type
    when :instance
        const = :Instances
    when :agent
        const = :Agents
    when :scheduler
        const = :Schedulers
    when :rest
        return Processes::Manager.spawn(
            :rest_service,
            options.merge( options: { paths: { application: source_location } } ),
            &block
        )
    end

    Processes.const_get( const ).spawn(
      options.merge( application: source_location ),
      &block
    )
end

.valid_options?(options) ⇒ Boolean

Returns:

  • (Boolean)


163
164
165
166
167
168
169
170
# File 'lib/cuboid/application.rb', line 163

def valid_options?( options )
    @validate_options_with ||= nil
    if @validate_options_with
        return instance.method( @validate_options_with ).call( options )
    end

    true
end

.validate_options_with(handler) ⇒ Object



159
160
161
# File 'lib/cuboid/application.rb', line 159

def validate_options_with( handler )
    @validate_options_with = handler
end

Instance Method Details

#applicationObject



312
313
314
# File 'lib/cuboid/application.rb', line 312

def application
    Cuboid::Application.application
end

#inspectObject



289
290
291
292
293
294
295
# File 'lib/cuboid/application.rb', line 289

def inspect
    stats = statistics

    s = "#<#{self.class} (#{status}) "
    s << "runtime=#{stats[:runtime]} "
    s << '>'
end

#optionsObject



274
275
276
# File 'lib/cuboid/application.rb', line 274

def options
    Options.application
end

#options=(opts) ⇒ Object



270
271
272
# File 'lib/cuboid/application.rb', line 270

def options=( opts )
    Options.application = opts
end

#runtimeObject



266
267
268
# File 'lib/cuboid/application.rb', line 266

def runtime
    @runtime
end

#safe(&block) ⇒ Object

Raises:

  • (ArgumentError)


320
321
322
323
324
325
326
327
328
329
330
331
# File 'lib/cuboid/application.rb', line 320

def safe( &block )
    raise ArgumentError, 'Missing block.' if !block_given?

    begin
        block.call self
    ensure
        clean_up
        reset
    end

    nil
end

#serializerObject



316
317
318
# File 'lib/cuboid/application.rb', line 316

def serializer
    self.class.serializer
end

#statisticsHash

Returns Framework statistics:

  • ‘:runtime` – Scan runtime in seconds.

Returns:

  • (Hash)

    Framework statistics:

    • ‘:runtime` – Scan runtime in seconds.



283
284
285
286
287
# File 'lib/cuboid/application.rb', line 283

def statistics
    {
        runtime: @start_datetime ? (@finish_datetime || Time.now) - @start_datetime : 0,
    }
end

#unsafeObject



308
309
310
# File 'lib/cuboid/application.rb', line 308

def unsafe
    self
end

#versionString

Returns the version of the framework.

Returns:

  • (String)

    Returns the version of the framework.



299
300
301
# File 'lib/cuboid/application.rb', line 299

def version
    Cuboid::VERSION
end