Statistics
| Revision:

gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / src / main / java / org / gvsig / raster / cache / tile / impl / DefaultTileCacheManager.java @ 2424

History | View | Annotate | Download (4.32 KB)

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.impl;
23

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

    
27
import org.gvsig.raster.cache.tile.Tile;
28
import org.gvsig.raster.cache.tile.TileCache;
29
import org.gvsig.raster.cache.tile.TileCacheLibrary;
30
import org.gvsig.raster.cache.tile.TileCacheManager;
31
import org.gvsig.raster.cache.tile.disk.ITileFileSystemStrategy;
32
import org.gvsig.raster.cache.tile.impl.disk.FlatXFileSystemStrategy;
33
import org.gvsig.raster.cache.tile.impl.pool.ThreadPoolImpl;
34
import org.gvsig.raster.cache.tile.impl.provider.DefaultCacheStruct;
35
import org.gvsig.raster.cache.tile.pool.ThreadPool;
36
import org.gvsig.raster.cache.tile.provider.CacheStruct;
37

    
38
/**
39
 * Default {@link RasterManager} implementation.
40
 * 
41
 * @author Nacho Brodin (nachobrodin@gmail.com)
42
 * @version $Id$
43
 */
44
public class DefaultTileCacheManager implements TileCacheManager {
45
        private static DefaultTileCacheManager internalInstance  = new DefaultTileCacheManager();
46
        private TileCache                      tileCacheInstance = null;
47
        public static int                      TILE_TIME_OUT     = 20000;
48
           
49
        /**
50
         * Gets an instance of this object for internal use.
51
         * @return DefaultRasterManager
52
         */
53
        public static DefaultTileCacheManager getInstance() {
54
                return internalInstance;
55
        }
56

    
57
        public TileCache getTileCache(String baseDir) {
58
                if(tileCacheInstance == null)
59
                        tileCacheInstance = new TileCacheImpl(baseDir);
60
                return tileCacheInstance;
61
        }
62

    
63
        public Tile createTile(int level, int col, int row) {
64
                return new TileImpl(level, col, row);
65
        }
66
        
67
        public Tile createTile(int wPx, int hPx, int row, int col, Point2D ul, Point2D lr) {
68
                return new TileImpl(wPx, hPx, row, col, ul, lr);
69
        }
70
        
71
        public CacheStruct createCacheStructure(int typeOfCoords, 
72
                    int levels, 
73
                    Rectangle2D layerExtent, 
74
                    double pixelSize,
75
                    int tilePxWidth,
76
                    int tilePxHeight,
77
                    String uri,
78
                    String layerName,
79
                    String strategy,
80
                    String baseDir,
81
                    String fileSuffix,
82
                    String epsg,
83
                    long size) {
84
                return new DefaultCacheStruct(typeOfCoords, 
85
                                levels, 
86
                                layerExtent, 
87
                                pixelSize, 
88
                                tilePxWidth, 
89
                                tilePxHeight,
90
                                uri,
91
                                layerName, 
92
                                createStrategy(strategy),
93
                                baseDir,
94
                                fileSuffix,
95
                                epsg,
96
                                size );
97
        }
98
        
99
        public CacheStruct createCacheStructure(int typeOfCoords, 
100
                    int levels, 
101
                    Rectangle2D layerExtent, 
102
                    double pixelSize,
103
                    int tilePxWidth,
104
                    int tilePxHeight,
105
                    String layerName,
106
                    String strategy,
107
                    String baseDir,
108
                    String fileSuffix,
109
                    String epsg,
110
                    long size) {
111
                return new DefaultCacheStruct(typeOfCoords, 
112
                                levels, 
113
                                layerExtent, 
114
                                pixelSize, 
115
                                tilePxWidth, 
116
                                tilePxHeight,
117
                                layerName,
118
                                layerName, 
119
                                createStrategy(strategy),
120
                                baseDir,
121
                                fileSuffix,
122
                                epsg,
123
                                size );
124
        }
125
        
126
        /**
127
         * Creates a strategy object
128
         * @param strategy
129
         * @return
130
         */
131
        public ITileFileSystemStrategy createStrategy(String strategy) {
132
                ITileFileSystemStrategy strat = null;
133
                if(strategy == null || strategy.compareTo(TileCacheLibrary.FLATX_STRUCT) == 0)
134
                        strat = new FlatXFileSystemStrategy();
135
                return strat;
136
        }
137

    
138
        public ThreadPool createThreadPool(boolean priorityActive) {
139
                return new ThreadPoolImpl(priorityActive);
140
        }
141

    
142
        public ThreadPool createThreadPool(boolean priorityActive, int nThreads) {
143
                return new ThreadPoolImpl(priorityActive, nThreads);
144
        }
145
        
146
        public void setTileTimeOut(int ms) {
147
                TILE_TIME_OUT = ms;
148
        }
149
        
150
        public int getTileTimeOut() {
151
                return TILE_TIME_OUT;
152
        }
153
        
154
}