Revision 3222

View differences:

org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.1/org.gvsig.raster.cache.lib.api/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3
	<modelVersion>4.0.0</modelVersion>
4
	<artifactId>org.gvsig.raster.cache.lib.api</artifactId>
5
	<packaging>jar</packaging>
6
	<name>org.gvsig.raster.cache.lib.api</name>
7
	<parent>
8
		<groupId>org.gvsig</groupId>
9
		<artifactId>org.gvsig.raster.cache</artifactId>
10
		<version>2.2.1</version>
11
	</parent>
12
	<dependencies>
13
		<dependency>
14
            <groupId>org.gvsig</groupId>
15
            <artifactId>org.gvsig.tools.lib</artifactId>
16
            <type>test-jar</type>
17
            <scope>test</scope>
18
        </dependency>
19
        <dependency>
20
            <groupId>org.gvsig</groupId>
21
            <artifactId>org.gvsig.compat.api</artifactId>
22
            <scope>compile</scope>
23
        </dependency>
24
        <dependency>
25
            <groupId>org.gvsig</groupId>
26
            <artifactId>org.gvsig.compat.se</artifactId>
27
            <scope>compile</scope>
28
        </dependency>
29
     </dependencies>
30
	<build>
31
		<plugins>
32
			<plugin>
33
				<groupId>org.apache.maven.plugins</groupId>
34
				<artifactId>maven-jar-plugin</artifactId>
35
				<configuration>
36
				</configuration>
37
				<executions>
38
				<!--
39
				Generates a jar file only with the test classes
40
				-->
41
					<execution>
42
						<goals>
43
							<goal>test-jar</goal>
44
						</goals>
45
					</execution>
46
				</executions>
47
			</plugin>
48
		</plugins>
49
	</build>
50
</project>
0 51

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.1/org.gvsig.raster.cache.lib.api/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.raster.cache.tile.TileCacheLibrary
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.1/org.gvsig.raster.cache.lib.api/src/main/java/org/gvsig/raster/cache/tile/TileCacheManager.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.cache.tile;
23

  
24
import java.awt.geom.Point2D;
25
import java.awt.geom.Rectangle2D;
26

  
27
import org.gvsig.raster.cache.tile.pool.ThreadPool;
28
import org.gvsig.raster.cache.tile.provider.CacheStruct;
29

  
30

  
31

  
32
/**
33
 * This class is responsible of the management of the library's business logic.
34
 * It is the library's main entry point, and provides all the services to manage
35
 * {@link TileCacheService}s.
36
 * 
37
 * @author Nacho Brodin (nachobrodin@gmail.com)
38
 * @version $Id$
39
 */
