Commits

Guillermo Szeliga committed ca04ac8

- we can use created actor references within parent constructor, so all find_by_id() calles have been replaced.
- Need to introduce optimizations on tracking and logging so that we reduce locking calls and gain in performance.

Comments (0)

Files changed (8)

longtang/actors/domain.py

         self.__actor_ref = actor_inst
 
     def from_type(self, actor_type, unique_id):
-        self.__system_ref.from_type(actor_type, unique_id, self.__system_ref.find_by_id(self.__actor_ref.unique_id()))
+        return self.__system_ref.from_type(actor_type, unique_id, self.__system_ref.find_by_id(self.__actor_ref.unique_id()))
 
     def with_factory(self, factory_instance, unique_id):
-        self.__system_ref.with_factory(factory_instance, unique_id, self.__system_ref.find_by_id(self.__actor_ref.unique_id()))
+        return self.__system_ref.with_factory(factory_instance, unique_id, self.__system_ref.find_by_id(self.__actor_ref.unique_id()))
 
     def child(self, child_unique_id):
         return self.__system_ref.get_child(child_unique_id, self.__actor_ref.unique_id())

longtang/actors/inbound/filepoller.py

 
 						self.__inflate_requests[full_path]=None
 
-						self.context().find_by_id('filepump-actor').tell(fp_messages.InflateFile(full_path), self.myself())
+						self.__filepump_ref.tell(fp_messages.InflateFile(full_path), self.myself())
 
 				self.__notify_polling_done_if_possible()
 

longtang/actors/supervisors/filepackaging/filepackaging.py

 			
 			self.logger().info('File to be packaged received', message.tracking())
 			facade.MediaTrackingFacade.from_context(self.context()).notify(message.tracking(), events.PackagingStarted())
