public abstract class AbstractJPPFJobStream extends JobListenerAdapter implements Iterable<JPPFJob>, Iterator<JPPFJob>, AutoCloseable
A common usage pattern is as follows:
// concurrency level
int concurrency = 4;
try (JPPFClient client = new JPPFClient();
AbstractJPPFJobStream jobStream = new MyJobStreamImplementation(concurrency)) {
jobStream.forEach(job -> client.submitJob(job));
jobsStream.awaitEndOfStream();
}| Constructor and Description |
|---|
AbstractJPPFJobStream(int concurrencyLimit)
Initialize this job provider.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
awaitEndOfStream()
Wait until this job stream has finished procesing all of its jobs.
|
abstract void |
close()
Close this stream and release the underlying resources it uses.
|
protected abstract JPPFJob |
createNextJob()
Create the next job in the stream, along with its tasks.
|
int |
getExecutedJobCount()
Get the number of completed jobs.
|
int |
getJobCount()
Get the number of submitted jobs.
|
int |
getTaskCount()
Get the number of submitted task.
|
abstract boolean |
hasNext()
Determine whether there is at least one more job in the stream.
|
boolean |
hasPendingJob()
Determine whether any job is still being executed.
|
Iterator<JPPFJob> |
iterator() |
void |
jobEnded(JobEvent event)
This implementation of
JobListener.jobEnded(JobEvent) decreases the counter of running jobs,
notifies all threads waiting in next() and finally processes the results asynchronously. |
JPPFJob |
next()
Get the next job in the stream.
|
protected abstract void |
processResults(JPPFJob job)
Callback invoked when a job is complete.
|
void |
remove()
This operation is not supported and results in an
UnsupportedOperationException being thrown. |
jobDispatched, jobReturned, jobStartedclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorforEachRemainingpublic AbstractJPPFJobStream(int concurrencyLimit)
concurrencyLimit - the maximum number of jobs submitted concurrently.public abstract boolean hasNext()
public JPPFJob next() throws NoSuchElementException
next in interface Iterator<JPPFJob>JPPFJob object.NoSuchElementException - if this stream has no more job to provide.protected abstract JPPFJob createNextJob()
This method is called each time next() is invoked, including implicitely in enhanced for loops.
public void remove()
throws UnsupportedOperationException
UnsupportedOperationException being thrown.remove in interface Iterator<JPPFJob>UnsupportedOperationException - every time this method is called.public void jobEnded(JobEvent event)
JobListener.jobEnded(JobEvent) decreases the counter of running jobs,
notifies all threads waiting in next() and finally processes the results asynchronously.jobEnded in interface JobListenerjobEnded in class JobListenerAdapterevent - encaspulates the source of the event.protected abstract void processResults(JPPFJob job)
job - the job whose results to process.public abstract void close()
throws Exception
close in interface AutoCloseableException - if any error occurs.public boolean hasPendingJob()
true if at least one job was submitted and has not yet completed, false otherwise.public int getJobCount()
public int getExecutedJobCount()
public int getTaskCount()
public boolean awaitEndOfStream()
true if the end of stream has been reached, false if the current thread was interrupted before the end of stream occurred.Copyright © 2005-2019 JPPF Team.