40
public interface TileCacheManager {
41
	/**
42
	 * Builds a new entry point for a tile cache. The parameter is an identifier for a 
43
	 * tile cache structured implemented inside of this library
44
	 * @param baseDir
45
	 * @return
46
	 */
47
	public TileCache getTileCache(String baseDir);
48
	
49
	/**
50
	 * Creates a new tile structure
51
	 * @param level
52
	 * @param col
53
	 *        Tile column
54
	 * @param row
55
	 *        Tile row
56
	 * @return
57
	 */
58
	public Tile createTile(int level, int col, int row);
59
	
60
	/**
61
	 * Creates a new tile structure
62
	 * @param wPx
63
	 *        Width in pixels
64
	 * @param hPx
65
	 *        Height in pixels
66
	 * @param row
67
	 *        Tile row
68
	 * @param col
69
	 *        Tile column
70
	 * @param ul
71
	 *        Upper left coordinate
72
	 * @param lr
73
	 *        Lower roght coordinate 
74
	 * @return
75
	 */
76
	public Tile createTile(int wPx, int hPx, int row, int col, Point2D ul, Point2D lr);
77
	
78
	/**
79
	 * Builds a standard cache structure 
80
	 * @param typeOfCoords Constant defined in CacheStruct interface
81
	 * @param levels Number of levels
82
	 * @param layerExtent Bounding box of the layer
83
	 * @param pixelSize Pixel size of the layer
84
	 * @param tilePxWidth Width in pixels of a tile
85
	 * @param tilePxHeight Height in pixels of a tile
86
	 * @param uri server URL
87
	 * @param layerName Layer name or identifier
88
	 * @param strategy Strategy to store tiles in disk
89
	 * @param baseDir path to this layer
90
	 * @param fileSuffix File suffix
91
	 * @param epsg 
92
	 * @return
93
	 */
94
	public CacheStruct createCacheStructure(int typeOfCoords, 
95
    		int levels, 
96
    		Rectangle2D layerExtent, 
97
    		double pixelSize,
98
    		int tilePxWidth,
99
    		int tilePxHeight,
100
    		String uri,
101
    		String layerName,
102
    		String strategy,
103
    		String baseDir,
104
    		String fileSuffix,
105
    		String epsg,
106
    		long fileSize);
107
	
108
	/**
109
	 * Builds a standard cache structure for local files
110
	 * @param typeOfCoords Constant defined in CacheStruct interface
111
	 * @param levels Number of levels
112
	 * @param layerExtent Bounding box of the layer
113
	 * @param pixelSize Pixel size of the layer
114
	 * @param tilePxWidth Width in pixels of a tile
115
	 * @param tilePxHeight Height in pixels of a tile
116
	 * @param layerName Layer name or identifier
117
	 * @param strategy Strategy to store tiles in disk
118
	 * @param baseDir path to this layer
119
	 * @param fileSuffix File suffix
120
	 * @param epsg 
121
	 * @return
122
	 */
123
	public CacheStruct createCacheStructure(int typeOfCoords, 
124
    		int levels, 
125
    		Rectangle2D layerExtent, 
126
    		double pixelSize,
127
    		int tilePxWidth,
128
    		int tilePxHeight,
129
    		String layerName,
130
    		String strategy,
131
    		String baseDir,
132
    		String fileSuffix,
133
    		String epsg,
134
    		long fileSize);
135
	
136
	/**
137
	 * Builds a new thread pool. This pool will use five threads by default
138
	 * @return
139
	 */
140
	public ThreadPool createThreadPool(boolean priorityActive);
141
	
142
	/**
143
	 * Builds a new thread pool selecting the number of threads
144
	 * @return
145
	 */
146
	public ThreadPool createThreadPool(boolean priorityActive, int nThreads);
147
	
148
	/**
149
	 * Sets the time out in milliseconds
150
	 * @param ms
151
	 */
152
	public void setTileTimeOut(int ms);
153
	
154
	/**
155
	 * Gets the time out in milliseconds
156
	 * @return
157
	 */
158
	public int getTileTimeOut();
159
}
0 160

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.1/org.gvsig.raster.cache.lib.api/src/main/java/org/gvsig/raster/cache/tile/layer/TiledLayer.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.cache.tile.layer;
23

  
24
import java.util.List;
25

  
26
import org.gvsig.raster.cache.tile.Tile;
27
import org.gvsig.raster.cache.tile.exception.TileGettingException;
28
import org.gvsig.raster.cache.tile.provider.TileListener;
29
import org.gvsig.tools.task.TaskStatus;
30

  
31
/**
32
 * API interface for a cached layer
33
 *
34
 * @author Nacho Brodin (nachobrodin@gmail.com)
35
 */
36
public interface TiledLayer {
37
	
38
	/**
39
	 * Gets a tile
40
	 * @param tile
41
	 * @return
42
	 * @throws TileGettingException 
43
	 */
44
	public Tile getTile(Tile tile) throws TileGettingException;
45
	
46
	/**
47
	 * Gets a list of tiles
48
	 * @param tiles
49
	 * @param listener
50
	 * @throws TileGettingException 
51
	 */
52
	public void getTiles(List<Tile> tiles, TileListener listener, TaskStatus status) throws TileGettingException;
53
	
54
	/**
55
	 * Gets the base directory for this layer. This function builds an unique identifier
56
	 * for a layer with a limited length.
57
	 * @return
58
	 */
59
	public String getBaseLayerDirectory();
60
	
61
	/**
62
	 * Returns the ID of this layer. 
63
	 * The ID is the name of the directory where the tiles are stored.
64
	 * @return
65
	 */
66
	public String getID();
67
	
68
	/**
69
	 * Deletes the files of this layer 
70
	 * @return Size of information that was deleted
71
	 */
72
	public long delete();
73
}
0 74

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.1/org.gvsig.raster.cache.lib.api/src/main/java/org/gvsig/raster/cache/tile/layer/package.html
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head>
5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
<title>org.gvsig.raster.cache.tile.layer package documentation</title>
7
</head>
8
<body>
9

  
10
	<p>Tile layer</p>
