Class: Cuboid::Application
Overview
Defined Under Namespace
Modules: Parts, PrependMethods
Classes: Error, Runtime
Class Method Summary
collapse
Instance Method Summary
collapse
included
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?
initialize
#included
#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
#error_logfile, #has_error_log?, initialize, #set_error_logfile
#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
#output_provider_file, #print_bad, #print_debug, #print_error, #print_info, #print_line, #print_ok, #print_status, #print_verbose
prepended
Constructor Details
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.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_services ⇒ Object
138
139
140
|
# File 'lib/cuboid/application.rb', line 138
def agent_services
@agent_services ||= {}
end
|
.application ⇒ Object
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_services ⇒ Object
122
123
124
|
# File 'lib/cuboid/application.rb', line 122
def instance_services
@instance_services ||= {}
end
|
.max_cores ⇒ Object
98
99
100
|
# File 'lib/cuboid/application.rb', line 98
def max_cores
@max_cores ||= 0
end
|
114
115
116
|
# File 'lib/cuboid/application.rb', line 114
def max_disk
@max_disk ||= 0
end
|
.max_memory ⇒ Object
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
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_services ⇒ Object
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
|
.serializer ⇒ Object
154
155
156
157
|
# File 'lib/cuboid/application.rb', line 154
def serializer
@serializer ||= nil
@serializer || RPC::Serializer
end
|
.signal_handlers ⇒ Object
146
147
148
|
# File 'lib/cuboid/application.rb', line 146
def signal_handlers
@signal_handlers ||= {}
end
|
.source_location ⇒ Object
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
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
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
|
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
|
266
267
268
|
# File 'lib/cuboid/application.rb', line 266
def runtime
@runtime
end
|
#safe(&block) ⇒ Object
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
|
#serializer ⇒ Object
316
317
318
|
# File 'lib/cuboid/application.rb', line 316
def serializer
self.class.serializer
end
|
#statistics ⇒ Hash
Returns Framework statistics:
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
|
308
309
310
|
# File 'lib/cuboid/application.rb', line 308
def unsafe
self
end
|
#version ⇒ String
Returns the version of the framework.
299
300
301
|
# File 'lib/cuboid/application.rb', line 299
def version
Cuboid::VERSION
end
|