Revision 5327

View differences:

branches/MULTITHREADING_DEVELOPMENT/extensions/extWMS/src/com/iver/cit/gvsig/fmap/drivers/wms/FMapWMSDriverFactory.java
9 9
	private static Hashtable drivers = new Hashtable();
10 10
	private FMapWMSDriverFactory() {} // Avoid instantiation
11 11
	
12
	public static FMapWMSDriver getDriverForHost(URL host) {
13
//		FMapWMSDriver drv = (FMapWMSDriver) drivers.get(host);
14
//		if (drv == null) {
15
//			drv = new FMapWMSDriver(host);
16
//			drivers.put(host, drv);
17
//		}
18
//		return drv;
19
		return new FMapWMSDriver(host);
12
//	public static FMapWMSDriver getDriverForHost(URL host) {
13
////		FMapWMSDriver drv = (FMapWMSDriver) drivers.get(host);
14
////		if (drv == null) {
15
////			drv = new FMapWMSDriver(host);
16
////			drivers.put(host, drv);
17
////		}
18
////		return drv;
19
//		return new FMapWMSDriver(host);
20
//	}
21
	
22
	public static ExperimentalAsynchronousFMapWMSDriver getDriverForHost(URL host) {
23
		ExperimentalAsynchronousFMapWMSDriver drv = (ExperimentalAsynchronousFMapWMSDriver) drivers.get(host);
24
		if (drv == null) {
25
			drv = new ExperimentalAsynchronousFMapWMSDriver(host);
26
			drivers.put(host, drv);
27
		}
28
		return drv;
29
//		return new ExperimentalAsynchronousFMapWMSDriver(host);
20 30
	}
21 31
}
branches/MULTITHREADING_DEVELOPMENT/extensions/extWMS/src/com/iver/cit/gvsig/fmap/drivers/wms/ExperimentalAsynchronousFMapWMSDriver.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.1.2.1  2006-05-19 12:50:31  jaume
46
* Revision 1.1.2.2  2006-05-22 12:19:06  jaume
47 47
* *** empty log message ***
48 48
*
49
* Revision 1.1.2.1  2006/05/19 12:50:31  jaume
50
* *** empty log message ***
49 51
*
52
*
50 53
*/
51 54
package com.iver.cit.gvsig.fmap.drivers.wms;
52 55

  
56
import java.io.File;
53 57
import java.net.URL;
58
import java.util.Hashtable;
54 59

  
60
import org.gvsig.remoteClient.exceptions.ServerErrorException;
61
import org.gvsig.remoteClient.exceptions.WMSException;
55 62
import org.gvsig.remoteClient.taskplanning.retrieving.RetrieveEvent;
56 63
import org.gvsig.remoteClient.wms.WMSEventListener;
64
import org.gvsig.remoteClient.wms.WMSStatus;
57 65

  
58 66
public class ExperimentalAsynchronousFMapWMSDriver extends FMapWMSDriver implements Runnable,
59 67
		WMSEventListener {
60

  
68
	Hashtable pool = new Hashtable();
69
	WMSStatus status;
70
	private boolean done;
71
	private final long latency = 200; // milliseconds
72
	private String fileName;
61 73
	protected ExperimentalAsynchronousFMapWMSDriver(URL host) {
62 74
		super(host);
63 75
		// TODO Auto-generated constructor stub
64 76
	}
65 77

  
66 78
	public void run() {
67
		// TODO Auto-generated method stub
68

  
79
		try {
80
			client.getMap(status);
81
			while (!done) {
82
				Thread.sleep(latency);
83
			}
84
		} catch (WMSException e) {
85
			// TODO Auto-generated catch block
86
			e.printStackTrace();
87
		} catch (ServerErrorException e) {
88
			// TODO Auto-generated catch block
89
			e.printStackTrace();
90
		} catch (InterruptedException e) {
91
			// TODO Auto-generated catch block
92
			e.printStackTrace();
93
		}
69 94
	}
70 95

  
71 96
	public void newEvent(int idRequest, RetrieveEvent event) {
72
		// TODO Auto-generated method stub
73

  
97
		if (idRequest == WMSOperations.GET_MAP) {
98
			if (event.getType() == WMSOperations.REQUEST_FINISHED) {
99
				done = true;
100
				fileName = event.getFileName();
101
			} else if (event.getType() == WMSOperations.REQUEST_FAILED) {
102
				System.err.println("something failed");
103
				done = true;
104
			}
105
		} else 
106
			super.newEvent(idRequest, event);			
74 107
	}
108
	
109
	/*
110
	 *  (non-Javadoc)
111
	 * @see com.iver.cit.gvsig.fmap.drivers.WMSDriver#getMap(org.gvsig.remoteClient.wms.WMSStatus)
112
	 */
113
    public void getMap(WMSStatus status) {
114
    	done = false;
115
    	this.status = status;
116
        
117
    }
75 118

  
119
    public File getFile() {
120
    	return new File(fileName);
121
    }
76 122
}
branches/MULTITHREADING_DEVELOPMENT/extensions/extWMS/src/com/iver/cit/gvsig/fmap/drivers/wms/FMapWMSDriver.java
71 71
public class FMapWMSDriver implements WMSEventListener {
72 72
	
73 73
	
74
	private WMSClient client;
74
	protected WMSClient client;
75 75
    private WMSLayerNode fmapRootLayer;
76 76
    private TreeMap layers = new TreeMap();
77 77
    private Vector listeners = new Vector();
branches/MULTITHREADING_DEVELOPMENT/extensions/extWMS/src/com/iver/cit/gvsig/fmap/drivers/wms/WMSOperations.java
43 43
*
44 44
* $Id$
45 45
* $Log$
46
* Revision 1.1.2.1  2006-05-18 22:50:44  jaume
46
* Revision 1.1.2.2  2006-05-22 12:19:06  jaume
47 47
* *** empty log message ***
48 48
*
49
* Revision 1.1.2.1  2006/05/18 22:50:44  jaume
50
* *** empty log message ***
51
*
49 52
* Revision 1.1.2.3  2006/05/18 17:20:42  jaume
50 53
* *** empty log message ***
51 54
*
......
69 72
	public static final int GET_MAP 				= WMSClient.GET_MAP;
70 73
	public static final int GET_FEATURE_INFO 		= WMSClient.GET_FEATURE_INFO;
71 74
	public static final int REQUEST_FINISHED 		= RetrieveEvent.REQUEST_FINISHED;
72
	public static final int REQUEST_CANCELLED 		= RetrieveEvent.REQUEST_CANCELLED;
75
	public static final int REQUEST_CANCELED 		= RetrieveEvent.REQUEST_CANCELED;
73 76
	public static final int REQUEST_FAILED 			= RetrieveEvent.REQUEST_FAILED;
74 77
	public static final int REQUEST_STARTED 		= RetrieveEvent.CONNECTING;
75 78
	public static final int REQUEST_TRANSFERRING	= RetrieveEvent.TRANSFERRING;
branches/MULTITHREADING_DEVELOPMENT/extensions/extWMS/src/com/iver/cit/gvsig/fmap/layers/FLyrWMS.java
85 85
import com.iver.cit.gvsig.fmap.ViewPort;
86 86
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
87 87
import com.iver.cit.gvsig.fmap.drivers.UnsupportedVersionException;
88
import com.iver.cit.gvsig.fmap.drivers.wms.ExperimentalAsynchronousFMapWMSDriver;
88 89
import com.iver.cit.gvsig.fmap.drivers.wms.FMapWMSDriver;
89 90
import com.iver.cit.gvsig.fmap.drivers.wms.FMapWMSDriverFactory;
90 91
import com.iver.cit.gvsig.fmap.drivers.wms.WMSException;
......
142 143
	private Dimension 					fixedSize;
143 144
	private boolean 					queryable = true;
144 145
	private VisualStatusWMS				visualStatus = new VisualStatusWMS();
145
	private DrawingProperties			dProperties = new DrawingProperties();
146 146
	
147 147
	public FLyrWMS(){
148 148
		super();
......
583 583
			wmsStatus.setTransparency(wmsTransparency);
584 584
			wmsStatus.setOnlineResource((String) onlineResources.get("GetMap"));
585 585
			
586
			getDriver().getMap(wmsStatus);
587
			SwingUtilities.invokeAndWait(getDriver());
588
			File f = getDriver().getFile();
589
			String nameWorldFile = f.getPath() + getExtensionWorldFile();
590
			com.iver.andami.Utilities.createTemp(nameWorldFile, this.getDataWorldFile(bBox, fixedSize));
586 591
			
587
			dProperties.bBox = bBox;
588
			dProperties.graphics = g;
589
			dProperties.sz = fixedSize;
590
			dProperties.viewPort = vp;
592
			if(status!=null && firstLoad){
593
				status.applyStatus(this);
594
				firstLoad = false;
595
			}
591 596
			
592
			getDriver().getMap(wmsStatus);
593
//			String nameWorldFile = f.getPath() + getExtensionWorldFile();
594
//			com.iver.andami.Utilities.createTemp(nameWorldFile, this.getDataWorldFile(bBox, fixedSize));
595
//			
596
//			if(status!=null && firstLoad){
597
//				status.applyStatus(this);
598
//				firstLoad = false;
599
//			}
600
//			
601
//			// And finally, obtain the extent intersecting the view and the BBox
602
//			// to draw to.
603
//			Rectangle2D extent = new Rectangle2D.Double();
604
//			Rectangle2D.intersect(vp.getAdjustedExtent(), bBox, extent);
605
//			
606
//			ViewPortData vpData = new ViewPortData(
607
//				vp.getProjection(), new Extent(extent), fixedSize );
608
//			vpData.setMat(vp.getAffineTransform());
609
//
610
//			rasterProcess(g, vpData, f);
597
			// And finally, obtain the extent intersecting the view and the BBox
598
			// to draw to.
599
			Rectangle2D extent = new Rectangle2D.Double();
600
			Rectangle2D.intersect(vp.getAdjustedExtent(), bBox, extent);
611 601
			
602
			ViewPortData vpData = new ViewPortData(
603
				vp.getProjection(), new Extent(extent), fixedSize );
604
			vpData.setMat(vp.getAffineTransform());
605

  
606
			rasterProcess(g, vpData, f);
607
			
612 608
		} catch (ValidationException e) {
613 609
			throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e);
614 610
		} catch (UnsupportedVersionException e) {
615 611
			throw new DriverException(PluginServices.getText(this, "version_conflict"), e);
616 612
		} catch (IOException e) {
617 613
			throw new DriverException(PluginServices.getText(this, "connect_error"), e);
618
		} catch (WMSException e) {
619
            JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage());
