I've implemented a similar requirement as follows. On the server we present a simple facade with an interface like this:
Code:
interface LongRunningJobManager {
JobKey start(JobDefinition jobDefinition);
JobStatus getStatus(JobKey jobKey);
void cancel(JobKey jobKey);
}
behind this facade is a thread pool for running the jobs and a map from JobKey to status+executing thread of each active job. On the client we adapt this (convenient for remoting but not for the client) interface to the following:
Code:
interface LongRunningJob {
JobDefinition getDefinition();
void start();
void cancel();
void addJobEventListener(JobEventListener listener);
}
interface JobEventListener {
void jobStarted(LongRunningJob job);
void jobCompletedSomeWork(LongRunningJob job, JobStatus status);
void jobCancelled(LongRunningJob job);
void jobFinished(LongRunningJob job, JobResult result);
}
The implementation of LongRunningJob simply pools the server interface at some useful interval (to cut down on remote invocations we use an adaptive interval that is based on the rate the job is progressing) and if you're using Swing remember to fire the JobEventListener methods in the event dispatch thread!
HTH
Ollie