package eu.simstadt.nf4j.async; import java.io.File; import eu.simstadt.nf4j.FailedTransmissionException; import eu.simstadt.nf4j.InvalidJobDescriptorException; import eu.simstadt.nf4j.JobStatus; /** * This is a class for development and test purposes. It is not needed for production. You may want to delete it. * * @author Marcel Bruse */ public class Client implements JobStatusListener { public AsyncExportJob job; public static void main(String[] args) { Client client = new Client(); client.processJob(); } public void processJob() { // Describe the export job ExportJobDescription description= ExportJobDescription.getDefaultDescriptor(); description.setInitiator("2758"); description.setAccount("Bruse"); description.setProduct("WU3"); description.setJobnumber("Bruse_0815"); // Set at least one unit. You could also define a region polygon. Unit unit = Unit.getDefaultUnit(); unit.setValue("821"); description.addUnit(unit); // Set at least one layer Layer layer = Layer.getDefaultLayer(); layer.setProduct("WU3"); layer.setName("GML"); description.addLayer(layer); // Create a new export job with the job description and a HTTP connection job = new AsyncExportJob(description, new HTTPConnection("193.196.136.164")); // Register a job status listener job.addJobStatusListener(this); try { // Send the export job to the nF server in a separate thread job.send(); } catch (FailedTransmissionException ex) { // There was a problem with your connection or the job has been sent twice ex.printStackTrace(); } catch (InvalidJobDescriptorException ex) { // The export job description is invalid ex.printStackTrace(); } } // This client is a job status listener and will get notified upon job status changes @Override public void jobStatusChanged(JobStatusEvent event) { JobStatus status = (JobStatus) event.getSource(); System.out.println(status); if (status == JobStatus.FINISHED) { try { // Start an asynchronous download of the resulting CityGML file job.downloadResult(); } catch (FailedTransmissionException ex) { // Only finished jobs can download files ex.printStackTrace(); } } else if (status == JobStatus.DOWNLOAD) { try { // Obtain the CityGML file handle File file = job.getResult(); System.out.println("CityGML at " + file.getAbsolutePath()); } catch (FailedTransmissionException ex) { // Download may have failed ex.printStackTrace(); } } } }