Class: AutomateEm::LogicModule

Inherits:
Object
  • Object
show all
Defined in:
lib/automate-em/core/modules.rb

Constant Summary collapse

@@instances =

id => @instance

{}
@@lookup =
{}
@@lookup_lock =
Mutex.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(system, controllerLogic, theModule) ⇒ LogicModule

Returns a new instance of LogicModule.



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
# File 'lib/automate-em/core/modules.rb', line 312

def initialize(system, controllerLogic, theModule)
  @@lookup_lock.synchronize {
    if @@instances[controllerLogic.id].nil?
      instantiate_module(controllerLogic, system, theModule)
    end
  }
  if @instance.respond_to?(:on_load)
    begin
      @instance.on_load
    rescue => e
      AutomateEm.print_error(System.logger, e, {
        :message => "logic module #{@instance.class} error whilst calling: on_load",
        :level => Logger::ERROR
      })
    ensure
      ActiveRecord::Base.clear_active_connections!
    end
  end
end

Instance Attribute Details

#instanceObject (readonly)

Returns the value of attribute instance.



366
367
368
# File 'lib/automate-em/core/modules.rb', line 366

def instance
  @instance
end

Class Method Details

.instance_of(db_id) ⇒ Object



360
361
362
363
364
# File 'lib/automate-em/core/modules.rb', line 360

def self.instance_of(db_id)
  @@lookup_lock.synchronize {
    return @@instances[db_id]
  }
end

.lookup(instance) ⇒ Object



354
355
356
357
358
# File 'lib/automate-em/core/modules.rb', line 354

def self.lookup(instance)
  @@lookup_lock.synchronize {
    return @@lookup[instance]
  }
end

Instance Method Details

#unloadObject



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
# File 'lib/automate-em/core/modules.rb', line 332

def unload
  if @instance.respond_to?(:on_unload)
    begin
      @instance.on_unload
    rescue => e
      AutomateEm.print_error(System.logger, e, {
        :message => "logic module #{@instance.class} error whilst calling: on_unload",
        :level => Logger::ERROR
      })
    ensure
      ActiveRecord::Base.clear_active_connections!
    end
  end
  
  @instance.clear_active_timers
  
  @@lookup_lock.synchronize {
    db = @@lookup.delete(@instance)
    @@instances.delete(db.id)
  }
end