Skip to content

Commit

Permalink
documentation and mode commands improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
xea committed Oct 28, 2015
1 parent 6bc3dc5 commit d5555c3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 44 deletions.
13 changes: 0 additions & 13 deletions lib/console/mode_home.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,4 @@ class ModeHome < ModeGlobal
}
})

register_command(:mode_browse, "browse $objecttype :objectid", "Browse objects") do |objecttype, objectid|
p objecttype
p objectid
end

register_command(:set_global_var, "set :varname :value") { |varname, value| @global_vars[varname] = value }
register_command(:get_global_var, "get :varname") { |varname| puts @global_vars[varname] }

def construct
@global_vars = {}
end

end

62 changes: 31 additions & 31 deletions lib/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Core
include RunState
include Dispatcher

# Initialise a core with the most essential services (framework and console host).
# Initialise a core with the most essential services (framework and console host).
def initialize(system_name, pure = false)
@system_name = system_name
@current_stage = []
Expand Down Expand Up @@ -60,22 +60,14 @@ def initialize(system_name, pure = false)
end
end

def new_service(service_id, service_class, *args, &blk)
if service_class.include? Celluloid
@supervisor.supervise(service_id, service_class, *args, &blk)
else
service_class.new(*args, &blk)
end
end

def register_service(service_id, service, *service_args, &success_callback)
# Make sure we've got an initialised service object here
service_object = service.kind_of?(Class) ? new_service(service_id, service, *service_args) : service
# TODO service object initialisation error handling
service_object.init

# TODO revise the data type of service registration requests but they are good as arrays for now
service_registration_request = [ service_id, service_object, service_object.provided_features ]
service_registration_request = [ service_id, service_object, service_object.provided_features ]

@stage_monitor.synchronize do
@current_stage << service_registration_request
Expand All @@ -94,7 +86,7 @@ def bootstrap
try_console
end

# Initiate core shutdown.
# Initiate core shutdown.
def shutdown
@event_queue << :shutdown
@event_thread.join unless @event_thread.nil?
Expand Down Expand Up @@ -131,7 +123,7 @@ def process_stages(stages)
end
end

@stage_monitor.synchronize do
@stage_monitor.synchronize do
process_stages @service_stages
end
end
Expand Down Expand Up @@ -173,7 +165,7 @@ def start_service(service_registration)

# Post-activate optional dependencies
@service_registry.find_all { |srv| srv.state == RunState::ACTIVE and srv.optional_features.find_all { |feature| service.provided_features.member? feature}.length > 0 }.each do |opt_dependency|
opt_dependency.service.optional_features.find_all { |feature| service.provided_features.member? feature }.each do |feature|
opt_dependency.service.optional_features.find_all { |feature| service.provided_features.member? feature }.each do |feature|
puts "optional injection: #{feature} to #{opt_dependency.service.service_id}"
proxy = ServiceProxy.consume service.spawn_new(opt_dependency.service.service_id), self
opt_dependency.service.feature_up feature, proxy
Expand Down Expand Up @@ -211,7 +203,7 @@ def stop_service(service_registration)
end
end

# Close and commit the current service stage and open a new, empty stage. Services registered up to this
# Close and commit the current service stage and open a new, empty stage. Services registered up to this
# point will be processed as one batch.
def commit_stage
@stage_monitor.synchronize do
Expand All @@ -237,14 +229,37 @@ def event_loop(main_thread = nil)
end
end
end


protected

def run_console(console)
console.welcome

while console.running? do
console.show_prompt
raw_input = console.read_input
host_event = console.process_input raw_input
if host_event.kind_of? Symbol
@event_queue << host_event unless host_event.nil? if host_event.kind_of? Symbol
end
end
end

def new_service(service_id, service_class, *args, &blk)
if service_class.include? Celluloid
@supervisor.supervise(service_id, service_class, *args, &blk)
else
service_class.new(*args, &blk)
end
end

# TODO deal with concurrent/subsequent invocations
def try_console
# if console service is available

console = @framework.service :console
main_thread = Thread.current

if console.nil?
# No console service present, looping on main thread
event_loop(main_thread)
Expand All @@ -263,19 +278,4 @@ def try_console
end
end

protected

def run_console(console)
console.welcome

while console.running? do
console.show_prompt
raw_input = console.read_input
host_event = console.process_input raw_input
if host_event.kind_of? Symbol
@event_queue << host_event unless host_event.nil? if host_event.kind_of? Symbol
end
end
end
end

1 change: 1 addition & 0 deletions toolbox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require_relative 'lib/service/logger'
require_relative 'lib/service/discovery'

# Base toolbox setup with a core and some of the most essential services.
core = Core.new :toolbox
core.register_service :console, ConsoleService
core.commit_stage
Expand Down

0 comments on commit d5555c3

Please sign in to comment.