11
	
12
	<p>
13
	</p>
14

  
15
</body>
16
</html>
0 17

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.1/org.gvsig.raster.cache.lib.api/src/main/java/org/gvsig/raster/cache/tile/Tile.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.cache.tile;
23

  
24
import java.awt.geom.Point2D;
25
import java.awt.geom.Rectangle2D;
26
import java.io.File;
27

  
28
import org.gvsig.raster.cache.tile.pool.AtomicTask;
29
import org.gvsig.raster.cache.tile.pool.TilePipe;
30
import org.gvsig.raster.cache.tile.provider.Downloader;
31
import org.gvsig.compat.net.ICancellable;
32

  
33
/**
34
 * Tile structure for requests
35
 *
36
 * @author Nacho Brodin (nachobrodin@gmail.com)
37
 */
38
public interface Tile extends AtomicTask {
39
	
40
	/**
41
	 * Gets the Variable that this tile belong to.This is useful when the source 
42
	 * is a multidimensional container. If it is not then this variable will have
43
	 * a default value. 
44
	 * @return
45
	 */
46
	public String getVariable();
47
	
48
	/**
49
	 * Gets the Z that this tile belong to. This is useful when the source 
50
	 * is a multidimensional container. If it is not then this variable will have
51
	 * a 0 value. 
52
	 * @return
53
	 */
54
	public String getZ();
55
	
56
	/**
57
	 * Gets the time instant that this tile belong to.This is useful when the source 
58
	 * is a multidimensional container. If it is not then this variable will have
59
	 * a 0 value. 
60
	 * @return
61
	 */
62
	public String getTimeInstant();
63
	
64
	/**
65
	 * Sets the Variable that this tile belong to.This is useful when the source 
66
	 * is a multidimensional container. If it is not then this variable will have
67
	 * a default value. 
68
	 * @return
69
	 */
70
	public void setVariable(String var);
71
	
72
	/**
73
	 * Sets the Z that this tile belong to. This is useful when the source 
74
	 * is a multidimensional container. If it is not then this variable will have
75
	 * a 0 value. 
76
	 * @return
77
	 */
78
	public void setZ(String z);
79
	
80
	/**
81
	 * Sets the time instant that this tile belong to.This is useful when the source 
82
	 * is a multidimensional container. If it is not then this variable will have
83
	 * a 0 value. 
84
	 * @return
85
	 */
86
	public void setTimeInstant(String t);
87
	
88
	/**
89
	 * Gets the column of this tile
90
	 * @return
91
	 */
92
	public int getCol();
93
	
94
	/**
95
	 * Gets the row of this tile
96
	 * @return
97
	 */
98
	public int getRow();
99
	
100
	/**
101
	 * Gets the resolution level of this tile
102
	 * @return
103
	 */
104
	public int getLevel();
105
	
106
	/**
107
	 * Sets the column of this tile in its level
108
	 * @param col
109
	 */
110
	public void setCol(int col);
111
	
112
	/**
113
	 * Sets the row of this tile in its level
114
	 * @param col
115
	 */
116
	public void setRow(int row);
117
	
118
	/**
119
	 * Sets the level of resolution of this tile
120
	 * @param col
121
	 */
122
	public void setLevel(int level);
123
	
124
	/**
125
	 * Gets the coordinates in pixels of this tile inside the layer.
126
	 * This function is only for the real level. 
127
	 * @return
128
	 */
129
	public Rectangle2D getCoordsPx();
130
	
131
	/**
132
	 * Sets the coordinates ins pixels of this tile inside the layer.
133
	 * This function is only for the real level.
134
	 * @param r
135
	 */
136
	public void setCoordsPx(Rectangle2D r);
137
	
138
	/**
139
	 * Gets the width in pixels of this tile
140
	 * @return
141
	 */
142
	public int getWidthPx();
143

  
144
	/**
145
	 * Sets the width in pixels of this tile
146
	 * @param widthPx
147
	 */
148
	public void setWidthPx(int widthPx);
149

  
150
	/**
151
	 * Gets the height in pixels of this tile
152
	 * @return
153
	 */
154
	public int getHeightPx();
155

  
156
	/**
157
	 * Sets the height in pixels of this tile
158
	 * @param heightPx
159
	 */
160
	public void setHeightPx(int heightPx);
161
	
162
	/**
163
	 * Gets the bounding box
164
	 * @return
165
	 */
166
	public Rectangle2D getExtent();
167

  
168
	/**
169
	 * Gets the upper left coordinate of this tile
170
	 * @return
171
	 */
172
	public Point2D getUl();
173

  
174
	/**
175
	 * Sets the upper left coordinate of this tile
176
	 * @return
177
	 */
178
	public void setUl(Point2D ul);
179

  
180
	/**
181
	 * Gets the lower right coordinate of this tile
182
	 * @return
183
	 */
184
	public Point2D getLr();
185

  
186
	/**
187
	 * Sets the lower right coordinate of this tile
188
	 * @return
189
	 */
190
	public void setLr(Point2D lr);
191

  
192
	/**
193
	 * Gets the file associated to this tile
194
	 * @return
195
	 */
196
	public File getFile();
197

  
198
	/**
199
	 * Sets the file associated to this tile
200
	 * @param file
201
	 */
202
	public void setFile(File file);
203
	
204
	/**
205
	 * Gets an unique identifier to this tile
206
	 * @return
207
	 */
208
	public String getId();
209
	
210
	/**
211
	 * Gets the Downloader parameters
212
	 * @return
213
	 */
214
	public Object getDownloaderParams(String key);
215

  
216
	/**
217
	 * Sets the Downloader parameters
218
	 * @param downloaderParams
219
	 */
220
	public void setDownloaderParams(String key, Object downloaderParams);
221
	
222
	/**
223
	 * Sets the data associated to this tile. In the most cases
224
	 * will be only one element in the array of objects
225
	 * @param data
226
	 */
227
	public void setData(Object[] data);
228
	
229
	/**
230
	 * Gets the data associated to this tile. In the most cases
231
	 * will be only one element in the array of objects
232
	 * @return
233
	 */
234
	public Object[] getData();
235
	
236
	/**
237
	 * Returns true if the buffer data is loaded
238
	 * @return
239
	 */
240
	public boolean dataIsLoaded();	
241
	
242
	/**
243
	 * Sets this flag to true if the data is corrupt
244
	 * @param corrupt
245
	 */
246
	public void setCorrupt(boolean corrupt);
247
	
248
	/**
249
	 * Returns true if the downloaded tile is corrupt, so this can't be sent to the client 
250
	 * @return
251
	 */
252
	public boolean isCorrupt();
253
	
254
	/**
255
	 * Sets the pipe of tiles
256
	 * @param sharedPipe
257
	 */
258
	public void setSharedPipe(TilePipe sharedPipe);
259
	
260
	/**
261
	 * Sets the downloader for this tile
262
	 * @param downloader
263
	 */
264
	public void setDownloader(Downloader downloader);
265
	
266
	/**
267
	 * Gets the image that represent a tile while is downloading
268
	 * @return RGB image and an alpha band
269
	 * @deprecated
270
	 */
271
	public Object[] getDownloadingImage();
272
	
273
	/**
274
	 * Gets the image that represent a crash tile
275
	 * @return RGB image and an alpha band
276
	 * @deprecated
277
	 */
278
	public Object[] getCrashImage();
279
	
280
	/**
281
	 * Gets the image that represent a tile while is downloading
282
	 * @return ARGB image 
283
	 */
284
	public Object getDownloadingARGB();
285
	
286
	/**
287
	 * Gets the image that represent a crash tile
288
	 * @return ARGB image
289
	 */
290
	public Object getCrashARGB();
291
	
292
	/**
293
	 * Returns true if downloading has been canceled. This is useful when a tile is taking
294
	 * a lot of time. The task which will throw this action could cancel the process.
295
	 * @return
296
	 */
297
	public ICancellable getCancelled();
298
}
0 299

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.1/org.gvsig.raster.cache.lib.api/src/main/java/org/gvsig/raster/cache/tile/exception/TileGettingException.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.cache.tile.exception;
23

  
24
/**
25
 * This exception is thrown when the pool of threads fails
26
 *
27
 * @author Nacho Brodin (nachobrodin@gmail.com)
28
 */
