Recycler(BufferedItemSourcePool pool, ResizePolicy resizePolicy) { super(pool.getName() + "-Recycler"); this.pool = pool; this.resizePolicy = resizePolicy; }
Recycler(BufferedItemSourcePool pool, ResizePolicy resizePolicy) { super(pool.getName() + "-Recycler"); this.pool = pool; this.resizePolicy = resizePolicy; }
public String formattedMetrics(ByteBufAllocatorMetric allocatorMetric) { int capacity = allocatorMetric != null ? 384: 96; // roughly with or without allocator metrics StringBuilder sb = new StringBuilder(capacity) .append('{') .append(" poolName: ").append(getName()) .append(", initialPoolSize: ").append(getInitialSize()) .append(", totalPoolSize: ").append(getTotalSize()) .append(", availablePoolSize: ").append(getAvailableSize()); if (allocatorMetric != null) { sb.append(", allocatorMetric: ").append(allocatorMetric); } return sb.append('}').toString(); }
public String formattedMetrics(ByteBufAllocatorMetric allocatorMetric) { int capacity = allocatorMetric != null ? 384: 96; // roughly with or without allocator metrics StringBuilder sb = new StringBuilder(capacity) .append('{') .append(" poolName: ").append(getName()) .append(", initialPoolSize: ").append(getInitialSize()) .append(", totalPoolSize: ").append(getTotalSize()) .append(", availablePoolSize: ").append(getAvailableSize()); if (allocatorMetric != null) { sb.append(", allocatorMetric: ").append(allocatorMetric); } return sb.append('}').toString(); }
private boolean resize(Consumer<Boolean> callback) throws PoolResourceException { boolean resized = false; try { LOGGER.info("Pool [{}] attempting to resize using policy [{}]", getName(), resizePolicy.getClass().getName()); resized = resizePolicy.increase(this); if (!resized) { // TODO: remove when limited resize policy is ready // throw to resurface issues throw new PoolResourceException(String.format("Unable to resize. Creation of %s was unsuccessful", ItemSource.class.getSimpleName())); } } finally { callback.accept(resized); } return resized; }
private boolean resize(Consumer<Boolean> callback) throws PoolResourceException { boolean resized = false; try { LOGGER.info("Pool [{}] attempting to resize using policy [{}]", getName(), resizePolicy.getClass().getName()); resized = resizePolicy.increase(this); if (!resized) { // TODO: remove when limited resize policy is ready // throw to resurface issues throw new PoolResourceException(String.format("Unable to resize. Creation of %s was unsuccessful", ItemSource.class.getSimpleName())); } } finally { callback.accept(resized); } return resized; }
/** * Creates pooled {@link BufferedItemSource} instances * * @param delta number of elements to be pooled */ @Override public final void incrementPoolSize(int delta) { long start = System.currentTimeMillis(); for (int i = 0; i < delta; i++) { incrementPoolSize(); } LOGGER.info("Pool [{}] {} pooled elements added. Total pooled elements: {}. Took: {}ms", getName(), delta, getTotalSize(), (System.currentTimeMillis() - start)); }
/** * Creates pooled {@link BufferedItemSource} instances * * @param delta number of elements to be pooled */ @Override public final void incrementPoolSize(int delta) { long start = System.currentTimeMillis(); for (int i = 0; i < delta; i++) { incrementPoolSize(); } LOGGER.info("Pool [{}] {} pooled elements added. Total pooled elements: {}. Took: {}ms", getName(), delta, getTotalSize(), (System.currentTimeMillis() - start)); }
/** * Schedules a task that prints pool statistics * * @param monitorTaskInterval interval between two snapshots */ void startMonitorTask(long monitorTaskInterval) { executor.scheduleAtFixedRate(new MetricPrinter(getName(), byteBufAllocator.metric(), this.new PoolMetrics()), 1000L, monitorTaskInterval, TimeUnit.MILLISECONDS ); }
/** * Schedules a task that prints pool statistics * * @param monitorTaskInterval interval between two snapshots */ void startMonitorTask(long monitorTaskInterval) { executor.scheduleAtFixedRate(new MetricPrinter(getName(), byteBufAllocator.metric(), this.new PoolMetrics()), 1000L, monitorTaskInterval, TimeUnit.MILLISECONDS ); }