Client.java 2.97 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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();
            }
        }
    }

}