29
public class TileGettingException extends Exception {
30
	private static final long serialVersionUID = 1L;
31
	
32
	String message;
33

  
34
	public TileGettingException() {
35
		super();
36
	}
37

  
38
	/**
39
	 * Crea TileGettingException.
40
	 *
41
	 * @param message
42
	 */
43
	public TileGettingException(String message) {
44
        super();
45
        this.message = message;
46
	}
47

  
48
	/**
49
	 * Crea TileGettingException.
50
	 *
51
	 * @param message
52
	 * @param cause
53
	 */
54
	public TileGettingException(String message, Throwable cause) {
55
		super(format(message, 200), cause);
56
	}
57

  
58
	/**
59
	  * Crea TileGettingException.
60
	 *
61
	 * @param cause
62
	 */
63
	public TileGettingException(Throwable cause) {
64
		super(cause);
65
	}
66
    
67
    /**
68
     * Cuts the message text to force its lines to be shorter or equal to 
69
     * lineLength.
70
     * @param message, the message.
71
     * @param lineLength, the max line length in number of characters.
72
     * @return the formated message.
73
     */
74
    private static String format(String message, int lineLength){
75
        if (message.length() <= lineLength) return message;
76
        String[] lines = message.split("\n");
77
        String theMessage = "";
78
        for (int i = 0; i < lines.length; i++) {
79
            String line = lines[i].trim();
80
            if (line.length()<lineLength)
81
                theMessage += line+"\n";
82
            else {
83
                String[] chunks = line.split(" ");
84
                String newLine = "";
85
                for (int j = 0; j < chunks.length; j++) {
86
                    int currentLength = newLine.length();
87
                    chunks[j] = chunks[j].trim();
88
                    if (chunks[j].length()==0)
89
                        continue;
90
                    if ((currentLength + chunks[j].length() + " ".length()) <= lineLength)
91
                        newLine += chunks[j] + " ";
92
                    else {
93
                        newLine += "\n"+chunks[j]+" ";
94
                        theMessage += newLine;
95
                        newLine = "";
96
                    }
97
                }
98
                
99
            }
100
        }
101
        return theMessage;
102
    }
103
}
0 104

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.1/org.gvsig.raster.cache.lib.api/src/main/java/org/gvsig/raster/cache/tile/exception/package.html
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head>
5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
<title>org.gvsig.raster.cache.tile.exception package documentation</title>
7
</head>
8
<body>
9

  
10
	<p>Exceptions which are thrown by a wrong access to tile structures</p>
