@Override public ReferenceCountingResourceHolder<T> take() { checkInitialized(); try { return wrapObject(takeObject()); } catch (InterruptedException e) { throw new RuntimeException(e); } }
@Nullable private ReferenceCountingResourceHolder<T> wrapObject(T theObject) { return theObject == null ? null : new ReferenceCountingResourceHolder<>( theObject, () -> offer(theObject) ); }
@Override @Nullable public ReferenceCountingResourceHolder<T> take(final long timeoutMs) { Preconditions.checkArgument(timeoutMs >= 0, "timeoutMs must be a non-negative value, but was [%s]", timeoutMs); checkInitialized(); try { return wrapObject(timeoutMs > 0 ? pollObject(timeoutMs) : pollObject()); } catch (InterruptedException e) { throw new RuntimeException(e); } }
@Override public List<ReferenceCountingResourceHolder<T>> takeBatch(final int elementNum, final long timeoutMs) { Preconditions.checkArgument(timeoutMs >= 0, "timeoutMs must be a non-negative value, but was [%s]", timeoutMs); checkInitialized(); try { final List<T> objects = timeoutMs > 0 ? pollObjects(elementNum, timeoutMs) : pollObjects(elementNum); return objects.stream().map(this::wrapObject).collect(Collectors.toList()); } catch (InterruptedException e) { throw new RuntimeException(e); } }
@Override public List<ReferenceCountingResourceHolder<T>> takeBatch(final int elementNum) { checkInitialized(); try { return takeObjects(elementNum).stream().map(this::wrapObject).collect(Collectors.toList()); } catch (InterruptedException e) { throw new RuntimeException(e); } }
@Provides @LazySingleton @Merging public BlockingPool<ByteBuffer> getMergeBufferPool(DruidProcessingConfig config) { verifyDirectMemory(config); return new DefaultBlockingPool<>( new OffheapBufferGenerator("result merging", config.intermediateComputeSizeBytes()), config.getNumMergeBuffers() ); }
@Override public List<ReferenceCountingResourceHolder<T>> takeBatch(final int elementNum) { checkInitialized(); try { return takeObjects(elementNum).stream().map(this::wrapObject).collect(Collectors.toList()); } catch (InterruptedException e) { throw new RuntimeException(e); } }
@Override public List<ReferenceCountingResourceHolder<T>> takeBatch(final int elementNum, final long timeoutMs) { Preconditions.checkArgument(timeoutMs >= 0, "timeoutMs must be a non-negative value, but was [%s]", timeoutMs); checkInitialized(); try { final List<T> objects = timeoutMs > 0 ? pollObjects(elementNum, timeoutMs) : pollObjects(elementNum); return objects.stream().map(this::wrapObject).collect(Collectors.toList()); } catch (InterruptedException e) { throw new RuntimeException(e); } }
@Provides @LazySingleton @Merging public BlockingPool<ByteBuffer> getMergeBufferPool(DruidProcessingConfig config) { verifyDirectMemory(config); return new DefaultBlockingPool<>( new OffheapBufferGenerator("result merging", config.intermediateComputeSizeBytes()), config.getNumMergeBuffers() ); }
@Override public ReferenceCountingResourceHolder<T> take() { checkInitialized(); try { return wrapObject(takeObject()); } catch (InterruptedException e) { throw new RuntimeException(e); } }
@Override @Nullable public ReferenceCountingResourceHolder<T> take(final long timeoutMs) { Preconditions.checkArgument(timeoutMs >= 0, "timeoutMs must be a non-negative value, but was [%s]", timeoutMs); checkInitialized(); try { return wrapObject(timeoutMs > 0 ? pollObject(timeoutMs) : pollObject()); } catch (InterruptedException e) { throw new RuntimeException(e); } }
@Nullable private ReferenceCountingResourceHolder<T> wrapObject(T theObject) { return theObject == null ? null : new ReferenceCountingResourceHolder<>( theObject, () -> offer(theObject) ); }