LoaderQueue with strategies

With the loader queue it is easy to load data (f.e images or xml) application wide in a priority queue. This version uses encapsulated ILoader implementations and is therefore easy to extend.

The loader queue has the following tokens:

  • priority
  • stop/pause/resume services
  • remove services
  • In addition it is possible to parametrize the loaded data with an anchor that could be of any type. This is very useful when images belong to specific objects (see code example).

    For a new need of a loader implementation a programmer just had to write a new specific loader strategy that implements ILoader.

    Basic implementations like a Loader and a URLLoader for loading Loader and URLLoader specific data can be found in the addicted2flash library.

    Here is an example on how to use the LoaderQueue:

     
    package
    {
    	import flash.display.Sprite;	
     
    	import com.addicted2flash.data.DataEventType;
    	import com.addicted2flash.data.loader.LoaderQueue;
    	import com.addicted2flash.data.loader.URLLoader;
    	import com.addicted2flash.data.service.IDataService;
    	import com.addicted2flash.data.service.IDataServiceObserver;
     
    	import flash.net.URLRequest;	
     
    	/**
    	 * @author Tim Richter
    	 */
    	public class LoaderQueueTest extends Sprite implements IDataServiceObserver
    	{
     
    		public function LoaderQueueTest()
    		{
    			var anchor: String = "test anchor";
    			var service: IDataService = LoaderQueue.create( new URLLoader( ), new URLRequest( xmlSource ), anchor );
    			service.addDataServiceObserver( this );
    		}
     
    		public function get xmlSource(): String
    		{
    			return "http://gdata.youtube.com/feeds/base/standardfeeds/most_viewed?client=ytapi-youtube-browse&alt=rss&time=today";
    		}
     
    		/**
    		 * method from IDataServiceObserver
    		 */
    		public function processDataServiceEvent( type: String, service: IDataService ): void
    		{
    			trace( service.anchor );
     
    			switch( type )
    			{
    				case DataEventType.COMPLETE:
    					trace( service.data );
    					break;
     
    				case DataEventType.PROGRESS:
    					trace( service.dataProgress );
    					break;
     
    				case DataEventType.IO_ERROR:
    					trace( service.errorMessage );
    					break;
    			}
    		}
     
    		/**
    		 * method from IDataServiceObserver
    		 */
    		public function get acceptedDataServiceEvents(): int
    		{
    			return DataEventType.COMPLETE | DataEventType.PROGRESS | DataEventType.IO_ERROR;
    		}
    	}
    }
     

    The following uml-diagram shows the dependencies between the participants:
    LoaderQueue

    Leave a Reply

    Formatting: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>