11
	
12
	<p>
13
	</p>
14

  
15
</body>
16
</html>
0 17

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.1/org.gvsig.raster.cache.lib.api/src/main/java/org/gvsig/raster/cache/tile/exception/ThreadPoolException.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.cache.tile.exception;
23

  
24
/**
25
 * This exception is thrown when the pool of threads fails
26
 *
27
 * @author Nacho Brodin (nachobrodin@gmail.com)
28
 */
29
public class ThreadPoolException extends Exception {
30
	private static final long serialVersionUID = 1L;
31
	
32
	String message;
33

  
34
	public ThreadPoolException() {
35
		super();
36
	}
37

  
38
	/**
39
	 * Crea ThreadPoolException.
40
	 *
41
	 * @param message
42
	 */
43
	public ThreadPoolException(String message) {
44
        super();
45
        this.message = message;
46
	}
47

  
48
	/**
49
	 * Crea ThreadPoolException.
50
	 *
51
	 * @param message
52
	 * @param cause
53
	 */
54
	public ThreadPoolException(String message, Throwable cause) {
55
		super(format(message, 200), cause);
56
	}
57

  
58
	/**
59
	  * Crea ThreadPoolException.
60
	 *
61
	 * @param cause
62
	 */
63
	public ThreadPoolException(Throwable cause) {
64
		super(cause);
65
	}
66
    
67
    /**
68
     * Cuts the message text to force its lines to be shorter or equal to 
69
     * lineLength.
70
     * @param message, the message.
71
     * @param lineLength, the max line length in number of characters.
72
     * @return the formated message.
73
     */
74
    private static String format(String message, int lineLength){
75
        if (message.length() <= lineLength) return message;
76
        String[] lines = message.split("\n");
77
        String theMessage = "";
78
        for (int i = 0; i < lines.length; i++) {
79
            String line = lines[i].trim();
80
            if (line.length()<lineLength)
81
                theMessage += line+"\n";
82
            else {
83
                String[] chunks = line.split(" ");
84
                String newLine = "";
85
                for (int j = 0; j < chunks.length; j++) {
86
                    int currentLength = newLine.length();
87
                    chunks[j] = chunks[j].trim();
88
                    if (chunks[j].length()==0)
89
                        continue;
90
                    if ((currentLength + chunks[j].length() + " ".length()) <= lineLength)
91
                        newLine += chunks[j] + " ";
92
                    else {
93
                        newLine += "\n"+chunks[j]+" ";
94
                        theMessage += newLine;
95
                        newLine = "";
96
                    }
97
                }
98
                
99
            }
100
        }
101
        return theMessage;
102
    }
103
}
0 104

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.1/org.gvsig.raster.cache.lib.api/src/main/java/org/gvsig/raster/cache/tile/exception/TileBuildException.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.cache.tile.exception;
23

  
24
/**
25
 * This exception is thrown when the pool of threads fails
26
 *
27
 * @author Nacho Brodin (nachobrodin@gmail.com)
28
 */
