Hi all, The problem description is as follows: I need to fetch a couple of files across the network, each file residing on different machines on the network. In some cases, I use FTP to retrieve them and for rest I directly get data from the database. Since, on a distributed environment, things can go wrong, therefore, I have a dedicated object maintaining a job queuue responsible for fetching different files across the netowrk. If an attempt fails for whatsoever reason, the dedicated object will try again after a time interval. It continues its attempt at regular intervals until it succeeds or instructed by a master controller object to terminate all its attempts. When the dedicated object successfully fetches a particular file, it must inform/notify the master controller object about it so that it can do further processing. Now, its for the above situation I intend to use the observer pattern. Here, the subject is the dedicated object and the observer is the master controller object. The motivation behind this is:- The master controller assigns a set of jobs to the dedicated object to be executed. But, the master controller does not know at what point of time and in what order they will get executed. The dedicated object must notify whenever it executed a task in its job queue to the controller so that it can take further action. Also, by using the observer pattern, I am achieving the loose coupling between the controller and dedicated object. Therefore, the dedicated object need not have any reference of the controller. Also, I intend to run the dedicated object as a seperate thread. Its for above reasons I intend to use Observer pattern. Can you please let me know your comments on this - anyone for or against it ?
In general the observer pattern sounds right for this application. However the design should take into consideration your distributed architecture. Please elaborate on what architecture you are planing to use.
posted 19 years ago
Aleksey, Many thanks for your comments. Well, the way I intend to implement this application is as follows: This application will lie on the middle tier on our iPlant application server along with other java objects written for other applications. By doing this, I can re-use the functionality of existing objects. I intend to put the bunch of classes in a seperate package under the billing module. This appplication contains the following main objects: Controller:- Its the big boss in the application - it delegates task, tracks their statuses, monitors them and takes suitable action in case failures(e.g. escalation of the situation by sending email notification to admin) Downloader Agent :- It has a job queue containing a set of tasks. Each task invovles retrieving a flat file containing billable data to a local working directory. This oject does not do the file-retrieving by iteself, instead delegates this task to a factory that actually knows where (across n/w) and how (whether ftp or from DB directly) to retrieve them. In case the factory is unable to get the files due whatsoever reason, then Downloader Agent will mark this task as a pending one. It will then delegate that task again to the factory at a later point of time. This cycle continues until a timeout or instructed by the masterController object to terminate. DownloaderFactory Objects:- The individual objects in this factory know how to retrieve a file across the network. It may either use FTP to retrieve or directly get data from a DB. All the data regarding the location from which data needs to retrieved is stored on a properties.txt file and they are configurable.
Was this info sufficient ? Thanks again, ------------------ - Sathvathsan Sampath