feat(renderer): Add getOrAcquire method and enhance get method in RendererWorkingSet implementation

This commit is contained in:
extio-de
2025-12-25 12:49:53 +01:00
parent 478dbc3f3c
commit 5d80ba3f9e
4 changed files with 70 additions and 5 deletions

View File

@@ -13,6 +13,10 @@ public interface RendererWorkingSet {
void put(String producerId, List<RenderingBo> work);
RenderingBo get(String producerId, String id);
<T extends RenderingBo> T get(String producerId, String id, Class<T> type);
<T extends RenderingBo> T getOrAcquire(String producerId, String id, Class<T> type);
Map<String, RenderingBo> getUncommittedWork(String producerId);

View File

@@ -54,6 +54,24 @@ public class RendererWorkingSetImpl implements RendererWorkingSet {
return this.getWorkingSetByProducer(producerId).next().get(id);
}
@Override
public <T extends RenderingBo> T get(final String producerId, final String id, final Class<T> type) {
final RenderingBo bo = this.getWorkingSetByProducer(producerId).next().get(id);
if (bo == null) {
return null;
}
return type.cast(bo);
}
@Override
public <T extends RenderingBo> T getOrAcquire(final String producerId, final String id, final Class<T> type) {
final var bo = this.get(producerId, id, type);
if (bo != null) {
return bo;
}
return this.rendererBoPool.acquire(id, type);
}
@Override
public Map<String, RenderingBo> commit(final String producerId, final boolean clone) {
final AtomicReference<Map<String, RenderingBo>> previousWork = new AtomicReference<>();
@@ -88,7 +106,7 @@ public class RendererWorkingSetImpl implements RendererWorkingSet {
this.releaseBoClasses(rendererWork.next());
}
}
@Override
public void getLiveSet(final List<RenderingBo> combinedLiveSet, final Predicate<String> filter) {
this.workingSet.forEach((producer, rendererWork) -> {
@@ -106,7 +124,7 @@ public class RendererWorkingSetImpl implements RendererWorkingSet {
if (work == null || work.isEmpty()) {
return;
}
final var releasedBoClasses = this.obtainSetFromPool();
for (final RenderingBo renderingBO : work.values()) {
if (releasedBoClasses.add(renderingBO.getClass())) {
@@ -118,7 +136,7 @@ public class RendererWorkingSetImpl implements RendererWorkingSet {
this.returnMapToPool(work);
this.returnSetToPool(releasedBoClasses);
}
private Map<String, RenderingBo> obtainMapFromPool() {
var map = this.mapsPool.poll();
if (map == null) {