620
			this.setVisible(false);
614
		} catch (IllegalStateException e) {
615
			e.printStackTrace();
616
		} catch (InterruptedException e) {
617
			e.printStackTrace();
618
		} catch (InvocationTargetException e) {
619
			e.printStackTrace();
621 620
		}
622 621
		
623 622
		
......
665 664
			wmsStatus.setTransparency(wmsTransparency);
666 665
			wmsStatus.setOnlineResource((String) onlineResources.get("GetMap"));
667 666
			
668
			
669
			dProperties.bBox = bBox;
670
			dProperties.graphics = g;
671
			dProperties.sz = sz;
672
			dProperties.viewPort = vp;
673 667
			getDriver().getMap(wmsStatus);
674
//			String nameWordFile = f.getPath() + getExtensionWorldFile();
675
//			com.iver.andami.Utilities.createTemp(nameWordFile, this.getDataWorldFile(bBox, sz));
676
//			
677
//			if(status!=null && firstLoad){
678
//				status.applyStatus(this);
679
//				firstLoad = false;
680
//			}
681
//			ViewPortData vpData = new ViewPortData(
682
//				vp.getProjection(), new Extent(bBox), sz );
683
//			vpData.setMat(vp.getAffineTransform());
684
//
685
//			rasterProcess(g, vpData, f);
686 668
			
