Class: Mxrb::RubyApp::NativeBridge

Inherits:
Object
  • Object
show all
Defined in:
lib/mxrb/ruby_app.rb

Overview

Owns the source MPR and its pure-Ruby interpreter for one application.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, database:, record_hooks: {}, adapters: {}, java_custom_actions: {}, allow_destructive: false, coordinator: nil, scheduler_lease_ttl: 300) ⇒ NativeBridge

Returns a new instance of NativeBridge.



805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
# File 'lib/mxrb/ruby_app.rb', line 805

def initialize(path, database:, record_hooks: {}, adapters: {}, java_custom_actions: {},
               allow_destructive: false, coordinator: nil, scheduler_lease_ttl: 300)
  FileUtils.mkdir_p(File.dirname(database))
  @project = Model::Project.open(path)
  @store = Runtime::SQLiteStore.new(@project, path: database, allow_destructive:)
  @access_control = Runtime::AccessControl.new(@project)
  @interpreter = Runtime::Native::Interpreter.new(
    @project, store: @store, policy: @access_control, adapters:, java_custom_actions:
  )
  register_record_hooks(record_hooks)
  @scheduler = Runtime::Scheduler.new(
    @project,
    executor: ->(name, **) { @interpreter.call(name) }, coordinator:,
    lease_ttl: scheduler_lease_ttl
  )
rescue StandardError
  close
  raise
end

Instance Attribute Details

#access_controlObject (readonly)

Returns the value of attribute access_control.



803
804
805
# File 'lib/mxrb/ruby_app.rb', line 803

def access_control
  @access_control
end

#interpreterObject (readonly)

Returns the value of attribute interpreter.



803
804
805
# File 'lib/mxrb/ruby_app.rb', line 803

def interpreter
  @interpreter
end

#projectObject (readonly)

Returns the value of attribute project.



803
804
805
# File 'lib/mxrb/ruby_app.rb', line 803

def project
  @project
end

#schedulerObject (readonly)

Returns the value of attribute scheduler.



803
804
805
# File 'lib/mxrb/ruby_app.rb', line 803

def scheduler
  @scheduler
end

#storeObject (readonly)

Returns the value of attribute store.



803
804
805
# File 'lib/mxrb/ruby_app.rb', line 803

def store
  @store
end

Instance Method Details

#closeObject



830
831
832
833
834
# File 'lib/mxrb/ruby_app.rb', line 830

def close
  scheduler&.shutdown
  store&.close
  project&.close
end

#start_schedulerObject



825
826
827
828
# File 'lib/mxrb/ruby_app.rb', line 825

def start_scheduler
  scheduler.start unless scheduler.jobs.empty?
  scheduler
end