29
public class TileBuildException extends Exception {
30
	private static final long serialVersionUID = 1L;
31
	
32
	String message;
33

  
34
	public TileBuildException() {
35
		super();
36
	}
37

  
38
	/**
39
	 * Crea TileGettingException.
40
	 *
41
	 * @param message
42
	 */
43
	public TileBuildException(String message) {
44
        super();
45
        this.message = message;
46
	}
47

  
48
	/**
49
	 * Crea TileGettingException.
50
	 *
51
	 * @param message
52
	 * @param cause
53
	 */
54
	public TileBuildException(String message, Throwable cause) {
55
		super(format(message, 200), cause);
56
	}
57

  
58
	/**
59
	  * Crea TileGettingException.
60
	 *
61
	 * @param cause
62
	 */
63
	public TileBuildException(Throwable cause) {
64
		super(cause);
65
	}
66
    
67
    /**
68
     * Cuts the message text to force its lines to be shorter or equal to 
69
     * lineLength.
70
     * @param message, the message.
71
     * @param lineLength, the max line length in number of characters.
72
     * @return the formated message.
73
     */
74
    private static String format(String message, int lineLength){
75
        if (message.length() <= lineLength) return message;
76
        String[] lines = message.split("\n");
77
        String theMessage = "";
78
        for (int i = 0; i < lines.length; i++) {
79
            String line = lines[i].trim();
80
            if (line.length()<lineLength)
81
                theMessage += line+"\n";
82
            else {
83
                String[] chunks = line.split(" ");
84
                String newLine = "";
85
                for (int j = 0; j < chunks.length; j++) {
86
                    int currentLength = newLine.length();
87
                    chunks[j] = chunks[j].trim();
88
                    if (chunks[j].length()==0)
89
                        continue;
90
                    if ((currentLength + chunks[j].length() + " ".length()) <= lineLength)
91
                        newLine += chunks[j] + " ";
92
                    else {
93
                        newLine += "\n"+chunks[j]+" ";
94
                        theMessage += newLine;
95
                        newLine = "";
96
                    }
97
                }
98
                
99
            }
100
        }
101
        return theMessage;
102
    }
103
}
0 104

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.1/org.gvsig.raster.cache.lib.api/src/main/java/org/gvsig/raster/cache/tile/package.html
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head>
5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
<title>org.gvsig.raster.cache.tile package documentation</title>
7
</head>
8
<body>
9

  
10
	<p>Base classes to get tiles from raster layers</p>
11
	
12
	<p>
13
	</p>