669
			SwingUtilities.invokeAndWait(getDriver());
670
			
671
			File f = getDriver().getFile();
672
			String nameWordFile = f.getPath() + getExtensionWorldFile();
673
			com.iver.andami.Utilities.createTemp(nameWordFile, this.getDataWorldFile(bBox, sz));
674
			
675
			if(status!=null && firstLoad){
676
				status.applyStatus(this);
677
				firstLoad = false;
678
			}
679
			ViewPortData vpData = new ViewPortData(
680
				vp.getProjection(), new Extent(bBox), sz );
681
			vpData.setMat(vp.getAffineTransform());
682

  
683
			rasterProcess(g, vpData, f);
684
					
687 685
		} catch (ValidationException e) {
688 686
			throw new DriverException(PluginServices.getText(this, "unknown_response_format"), e);
689 687
		} catch (UnsupportedVersionException e) {
690 688
			throw new DriverException(PluginServices.getText(this, "version_conflict"), e);
691 689
		} catch (IOException e) {
692 690
			throw new DriverException(PluginServices.getText(this, "connect_error"), e);
693
		} catch (WMSException e) {
694
            JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), e.getMessage());
695
			this.setVisible(false);
691
		} catch (IllegalStateException e) {
692
			e.printStackTrace();
693
		} catch (InterruptedException e) {
694
			e.printStackTrace();
695
		} catch (InvocationTargetException e) {
696
			e.printStackTrace();
697
			System.err.println(e.getCause());
696 698
		}
