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) ⇒ LogicModule

Returns a new instance of LogicModule.



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

def initialize(system, controllerLogic)
	@@lookup_lock.synchronize {
		if @@instances[controllerLogic.id].nil?
			instantiate_module(controllerLogic, system)
		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.



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

def instance
  @instance
end

Class Method Details

.instance_of(db_id) ⇒ Object



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

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

.lookup(instance) ⇒ Object



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

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

Instance Method Details

#unloadObject



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

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