14

  
15
</body>
16
</html>
0 17

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.1/org.gvsig.raster.cache.lib.api/src/main/java/org/gvsig/raster/cache/tile/TileCache.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.cache.tile;
23

  
24
import org.gvsig.raster.cache.tile.layer.TiledLayer;
25
import org.gvsig.raster.cache.tile.provider.TileServer;
26

  
27
/**
28
 * Main API interface for the tile cache
29
 *
30
 * @author Nacho Brodin (nachobrodin@gmail.com)
31
 */
32
public interface TileCache {
33
	/**
34
	 * Builds a new layer
35
	 * @param provider
36
	 * @param diskStructure
37
	 * @return
38
	 */
39
	public TiledLayer createLayer(TileServer provider, String diskStructure);
40
	
41
	/**
42
	 * Removes a layer from list.
43
	 * @param layer
44
	 */
45
	public void removeLayer(TiledLayer layer);
46
	
47
	/**
48
	 * Returns true if the size of data in disk is greater than the MAX_CACHE_SIZE
49
	 * @return
50
	 */
51
	public boolean isFullDiskCache();
52
	
53
	/**
54
	 * Updates the string with the base directory
55
	 * @param dir
56
	 */
57
	public void updateBaseDirectory(String dir);
58
	
59
	/**
60
	 * Gets the configuration directory
61
	 * @return
62
	 */
63
	public String getConfigurationDirectory();
64
}
0 65

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.1/org.gvsig.raster.cache.lib.api/src/main/java/org/gvsig/raster/cache/tile/TileCacheLocator.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.cache.tile;
23

  
24
import org.gvsig.tools.locator.BaseLocator;
25
import org.gvsig.tools.locator.Locator;
26
import org.gvsig.tools.locator.LocatorException;
27

  
28
/**
29
 * This locator is the entry point for the Raster library, providing
30
 * access to all Raster services through the {@link TileCacheManager}
31
 * .
32
 * 
33
 * @author gvSIG team
34
 * @version $Id$
35
 */
36
public class TileCacheLocator extends BaseLocator {
37
    public static final String             MANAGER_NAME            = "TileCache.manager";
38
    public static final String             MANAGER_DESCRIPTION     = "TileCache Manager";
39
    private static final String            LOCATOR_NAME            = "TileCache.locator";
40
    private static final TileCacheLocator  INSTANCE                = new TileCacheLocator();
41

  
42
    /**
43
     * Return the singleton instance.
44
     * 
45
     * @return the singleton instance
46
     */
47
    public static TileCacheLocator getInstance() {
48
        return INSTANCE;
49
    }
50

  
51
    /**
52
     * Return the Locator's name.
53
     * 
54
     * @return a String with the Locator's name
55
     */
56
    public final String getLocatorName() {
57
        return LOCATOR_NAME;
58
    }
59

  
60
    /**
61
     * Return a reference to the RasterManager.
62
     * 
63
     * @return a reference to the RasterManager
64
     * @throws LocatorException
65
     *             if there is no access to the class or the class cannot be
66
     *             instantiated
67
     * @see Locator#get(String)
68
     */
69
    public static TileCacheManager getManager() throws LocatorException {
70
        return (TileCacheManager) getInstance().get(MANAGER_NAME);
71
    }
72

  
73
    /**
74
     * Registers the Class implementing the RasterManager interface.
75
     * 
76
     * @param clazz
77
     *            implementing the RasterManager interface
78
     */
79
    public static void registerManager(
80
        Class<? extends TileCacheManager> clazz) {
81
        getInstance().register(MANAGER_NAME, MANAGER_DESCRIPTION, clazz);
82
    }
83

  
84
}
0 85

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.1/org.gvsig.raster.cache.lib.api/src/main/java/org/gvsig/raster/cache/tile/TileCacheLibrary.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.cache.tile;
23

  
24
import org.gvsig.tools.library.AbstractLibrary;
25
import org.gvsig.tools.library.LibraryException;
26
import org.gvsig.tools.locator.ReferenceNotRegisteredException;
27

  
28

  
29
/**
30
 * 
31
 * @author Nacho Brodin (nachobrodin@gmail.com)
32
 */