697 699
		
698 700
	}
......
814 816
		}
815 817
	}
816 818

  
819
	
817 820
	/**
818 821
	 * Devuelve el FMapWMSDriver.
819 822
	 *
......
824 827
	 * @throws UnsupportedVersionException
825 828
	 * @throws IOException
826 829
	 */
827
	private FMapWMSDriver getDriver()
830
	private ExperimentalAsynchronousFMapWMSDriver getDriver()
828 831
		throws IllegalStateException, ValidationException, 
829 832
			UnsupportedVersionException, IOException {
830
		FMapWMSDriver drv = FMapWMSDriverFactory.getDriverForHost(host);
833
		ExperimentalAsynchronousFMapWMSDriver drv = FMapWMSDriverFactory.getDriverForHost(host);
831 834
		drv.addListener(this);
832
		System.err.println("********** capa afegeix el listener");
833 835
//		if (wms == null) {
834 836
//			wms = FMapWMSDriverFactory.getDriverForHost(host); 
835 837
//			System.out.println("********** capa afegeix el listener");
......
839 841
//		return wms;
840 842
		return drv;
841 843
	}
842
	
843
	/**
844
	 * Devuelve el FMapWMSDriver.
845
	 *
846
	 * @return FMapWMSDriver
847
	 *
848
	 * @throws IllegalStateException
849
	 * @throws ValidationException
850
	 * @throws UnsupportedVersionException
851
	 * @throws IOException
852
	 */
853
//	public void setDriver(FMapWMSDriver drv) {
854
//		wms = drv;
855
//	}
856 844

  
857 845
	/**
858 846
	 * Devuelve el URL.
......
1417 1405
			}
1418 1406
		}
1419 1407
	}
1420
	
1421
	private class DrawingProperties {
1422
		Graphics2D graphics;
1423
		Rectangle2D bBox;
1424
		Dimension sz;
1425
		ViewPort viewPort;
1426
	}
1427
	
1408

  
1409
	/* This is unuseful until the layers will hold its own ImageBuffer */
1428 1410
	public void getCapabilities(int eventType, String message) { /* Nothing */ }
1429 1411
	public void getFeatureInfo(int eventType, String message)  { /* Nothing */ }
1430 1412
	public void getMap(int eventType, File mapFile, String message) {
1431
		File f = mapFile;
1413
		/*File f = mapFile;
1432 1414
		Graphics2D g = dProperties.graphics;
1433 1415
		ViewPort vp = dProperties.viewPort;
1434 1416
		Rectangle2D bBox = dProperties.bBox;
......
1455 1437
			vp.getProjection(), new Extent(extent), fixedSize );
1456 1438
		vpData.setMat(vp.getAffineTransform());
1457 1439

  
1458
		rasterProcess(g, vpData, f);
1440
		rasterProcess(g, vpData, f);*/
1459 1441
	}
1460 1442
}
branches/MULTITHREADING_DEVELOPMENT/extensions/extWMS/src/com/iver/cit/gvsig/gui/wizards/WMSWizard.java
116 116
				fillupControls();
117 117
				progress = 3;