-			self.context().find_by_id('id3-folder-manager-actor').tell(filesystem_messages.CreateFolderFromMetadata(message.source_file(),\
+			self.__folder_manager_ref.tell(filesystem_messages.CreateFolderFromMetadata(message.source_file(),\
 																													message.metadata(), \
 																													message.target_dir(), message.tracking()), self.myself())
 
 
 			self.logger().info('Target folder has been succesfully created', message.tracking())
 			facade.MediaTrackingFacade.from_context(self.context()).notify(message.tracking(), events.TargetFolderCreated())
-			self.context().find_by_id('id3-file-manager-actor').tell(filesystem_messages.CopyFileTo(message.source_file(),\
+			self.__file_manager_ref.tell(filesystem_messages.CopyFileTo(message.source_file(),\
 																									message.metadata(),\
 																									message.new_dir_path(), message.tracking()), self.myself())
 		elif isinstance(message, filesystem_messages.FileSuccessfullyCopied):
 
 			self.logger().info('Media file succesfully copied', message.tracking())
 			facade.MediaTrackingFacade.from_context(self.context()).notify(message.tracking(), events.MediaFileCopied())
-			self.context().find_by_id('id3-file-tagger-actor').tell(id3tag_messages.WriteFileMetadata(message.copied_file(),\
+			self.__file_tagger_ref.tell(id3tag_messages.WriteFileMetadata(message.copied_file(),\
 																										message.metadata(), message.tracking()), self.myself())
 		elif isinstance(message, id3tag_messages.FileMetadataUpdated):
 			
 			self.logger().info('Media file succesfully updated with metadata', message.tracking())
 			facade.MediaTrackingFacade.from_context(self.context()).notify(message.tracking(), events.MetadataUpdated())
-			self.context().find_by_id('id3-file-manager-actor').tell(filesystem_messages.RenameFileFromMetadata(message.source(),\
+			self.__file_manager_ref.tell(filesystem_messages.RenameFileFromMetadata(message.source(),\
 																												 message.metadata(), message.tracking()), self.myself())
 		elif isinstance(message, filesystem_messages.FileSuccessfullyRenamed):
 

longtang/actors/supervisors/flowconductor/flowconductor.py

 	
 	def receive(self, message):
 		if isinstance(message, messages.MediaFileAvailable):
-			self.context().find_by_id('id3taghandler-actor').tell(id3tag_messages.InspectFileMetadata(message.filepath(), message.tracking()), self.myself())
+			self.__id3taghandler_ref.tell(id3tag_messages.InspectFileMetadata(message.filepath(), message.tracking()), self.myself())
 		elif isinstance(message, id3tag_messages.FileMetadataAvailable):
-			self.context().find_by_id('filepackaging-actor').tell(packaging_messages.PerformFilePackaging(message.source_file(), message.metadata(), self.__config.generate_at, message.tracking()), self.myself())
+			self.__filepackaging_ref.tell(packaging_messages.PerformFilePackaging(message.source_file(), message.metadata(), self.__config.generate_at, message.tracking()), self.myself())
 		elif isinstance(message, packaging_messages.FilePackagingFinished):
 			self.parent().tell(messages.MediaFileHasBeenProcessed(message.tracking()), self.myself())
 		elif isinstance(message, id3tag_messages.FileMetadataCouldNotBeEvaluated):

longtang/actors/supervisors/id3taghandler/id3taghandler.py

 		if isinstance(message, messages.InspectFileMetadata):
 			self.logger().info(u'Starting metadata inspection on file .....', message.tracking())
 			facade.MediaTrackingFacade.from_context(self.context()).notify(message.tracking(), events.MetadataInspectionStarted())
-			self.context().find_by_id('id3tag-reader-actor').tell(id3tag_messages.CheckFileMetadata(message.source_file(), message.tracking()), self.myself())
+			self.__id3tagchecker_ref.tell(id3tag_messages.CheckFileMetadata(message.source_file(), message.tracking()), self.myself())
 
 		elif isinstance(message, id3tag_messages.FileMetadataIsComplete):
 			facade.MediaTrackingFacade.from_context(self.context()).notify(message.tracking(), events.MetadataAvailable())
 
 			if self.__config.override_tags:
-				self.context().find_by_id('musicbrainz-actor').tell(mb_messages.OverrideFileMetadata(message.source(), message.metadata(), message.tracking()), self.myself())				
+				self.__musicbrainz_ref.tell(mb_messages.OverrideFileMetadata(message.source(), message.metadata(), message.tracking()), self.myself())				
 			else:
 				self.parent().tell(messages.FileMetadataAvailable(message.source(), message.metadata(), message.tracking()), self.myself())
 
 			if not self.__config.offline_mode:
 				self.logger().info('There\'re some metadata fields missing. Trying with musicbrainz .....', message.tracking())
 				facade.MediaTrackingFacade.from_context(self.context()).notify(message.tracking(), events.FileMetadataIncomplete())
-				self.context().find_by_id('musicbrainz-actor').tell(mb_messages.FillUpMissingMetadataFields(message.source(), message.metadata(), message.tracking()), self.myself())
+				self.__musicbrainz_ref.tell(mb_messages.FillUpMissingMetadataFields(message.source(), message.metadata(), message.tracking()), self.myself())
 			else:
 				self.logger().error('File metadata could not be fulfilled and offline mode is active.', message.tracking())
 				facade.MediaTrackingFacade.from_context(self.context()).notify(message.tracking(), events.MetadataNotAvailable())

longtang/actors/supervisors/main/main.py

 
 	def pre_setup(self):
 		
+		self.__counter = 0
+
 		self.logger().info('Initializing actors...')
 		self.logger().info('Initializing file-poller-actor...')
 
 		self.__tracking_facade = facade.MediaTrackingFacade.create_within(self.context())
 
 	
+	#TODO Invertir la generacion de tracking id, en vez de que la genere el actor, hacemos que el facade
+	#lo haga y hacemos un tell en vez de un ask, y no perdemos el tracking
+
 	def receive(self, message):
 		if isinstance(message, messages.KickOffMediaProcessing):
 			self.__caller.append(self.sender())
 			self.logger().info('Media processing has just started. [From: {0}, To: {1}]'.format(self.__config.read_from, self.__config.generate_at))
-			self.context().find_by_id('file-poller-actor').tell(fp_messages.StartPolling(self.__config.read_from), self.myself())
+			self.__file_poller_ref.tell(fp_messages.StartPolling(self.__config.read_from), self.myself())
 
 		elif isinstance(message, fp_messages.CompressedAudioFileFound):
 			tracking_id, parent_tracking_id = facade.MediaTrackingFacade.from_context(self.context()).create_compressed_audio_tracking(message.filepath(), message.compressed_parent_filepath())
 			self.__filecount[tracking_id] = None
 
+			self.add_to_file_counter()
+
 			self.logger().debug(u'Compressed audio file tracked. [path: {0}, parent: {1}, tracking_id: {2}]'.format(message.filepath(),\
 																												  message.compressed_parent_filepath(),\
 																												  tracking_id))
 
-			self.context().find_by_id('flowconductor-actor').tell(fc_messages.MediaFileAvailable(message.filepath(), tracking_id), self.myself())
+			self.__flowconductor_ref.tell(fc_messages.MediaFileAvailable(message.filepath(), tracking_id), self.myself())
 
 		elif isinstance(message, fp_messages.AudioFileFound):
 			tracking_id = facade.MediaTrackingFacade.from_context(self.context()).create_audio_tracking(message.filepath())
 			self.__filecount[tracking_id] = None
+			self.add_to_file_counter()
 
 			self.logger().debug(u'Audio file tracked. [path: {0}, tracking_id: {1}]'.format(message.filepath(), tracking_id))
 
-			self.context().find_by_id('flowconductor-actor').tell(fc_messages.MediaFileAvailable(message.filepath(), tracking_id), self.myself())
+			self.__flowconductor_ref.tell(fc_messages.MediaFileAvailable(message.filepath(), tracking_id), self.myself())
 
 		elif isinstance(message, fp_messages.CompressedFileCouldNotBeOpened):
 
 		else: 
 			self.notify_marooned_message(message)		
 
+	def add_to_file_counter(self):
+		self.__counter = self.__counter + 1
+
 	def terminate_if_done(self, message):
 
-		self.__filecount.pop(message.tracking())
+		#self.__filecount.pop(message.tracking())
+		self.__counter = self.__counter - 1
 
-		if len(self.__filecount) == 0:
+		if self.__counter == 0:
 			self.logger().info('Terminating execution.....')
-			summary = facade.MediaTrackingFacade.from_context(self.context()).retrieve_summary()
+			summary =  None #facade.MediaTrackingFacade.from_context(self.context()).retrieve_summary()
 			self.__caller[0].tell(messages.MediaProcessingFinished(summary), self.myself())

longtang/actors/tracking/facade.py

 		return MediaTrackingFacade(system_ref_tmp, actor_ref)
 
 	def create_audio_tracking(self, mediapath):
-		response = interactions.InteractionPatterns.ask(self.__system_ref,self.__actor_ref, messages.CreateTrackingEntry(mediapath))
-		return response.tracking_id()
+		#response = interactions.InteractionPatterns.ask(self.__system_ref,self.__actor_ref, messages.CreateTrackingEntry(mediapath))
+		#return response.tracking_id()
+		pass
 
 	def create_compressed_audio_tracking(self, mediapath, parent_mediapath):
-		response = interactions.InteractionPatterns.ask(self.__system_ref,self.__actor_ref, messages.CreateCompressedAudioFileTrackingEntry(mediapath, parent_mediapath))
-		return response.tracking_id(), response.parent_tracking_id()
+		# response = interactions.InteractionPatterns.ask(self.__system_ref,self.__actor_ref, messages.CreateCompressedAudioFileTrackingEntry(mediapath, parent_mediapath))
+		# return response.tracking_id(), response.parent_tracking_id()
+		pass
 
 	def create_compressed_file_tracking(self, mediapath):
-		response = interactions.InteractionPatterns.ask(self.__system_ref,self.__actor_ref, messages.CreateCompressedFileTrackingEntry(mediapath))
-		return response.tracking_id()
+		# response = interactions.InteractionPatterns.ask(self.__system_ref,self.__actor_ref, messages.CreateCompressedFileTrackingEntry(mediapath))
+		# return response.tracking_id()
+		pass
 
 	def lookup(self, tracking_id):
-		response = interactions.InteractionPatterns.ask(self.__system_ref,self.__actor_ref, messages.LookupTrackingEntry(tracking_id))
-		return response.tracking_info()
+		# response = interactions.InteractionPatterns.ask(self.__system_ref,self.__actor_ref, messages.LookupTrackingEntry(tracking_id))
+		# return response.tracking_info()
+		pass
 
 	def notify(self, tracking_id, event):
 		self.__actor_ref.tell(messages.RegisterTrackingEvent(tracking_id,event), None)

longtang/system/syslogger.py

 	def __init__(self, system_ref, level):
 		#FIXME I'm always running the logger whether the level is None or not, maybe I could save a thread by not running it
 		self.__logger_actor_ref = system_ref.with_factory(factory.LoggerActorFactory(level),'sys-logger', domain.ROOT_PARENT)
+		print 'TODO ==> Evitar que se envien trazas cuando el nivel es None!!! ' + level
 		self.__level=level
 
 	def info(self, actor_id, message, source_file):