use of org.codelibs.core.misc.Tuple4 in project fess by codelibs.
the class HtmlTagBasedGenerator method createTask.
@Override
public Tuple4<String, String, String, String> createTask(final String path, final Map<String, Object> docMap) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final String thumbnailId = DocumentUtil.getValue(docMap, fessConfig.getIndexFieldId(), String.class);
final String url = DocumentUtil.getValue(docMap, fessConfig.getIndexFieldThumbnail(), String.class);
if (StringUtil.isBlank(url)) {
return null;
}
return new Tuple4<>(getName(), thumbnailId, url, path);
}
use of org.codelibs.core.misc.Tuple4 in project fess by codelibs.
the class BaseThumbnailGenerator method createTask.
@Override
public Tuple4<String, String, String, String> createTask(final String path, final Map<String, Object> docMap) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final String thumbnailId = DocumentUtil.getValue(docMap, fessConfig.getIndexFieldId(), String.class);
final String url = DocumentUtil.getValue(docMap, fessConfig.getIndexFieldUrl(), String.class);
return new Tuple4<>(getName(), thumbnailId, url, path);
}
use of org.codelibs.core.misc.Tuple4 in project fess by codelibs.
the class ThumbnailManager method init.
@PostConstruct
public void init() {
final String thumbnailPath = System.getProperty(FESS_THUMBNAIL_PATH);
if (thumbnailPath != null) {
baseDir = new File(thumbnailPath);
} else {
final String varPath = System.getProperty(FESS_VAR_PATH);
if (varPath != null) {
baseDir = new File(varPath, "thumbnails");
} else {
baseDir = ResourceUtil.getThumbnailPath().toFile();
}
}
if (baseDir.mkdirs()) {
logger.info("Created: " + baseDir.getAbsolutePath());
}
if (!baseDir.isDirectory()) {
throw new FessSystemException("Not found: " + baseDir.getAbsolutePath());
}
if (logger.isDebugEnabled()) {
logger.debug("Thumbnail Directory: " + baseDir.getAbsolutePath());
}
thumbnailTaskQueue = new LinkedBlockingQueue<>(thumbnailTaskQueueSize);
generating = true;
thumbnailQueueThread = new Thread((Runnable) () -> {
final List<Tuple4<String, String, String, String>> taskList = new ArrayList<>();
while (generating) {
try {
final Tuple4<String, String, String, String> task = thumbnailTaskQueue.poll(thumbnailTaskQueueTimeout, TimeUnit.MILLISECONDS);
if (task == null) {
if (!taskList.isEmpty()) {
storeQueue(taskList);
}
} else if (!taskList.contains(task)) {
taskList.add(task);
if (taskList.size() > thumbnailTaskBulkSize) {
storeQueue(taskList);
}
}
} catch (final InterruptedException e) {
logger.debug("Interupted task.", e);
} catch (final Exception e) {
if (generating) {
logger.warn("Failed to generage a thumbnail.", e);
}
}
}
}, "ThumbnailGenerator");
thumbnailQueueThread.start();
}
use of org.codelibs.core.misc.Tuple4 in project fess by codelibs.
the class ThumbnailManager method storeQueue.
protected void storeQueue(final List<Tuple4<String, String, String, String>> taskList) {
final FessConfig fessConfig = ComponentUtil.getFessConfig();
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final String[] targets = fessConfig.getThumbnailGeneratorTargetsAsArray();
final List<ThumbnailQueue> list = new ArrayList<>();
taskList.stream().filter(entity -> entity != null).forEach(task -> {
for (final String target : targets) {
final ThumbnailQueue entity = new ThumbnailQueue();
entity.setGenerator(task.getValue1());
entity.setThumbnailId(task.getValue2());
entity.setUrl(task.getValue3());
entity.setPath(task.getValue4());
entity.setTarget(target);
entity.setCreatedBy(Constants.SYSTEM_USER);
entity.setCreatedTime(systemHelper.getCurrentTimeAsLong());
list.add(entity);
}
});
taskList.clear();
final ThumbnailQueueBhv thumbnailQueueBhv = ComponentUtil.getComponent(ThumbnailQueueBhv.class);
thumbnailQueueBhv.batchInsert(list);
}
Aggregations