118 118
				dlg.setVisible(false);
119
			} else if (eventType == WMSOperations.REQUEST_CANCELLED) {
119
			} else if (eventType == WMSOperations.REQUEST_CANCELED) {
120 120
				progress = 3;
121 121
				dlg.setStatusMessage(PluginServices.getText(this, "cancelled"));
122 122
				dlg.setVisible(false);
branches/MULTITHREADING_DEVELOPMENT/libraries/libRemoteServices/src/org/gvsig/remoteClient/taskplanning/retrieving/RetrieveEvent.java
36 36
	/**
37 37
	 * The request was cancelled by somewho.
38 38
	 */
39
	public static final int REQUEST_CANCELLED = 5;
39
	public static final int REQUEST_CANCELED = 5;
40 40
	
41 41
	/**
42 42
	 * The task is postprocessing the request. For instance, it is closing the connection.
branches/MULTITHREADING_DEVELOPMENT/libraries/libRemoteServices/src/org/gvsig/remoteClient/taskplanning/retrieving/URLRetrieveTask.java
29 29
 */
30 30
public class URLRetrieveTask  implements IRunnableTask {
31 31
	
32
	private boolean running, cancelled;
32
	private boolean running, canceled;
33 33
	private URLRequest request;
34 34
	private InputStream is;
35 35
	
......
39 39
	public URLRetrieveTask(URLRequest request) {
40 40
		this.request = request;
41 41
		request.setWorker(this);
42
		running = cancelled = false;
42
		running = canceled = false;
43 43
	}
44 44
	
45 45

  
46 46
	public void execute() {
47 47
		request.setStatus(RetrieveEvent.NOT_STARTED);
48
		cancelled = false;
48
		canceled = false;
49 49
		running= true;
50 50
		
51 51
		long t = System.currentTimeMillis();
......
66 66
			byte[] buffer = new byte[1024*256];
67 67
			is = url.openStream();
68 68
			request.setStatus(RetrieveEvent.TRANSFERRING);
69
			if (!cancelled) {
69
			if (!canceled) {
70 70
				long readed = 0;
71
				for (int i = is.read(buffer); !cancelled && i>0; i = is.read(buffer)){
71
				for (int i = is.read(buffer); !canceled && i>0; i = is.read(buffer)){
72 72
					dos.write(buffer, 0, i);
73 73
					readed += i;
74 74
				}
......
76 76
				dos.close();
77 77
			}
78 78
			
79
			if (cancelled) {
79
			if (canceled) {
80 80
				// Bad incomplete file, delete it.
81 81
				System.out.println("\n[RemoteClients:URLRetrieveTask] download cancelled ("+url+")\n");
82 82
				f.delete();
83 83
			}
84 84
			
85 85
			running = false;
86
			if (cancelled)
87
				request.setStatus(RetrieveEvent.REQUEST_CANCELLED);
86
			if (canceled)
87
				request.setStatus(RetrieveEvent.REQUEST_CANCELED);
88 88
			else
89 89
				request.setStatus(RetrieveEvent.REQUEST_FINISHED);
90 90
//		} catch (ConnectException e) {
......
102 102
		} catch (IOException e) {
103 103
			e.printStackTrace();
104 104
//			event.setMessage("cant_connect");
105
			if (!cancelled)
105
			if (!canceled)
106 106
				request.setStatus(RetrieveEvent.REQUEST_FAILED);
107 107
		}
108 108
	}
......
118 118
		} catch (IOException e) {
119 119
			e.printStackTrace();
120 120
		}
121
		cancelled = true;
121
		canceled = true;
122 122
	}
123 123

  
124 124
	public boolean isRunning() {
125
		return running && !cancelled;
125
		return running && !canceled;
126 126
	}
127 127

  
128 128

  
branches/MULTITHREADING_DEVELOPMENT/libraries/libRemoteServices/src/org/gvsig/remoteClient/taskplanning/retrieving/RequestManager.java
51 51
				
52 52
				
53 53
				synchronized (this) {
54
					if (request.getStatus() == RetrieveEvent.REQUEST_CANCELLED ||
54
					if (request.getStatus() == RetrieveEvent.REQUEST_CANCELED ||
55 55
						request.getStatus() == RetrieveEvent.REQUEST_FAILED) {
56 56
						// The last requested URL was cancelled or it failed but now it is required again
57 57
						// so, I have to remove it and add again.
branches/MULTITHREADING_DEVELOPMENT/libraries/libRemoteServices/src/org/gvsig/remoteClient/wms/WMSProtocolHandler.java
142 142
					
143 143
	            }	
144 144
				if (theListener!=null) {
145
					System.err.println("comunique al driver que la capa ja ha arribat");
146 145
					theListener.newEvent(WMSEventListener.MAP, event);
147 146
				}
148 147
			}
branches/MULTITHREADING_DEVELOPMENT/libraries/libRemoteServices/test/org/gvsig/remoteClient/taskplanning/retrieving/URLRetrieveTest.java
43 43
 *
44 44
 * $Id$
45 45
 * $Log$
46
 * Revision 1.3.2.1  2006-05-17 09:21:49  jaume
46
 * Revision 1.3.2.2  2006-05-22 12:19:12  jaume
47 47
 * *** empty log message ***
48 48
 *
49
 * Revision 1.3.2.1  2006/05/17 09:21:49  jaume
50
 * *** empty log message ***
51
 *
49 52
 * Revision 1.3  2006/05/16 17:10:27  jaume
50 53
 * *** empty log message ***
51 54
 *
......
82 85
		public void transferEventReceived(RetrieveEvent event) {
83 86
			int e = event.getType();
84 87
			printMessage("listener1", event.getType());
85
			if (e==RetrieveEvent.REQUEST_FINISHED || e == RetrieveEvent.REQUEST_FAILED || e == RetrieveEvent.REQUEST_CANCELLED )
88
			if (e==RetrieveEvent.REQUEST_FINISHED || e == RetrieveEvent.REQUEST_FAILED || e == RetrieveEvent.REQUEST_CANCELED )
86 89
				finished1 = true;
87 90
		}
88 91
	};
......
99 102
		public void transferEventReceived(RetrieveEvent event) {
100 103
			int e = event.getType();
101 104
			printMessage("listener2", event.getType());
102
			if (e==RetrieveEvent.REQUEST_FINISHED || e == RetrieveEvent.REQUEST_FAILED || e==RetrieveEvent.REQUEST_CANCELLED )
105
			if (e==RetrieveEvent.REQUEST_FINISHED || e == RetrieveEvent.REQUEST_FAILED || e==RetrieveEvent.REQUEST_CANCELED )
103 106
				finished2 = true;
104 107

  
105 108
		}
......
112 115
		public void transferEventReceived(RetrieveEvent event) {
113 116
			int e = event.getType();
114 117
			printMessage("listener3", event.getType());
115
			if (e==RetrieveEvent.REQUEST_FINISHED || e == RetrieveEvent.REQUEST_FAILED  || e == RetrieveEvent.REQUEST_CANCELLED )
118
			if (e==RetrieveEvent.REQUEST_FINISHED || e == RetrieveEvent.REQUEST_FAILED  || e == RetrieveEvent.REQUEST_CANCELED )
116 119
				finished3 = true;
117 120

  
118 121
		}
......
125 128
		public void transferEventReceived(RetrieveEvent event) {
126 129
			int e = event.getType();
127 130
			printMessage("listener4", event.getType());
128
			if (e==RetrieveEvent.REQUEST_FINISHED || e == RetrieveEvent.REQUEST_FAILED  || e == RetrieveEvent.REQUEST_CANCELLED )
131
			if (e==RetrieveEvent.REQUEST_FINISHED || e == RetrieveEvent.REQUEST_FAILED  || e == RetrieveEvent.REQUEST_CANCELED )
129 132
				finished4 = true;
130 133

  
131 134
		}
......
259 262
		case RetrieveEvent.TRANSFERRING:
260 263
			System.out.println(who+": transferring");
261 264
			break;
262
		case RetrieveEvent.REQUEST_CANCELLED:
265
		case RetrieveEvent.REQUEST_CANCELED:
263 266
			System.out.println(who+": cancelled");
264 267
			break;
265 268
		case RetrieveEvent.REQUEST_FINISHED:

Also available in: Unified diff