cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremy Quinn <jer...@media.demon.co.uk>
Subject Any interest in a JobManager?
Date Thu, 21 Aug 2003 09:18:17 GMT
Hi All,

For my current client, I have implemented a JobManager and I am 
wondering if it is general enough to be of interest to anyone else (ie. 
commit it to Cocoon as a Block). It is not a proper avalon component 
yet, so I would have to do this first.

The problem I needed to solve was this:

The client needs to have large numbers of Resources added to their site 
on a regular basis.
The Resources comprise sets of media files. For example an ImageJob may 
comprise the following:

    assets/pending/images/
                                           large/image1.jpg             
-- hi res
                                           medium/image1.jpg        -- 
medium res
                                           small/image1.jpg             
-- low res

A VideoJob :

    assets/pending/video/
                                           ref/movie1.mov                
-- reference movie, linked to:
                                           data/movie1_56k.mov       -- 
low res data movie
                                           data/movie1_ISDN.mov     -- 
medium res data movie
                                           data/movie1_T1.mov         -- 
high res data movie

Adding the Resources involves :

	finding a Job
	validating the Job is intact
	adding meta data to a Form to be added to a database
	moving the Job's file set to the appropriate server location

This needs to be carried out by a team of people, sharing the work, so 
I had to have a way of locking a 'Job' while someone is working on it 
(which I have called 'take' and 'release').

I think I have managed to write this in a generic way.

You would write a Job/JobFactory pair and add the Factory (or any 
number of them) to a Manager then ask the Manger for Jobs.

The JobFactory is responsible for doing whatever is needed to generate 
a Job, for instance, a Job can be anything like a set of files, some 
database records, maybe even email, or a mixture .....

I have 4 Interfaces:

// implemented by a JobManagerImpl
public interface Manager {
	
	/**
	 * Get a named <code>{@link Managable}</code> Job from a source 
collection.
	 * Will look in all <code>{@link JobFactory}</code>s.
	 * @param source the source collection to use
	 * @param jobname the name of the job
	 * @return Job the job you asked for, or null if it did not exist
	 */	
	public Managable getJob (String source, String jobname);
	
	/**
	 * Get a Map of <code>{@link Managable}</code> Jobs from a source 
collection
	 * Will look in all JobFactories
	 * @param source the source collection to use
	 * @return Map a Map of Jobs from this source, an empty Map if there 
are none.
	 */	
	public Map getJobs (String source);
	
	/**
	 * Get a Map of <code>{@link Managable}</code> Jobs from a source 
collection
	 * Will only look in this JobFactory
	 * @param source the source collection to use
	 * @param factoryname the name of the factory
	 * @return Map a Map of Jobs from this source and factory, an empty 
Map if there are none.
	 */	
	public Map getJobs (String source, String factoryname);
	
	/**
	 * Add a <code>{@link JobFactory}</code>
	 * A JobFactory retrieves Jobs from somewhere
	 * @param factoryname the name of this JobFactory
	 * @param jobfactory the JobFactory
	 */	
	public void addJobFactory (String factoryname, JobFactory jobfactory);

	/**
	 * Take a <code>{@link Managable}</code> Job, so no-one else can use it
	 * @param job the Job to take
	 * @param user the User who is taking it
	 */	
	public void take (Managable job, String user);

	/**
	 * Release a <code>{@link Managable}</code> Job, so others can use it
	 * @param job the Job to release
	 */	
	public void release (Managable job);

	/**
	 * is a <code>{@link Managable}</code> Job taken?
	 * @param job the Job to check
	 */	
	public boolean isTaken (Managable job);

	/**
	 * get a <code>{@link Managable}</code> Job that has been taken
	 * @param name the name of the Job to get
	 */	
	public Managable getTaken (String name);

// implemented by a JobFactoryImpl
public interface JobFactory {
	
	/**
	 * get a named <code>{@link Managable}</code> Job from a source 
collection.
	 * @param source the root of the source collection
	 * @param jobname the name of the Job
	 */	
	public Managable getJob (String source, String jobname);

	/**
	 * get all <code>{@link Managable}</code> Jobs from a source 
collection.
	 * @param source the root of the source collection
	 */	
	public Map getJobs (String source);

// implemented by a JobImpl
public interface Managable {
	
	/**
	 * Take on the job.
	 * Make sure no-one else can take it while you have it.
	 * @param userid the Session ID of the User who is taking
	 */	
	public void take (String userid);

	/**
	 * Release the job.
	 * Let other users take it
	 */	
	public void release ();

	/**
	 * Get the name of the job.
	 * @return the name of the Job
	 */	
	public String getName ();

	/**
	 * Set the name of the job.
	 * @param name the name of the Job
	 */	
	public void setName (String name);

	/**
	 * Get the id of the user who has taken the job.
	 * @return the id of the User, or null if not taken
	 */	
	public String getUser ();

	/**
	 * Set the id of the user who has taken the job.
	 * @param the id of the User
	 */	
	public void setUser (String user);

	/**
	 * Has the job been taken?
	 * @return true or false
	 */	
	public boolean isTaken ();
	
	/**
	 * Is the job valid?
	 * @return true or false
	 */	
	public boolean isValid ();
	
	/**
	 * Get the Type of this Job.
	 * @return the type of Job
	 */	
	public String getType ();
}
and finally

// implemented by a JobImpl that needs to be moved
public interface Movable {
	
	/**
	 * move this <code>{@link Managable}</code> Job to another source 
collection
	 * @param destination the root of the source collection to move to
	 */	
	public void moveTo (String destination);	
}

The code is working (but needs to be repackaged and made into Avalon 
Components).

Jobs are automatically 'released' if a user logs or times out.
I use the User's Session ID to manage taken jobs, so the User can have 
multiple logins in multiple windows (a requirement of the client).

What do you think?
Is this generic/useful enough to contribute?

Feedback welcome
And don't tell me, something very similar is already included with 
Cocoon :)

regards Jeremy


Mime
View raw message