Skip to content

Commit

Permalink
Revert TileStore change
Browse files Browse the repository at this point in the history
  • Loading branch information
bchapuis committed Jun 23, 2023
1 parent e14afe6 commit 1f21d00
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void writeMBTiles(MBTilesBenchmark benchmark) throws TileStoreException {
for (int i = 0; i < benchmark.iterations; i++) {
var bytes = new byte[1 << 16];
random.nextBytes(bytes);
mbTilesStore.put(new TileCoord(0, 0, i), ByteBuffer.wrap(bytes));
mbTilesStore.write(new TileCoord(0, 0, i), ByteBuffer.wrap(bytes));
}
}

Expand All @@ -78,12 +78,12 @@ public void writeMBTilesBatch(MBTilesBenchmark benchmark) throws TileStoreExcept
buffers.add(ByteBuffer.wrap(bytes));
if (coords.size() == 100) {
random.nextBytes(bytes);
mbTilesStore.put(coords, buffers);
mbTilesStore.write(coords, buffers);
coords.clear();
buffers.clear();
}
}
mbTilesStore.put(coords, buffers);
mbTilesStore.write(coords, buffers);
coords.clear();
buffers.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public TileCache(TileStore tileStore, CaffeineSpec spec) {

/** {@inheritDoc} */
@Override
public ByteBuffer get(TileCoord tileCoord) throws TileStoreException {
public ByteBuffer read(TileCoord tileCoord) throws TileStoreException {
return cache.get(tileCoord, t -> {
try {
var buffer = tileStore.get(t);
var buffer = tileStore.read(t);
if (buffer == null) {
return null;
} else {
Expand All @@ -68,8 +68,8 @@ public ByteBuffer get(TileCoord tileCoord) throws TileStoreException {

/** {@inheritDoc} */
@Override
public void put(TileCoord tileCoord, ByteBuffer bytes) throws TileStoreException {
tileStore.put(tileCoord, bytes);
public void write(TileCoord tileCoord, ByteBuffer bytes) throws TileStoreException {
tileStore.write(tileCoord, bytes);
cache.invalidate(tileCoord);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public TileChannel(TileStore source, TileStore target, boolean deleteEmptyTiles)
@Override
public void accept(TileCoord tileCoord) {
try {
ByteBuffer blob = source.get(tileCoord);
ByteBuffer blob = source.read(tileCoord);
if (blob != null) {
target.put(tileCoord, blob);
target.write(tileCoord, blob);
} else if (deleteEmptyTiles) {
target.delete(tileCoord);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,48 @@
public interface TileStore {

/**
* Gets the content of a tile.
* Reads the content of a tile.
*
* @param tileCoord the tile coordinate
* @return the content of the tile
* @throws TileStoreException
*/
ByteBuffer get(TileCoord tileCoord) throws TileStoreException;
ByteBuffer read(TileCoord tileCoord) throws TileStoreException;

/**
* Gets the content of several tiles.
* Reads the content of several tiles.
*
* @param tileCoords the tile coordinates
* @return the content of the tiles
* @throws TileStoreException
*/
default List<ByteBuffer> get(List<TileCoord> tileCoords) throws TileStoreException {
default List<ByteBuffer> read(List<TileCoord> tileCoords) throws TileStoreException {
var blobs = new ArrayList<ByteBuffer>(tileCoords.size());
for (var tileCoord : tileCoords) {
blobs.add(get(tileCoord));
blobs.add(read(tileCoord));
}
return blobs;
}

/**
* Puts the content of a tile.
* Writes the content of a tile.
*
* @param tileCoord the tile coordinate
* @param blob the content of the tile
* @throws TileStoreException
*/
void put(TileCoord tileCoord, ByteBuffer blob) throws TileStoreException;
void write(TileCoord tileCoord, ByteBuffer blob) throws TileStoreException;

/**
* Puts the content of several tiles.
* Writes the content of several tiles.
*
* @param tileCoords the tile coordinates
* @param blobs the content of the tiles
* @throws TileStoreException
*/
default void put(List<TileCoord> tileCoords, List<ByteBuffer> blobs) throws TileStoreException {
default void write(List<TileCoord> tileCoords, List<ByteBuffer> blobs) throws TileStoreException {
for (int i = 0; i < tileCoords.size(); i++) {
put(tileCoords.get(i), blobs.get(i));
write(tileCoords.get(i), blobs.get(i));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public FileTileStore(Path path) {

/** {@inheritDoc} */
@Override
public ByteBuffer get(TileCoord tileCoord) throws TileStoreException {
public ByteBuffer read(TileCoord tileCoord) throws TileStoreException {
try {
return ByteBuffer.wrap(Files.readAllBytes(resolve(tileCoord)));
} catch (IOException e) {
Expand All @@ -48,7 +48,7 @@ public ByteBuffer get(TileCoord tileCoord) throws TileStoreException {

/** {@inheritDoc} */
@Override
public void put(TileCoord tileCoord, ByteBuffer blob) throws TileStoreException {
public void write(TileCoord tileCoord, ByteBuffer blob) throws TileStoreException {
try {
var file = resolve(tileCoord);
Files.createDirectories(file.getParent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public MBTilesStore(DataSource dataSource) {

/** {@inheritDoc} */
@Override
public ByteBuffer get(TileCoord tileCoord) throws TileStoreException {
public ByteBuffer read(TileCoord tileCoord) throws TileStoreException {
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(SELECT_TILE)) {
statement.setInt(1, tileCoord.z());
Expand All @@ -93,7 +93,7 @@ public ByteBuffer get(TileCoord tileCoord) throws TileStoreException {

/** {@inheritDoc} */
@Override
public void put(TileCoord tileCoord, ByteBuffer blob) throws TileStoreException {
public void write(TileCoord tileCoord, ByteBuffer blob) throws TileStoreException {
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(INSERT_TILE)) {
statement.setInt(1, tileCoord.z());
Expand All @@ -108,7 +108,7 @@ public void put(TileCoord tileCoord, ByteBuffer blob) throws TileStoreException

/** {@inheritDoc} */
@Override
public void put(List<TileCoord> tileCoords, List<ByteBuffer> blobs) throws TileStoreException {
public void write(List<TileCoord> tileCoords, List<ByteBuffer> blobs) throws TileStoreException {
try (Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(INSERT_TILE)) {
for (int i = 0; i < tileCoords.size(); i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public PostgresTileStore(DataSource datasource, Tileset tileset) {

/** {@inheritDoc} */
@Override
public ByteBuffer get(TileCoord tileCoord) throws TileStoreException {
public ByteBuffer read(TileCoord tileCoord) throws TileStoreException {
try (Connection connection = datasource.getConnection();
Statement statement = connection.createStatement();
ByteArrayOutputStream data = new ByteArrayOutputStream()) {
Expand Down Expand Up @@ -240,7 +240,7 @@ protected String tileEnvelope(TileCoord tileCoord) {

/** This operation is not supported. */
@Override
public void put(TileCoord tileCoord, ByteBuffer blob) {
public void write(TileCoord tileCoord, ByteBuffer blob) {
throw new UnsupportedOperationException("The postgis tile store is read only");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ void readWriteDeleteTile() throws Exception {
ByteBuffer blob = ByteBuffer.wrap("tile_content".getBytes());

// Write data
tileStore.put(tileCoord, blob);
tileStore.write(tileCoord, blob);

// Read the data
ByteBuffer inputStream = tileStore.get(tileCoord);
ByteBuffer inputStream = tileStore.read(tileCoord);
assertArrayEquals(blob.array(), inputStream.array());

// Delete the data
tileStore.delete(tileCoord);
assertThrows(TileStoreException.class, () -> tileStore.get(tileCoord));
assertThrows(TileStoreException.class, () -> tileStore.read(tileCoord));
}

public abstract TileStore createTileStore() throws Exception;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public Response getTile(String tileSetId, String tileMatrix, Integer tileRow, In
int y = tileCol;
TileCoord tileCoord = new TileCoord(x, y, z);
try {
ByteBuffer blob = tileStore.get(tileCoord);
ByteBuffer blob = tileStore.read(tileCoord);
if (blob != null) {
return Response.status(200) // lgtm [java/xss]
.header(ACCESS_CONTROL_ALLOW_ORIGIN, "*")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Response getTile(@PathParam("z") int z, @PathParam("x") int x, @PathParam
TileCoord tileCoord = new TileCoord(x, y, z);
try {
TileStore tileStore = tileStoreSupplier.get();
ByteBuffer blob = tileStore.get(tileCoord);
ByteBuffer blob = tileStore.read(tileCoord);
if (blob != null) {
byte[] bytes = new byte[blob.remaining()];
blob.get(bytes);
Expand Down

0 comments on commit 1f21d00

Please sign in to comment.