package eu.simstadt.nf4j.async; import java.util.Optional; import eu.simstadt.nf4j.FailedTransmissionException; import eu.simstadt.nf4j.InvalidJobDescriptorException; import eu.simstadt.nf4j.JobStatus; /** * This task sends an export job to your nF server asynchronously within a separate send thread. Once the send * operation has finished all of the jobs status listeners will be notified. You can cancel this task by calling * job.cancel(). * * @author Marcel Bruse */ public class SendExportJobTask implements Runnable { /** The job to be sent to your nF server. */ private AsyncExportJob job; /** * Constructor with the export job to be sent. * * @param job The export job to be sent. */ public SendExportJobTask(AsyncExportJob job) { this.job = job; } /** * This methods performs the actual send operation asynchronously in a separate send thread. * Job status listeners will be notified once the operation finishes or fails. */ @Override public void run() { try { HTTPConnection connector = (HTTPConnection) job.getConnector(); connector.sendAndUpdateExportJob(job); job.poll(); } catch (InvalidJobDescriptorException ex) { signalError("Job cancel because of an invalid job description!"); } catch (FailedTransmissionException ex) { signalError("The job transmission failed. There seams to be a problem with the connector!"); } } /** * This method is superfluous I guess? TODO: Please check and refactor it. */ private void signalError(String errorMessage) { job.setStatus(JobStatus.UNKOWN, Optional.of(errorMessage)); } }