All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.clickzetta.platform.client.pool.RowQueuePool Maven / Gradle / Ivy

There is a newer version: 2.0.0
Show newest version
package com.clickzetta.platform.client.pool;

import com.clickzetta.platform.client.api.Row;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class RowQueuePool implements RowPool {

  private int currentSize;
  private int poolSize;

  private BlockingQueue queue;

  private Loader loader;

  public RowQueuePool(int poolSize) {
    this.poolSize = poolSize;
    this.queue = new LinkedBlockingQueue<>(poolSize);
  }

  @Override
  public void initLoader(Loader loader) {
    this.loader = loader;
  }

  @Override
  public Row acquireRow() {
    if (this.queue.isEmpty() && currentSize < poolSize) {
      currentSize++;
      Row row = this.loader.load();
      row.getWriteOperation().setPoolStatus();
      return row;
    } else {
      return this.queue.poll();
    }
  }

  @Override
  public void releaseRow(Row row) {
    if (row.getWriteOperation().getPoolStatus()) {
      this.queue.offer(row);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy