Main.java 1.93 KB
Newer Older
bruse's avatar
bruse committed
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
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 Main implements JobStatusListener {

	public AsyncExportJob job;
	
	public void doit() {
		ExportJobDescription jobDescriptor = ExportJobDescription.getDefaultDescriptor();
		jobDescriptor.setProduct("WU3");
		
		Unit unit = Unit.getDefaultUnit();
		unit.setValue("821");
		jobDescriptor.addUnit(unit);
		
		Layer layer = Layer.getDefaultLayer();
		layer.setProduct("WU3");
		layer.setName("GML");
		jobDescriptor.addLayer(layer);
		
		job = new AsyncExportJob(jobDescriptor, new HTTPConnection("193.196.136.164"));
		job.addJobStatusListener(this);
		
		try {
			job.send();
		} catch (FailedTransmissionException ex) {
			ex.printStackTrace();
		} catch (InvalidJobDescriptorException ex) {
			ex.printStackTrace();
		}
		
		System.out.println("Main thread is back again");
	}
	
	public static void main(String[] args) {		
		Main m = new Main();
		m.doit();
	}

	@Override
	public void jobStatusChanged(JobStatusEvent event) {
		System.out.println(event.getSource() + ": " + event.getMessage().orElse("(no message)"));
		if (event.getSource() == JobStatus.FINISHED) {
			try {
				job.downloadResult();
			} catch (FailedTransmissionException ex) {
				// TODO Auto-generated catch block
				ex.printStackTrace();
			}
		} else if (event.getSource() == JobStatus.DOWNLOAD) {
			try {
				File f = job.getResult();
				System.out.println("File can be read for job "+ event.getJob().getId() +": " + f.getAbsolutePath());
			} catch (FailedTransmissionException ex) {
				// TODO Auto-generated catch block
				ex.printStackTrace();
			}
		}
	}

}