33
public class TileCacheLibrary extends AbstractLibrary {
34
	public static int                 DEFAULT_LEVELS       = 25; 
35
	public static int                 DEFAULT_TILEWIDTH    = 256;
36
	public static int                 DEFAULT_TILEHEIGHT   = 256;
37
	public static int                 ALTERNATIVE_TILESIZE = 1024;
38
	public static String              DEFAULT_STRUCTURE    = "FLATX";
39
	
40
	//One directory X dimension. The name of each tile is the Y coordinate. 
41
	public static String              FLATX_STRUCT         = "FLATX";
42
	public static String              QUADKEY_STRUCT       = "QUADKEY";
43
	
44
	public static int                 MAX_CACHE_SIZE       = 5000;
45
	
46
	public TileCacheLibrary() {
47
        registerAsAPI(TileCacheLibrary.class);
48
	}
49
	
50
	@Override
51
    protected void doInitialize() throws LibraryException {
52
    }
53

  
54
    @Override
55
    protected void doPostInitialize() throws LibraryException {
56
        TileCacheManager manager = TileCacheLocator.getManager();
57
        if (manager == null) {
58
            throw new ReferenceNotRegisteredException(
59
                TileCacheLocator.MANAGER_NAME, TileCacheLocator
60
                    .getInstance());
61
        }
62
    }
63
}
0 64

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.1/org.gvsig.raster.cache.lib.api/src/main/java/org/gvsig/raster/cache/tile/pool/TilePipe.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.cache.tile.pool;
23

  
24

  
25
/**
26
 * This class manages transactions between the producer and the consumer. The
27
 * producer download tiles from a server and the consumer is a tile provider
28
 * which will return downloaded tiles.
29
 *
30
 * @author Nacho Brodin (nachobrodin@gmail.com)
31
 */
32
public interface TilePipe {
33
	
34
	/**
35
	 * Sets a tile in the pipe
36
	 * @param tile
37
	 */
38
	public void setAtomicTask(AtomicTask tile);
39

  
40
	/**
41
	 * Gets a tile from the pipe
42
	 * @return
43
	 */
44
	public AtomicTask getAtomicTask();
45
	
46
	/**
47
	 * Returns the number of elements in the queue
48
	 * @return
49
	 */
50
	public int getSize();
51
	
52
	/**
53
	 * Cleans the queue
54
	 */
55
	public void clear();
56
}
0 57

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.1/org.gvsig.raster.cache.lib.api/src/main/java/org/gvsig/raster/cache/tile/pool/package.html
1
<?xml version="1.0" encoding="UTF-8" ?>
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head>
5
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
<title>org.gvsig.raster.cache.tile.pool package documentation</title>
7
</head>
8
<body>
9

  
10
	<p>API to build a pool of threads of tasks</p>
11
	
12
	<p>
13
	</p>
14

  
15
</body>
16
</html>
0 17

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.1/org.gvsig.raster.cache.lib.api/src/main/java/org/gvsig/raster/cache/tile/pool/AtomicTask.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.cache.tile.pool;
23

  
24
/**
25
 * Task with priorities
26
 *
27
 * @author Nacho Brodin (nachobrodin@gmail.com)
28
 */
29
public interface AtomicTask extends Runnable, Comparable<AtomicTask> {
30
	/**
31
	 * Gets the priority of this task
32
	 * @return
33
	 */
34
	public int getPriority();
35
	
36
	/**
37
	 * Sets the priority of this task
38
	 * @param priority
39
	 */
40
	public void setPriority(int priority);
41
	
42
	/**
43
	 * Cancels this current task
44
	 */
45
	public void cancelTask();
46
}
0 47

  
org.gvsig.raster.cache/tags/org.gvsig.raster.cache-2.2.1/org.gvsig.raster.cache.lib.api/src/main/java/org/gvsig/raster/cache/tile/pool/ThreadPool.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.raster.cache.tile.pool;
23

  
24
import java.util.LinkedList;
25

  
26

  
27
/**
28
 * Pool of threads. This class contains a list of tasks and a limited number
29
 * of threads to execute them. When a thread is free will execute the next task 
30
 * in the list. 
31
 *
32
 * @author Nacho Brodin (nachobrodin@gmail.com)
33
 */
34
public interface ThreadPool {
35
	/**
36
	 * Stops all threads in the list and sets the list to null
37
	 */
38
	public void destroyPool();
39

  
40
	/**
41
	 * Adds a new task to the list
42
	 * @param task
43
	 */
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff