final long START_TIME = System.currentTimeMillis();
final String layerName = tl.getName();
log.info(Thread.currentThread().getName() + " begins seeding layer : " + layerName);
TileRange tr = trIter.getTileRange();
checkInterrupted();
// TODO move to TileRange object, or distinguish between thread and task
super.tilesTotal = tileCount(tr);
final int metaTilingFactorX = tl.getMetaTilingFactors()[0];
final int metaTilingFactorY = tl.getMetaTilingFactors()[1];
final boolean tryCache = !reseed;
checkInterrupted();
long[] gridLoc = trIter.nextMetaGridLocation(new long[3]);
long seedCalls = 0;
while (gridLoc != null && this.terminate == false) {
checkInterrupted();
Map<String, String> fullParameters = tr.getParameters();
ConveyorTile tile = new ConveyorTile(storageBroker, layerName, tr.getGridSetId(), gridLoc,
tr.getMimeType(), fullParameters, null, null);
for (int fetchAttempt = 0; fetchAttempt <= tileFailureRetryCount; fetchAttempt++) {
try {
checkInterrupted();
tl.seedTile(tile, tryCache);
break;// success, let it go
} catch (Exception e) {
// if GWC_SEED_RETRY_COUNT was not set then none of the settings have effect, in
// order to keep backwards compatibility with the old behaviour
if (tileFailureRetryCount == 0) {
if (e instanceof GeoWebCacheException) {
throw (GeoWebCacheException) e;
}
throw new GeoWebCacheException(e);
}
long sharedFailureCount = sharedFailureCounter.incrementAndGet();
if (sharedFailureCount >= totalFailuresBeforeAborting) {
log.info("Aborting seed thread " + Thread.currentThread().getName()
+ ". Error count reached configured maximum of "
+ totalFailuresBeforeAborting);
super.state = GWCTask.STATE.DEAD;
return;
}
String logMsg = "Seed failed at " + tile.toString() + " after "
+ (fetchAttempt + 1) + " of " + (tileFailureRetryCount + 1)
+ " attempts.";
if (fetchAttempt < tileFailureRetryCount) {
log.debug(logMsg);
if (tileFailureRetryWaitTime > 0) {
log.trace("Waiting " + tileFailureRetryWaitTime
+ " before trying again");
Thread.sleep(tileFailureRetryCount);
}
} else {
log.info(logMsg
+ " Skipping and continuing with next tile. Original error: "
+ e.getMessage());
}
}
}
if (log.isTraceEnabled()) {
log.trace(Thread.currentThread().getName() + " seeded " + Arrays.toString(gridLoc));
}
// final long totalTilesCompleted = trIter.getTilesProcessed();
// note: computing the # of tiles processed by this thread instead of by the whole group
// also reduces thread contention as the trIter methods are synchronized and profiler
// shows 16 threads block on synchronization about 40% the time
final long tilesCompletedByThisThread = seedCalls * metaTilingFactorX
* metaTilingFactorY;
updateStatusInfo(tl, tilesCompletedByThisThread, START_TIME);
checkInterrupted();
seedCalls++;
gridLoc = trIter.nextMetaGridLocation(gridLoc);
}
if (this.terminate) {
log.info("Job on " + Thread.currentThread().getName() + " was terminated after "
+ this.tilesDone + " tiles");
} else {
log.info(Thread.currentThread().getName() + " completed (re)seeding layer " + layerName
+ " after " + this.tilesDone + " tiles and " + this.timeSpent + " seconds.");
}
checkInterrupted();
if (threadOffset == 0 && doFilterUpdate) {
runFilterUpdates(tr.getGridSetId());
}
super.state = GWCTask.STATE.DONE;
}