Class: AutomateEm::ServiceModule

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

Constant Summary collapse

@@instances =

db id => @instance

{}
@@dbentry =

db id => db instance

{}
@@services =

uri => @instance

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(system, controllerService, theModule) ⇒ ServiceModule

Returns a new instance of ServiceModule.



211
212
213
214
215
216
217
218
219
220
# File 'lib/automate-em/core/modules.rb', line 211

def initialize(system, controllerService, theModule)
	@@lookup_lock.synchronize {
		if @@instances[controllerService.id].nil?
			@system = system
			@service = controllerService.id
			@@dbentry[controllerService.id] = controllerService
		end
	}
	instantiate_module(controllerService, theModule)
end

Instance Attribute Details

#instanceObject (readonly)

Returns the value of attribute instance.



253
254
255
# File 'lib/automate-em/core/modules.rb', line 253

def instance
  @instance
end

Class Method Details

.instance_of(db_id) ⇒ Object



246
247
248
249
250
# File 'lib/automate-em/core/modules.rb', line 246

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

.lookup(instance) ⇒ Object



240
241
242
243
244
# File 'lib/automate-em/core/modules.rb', line 240

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

Instance Method Details

#unloadObject

should never be called on the reactor thread so no need to defer



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/automate-em/core/modules.rb', line 223

def unload	# should never be called on the reactor thread so no need to defer
	
	@instance.base.shutdown(@system)
	
	@@lookup_lock.synchronize {
		db = @@lookup[@instance].delete(@service)
		@@instances.delete(db)
		db = @@dbentry.delete(db)
		
		if @@lookup[@instance].empty?
			@@lookup.delete(@instance)
			@@services.delete(db.uri)
		end
	}
end