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

io.vertx.redis.client.impl.PooledRedisConnection Maven / Gradle / Ivy

There is a newer version: 5.0.0.CR3
Show newest version
package io.vertx.redis.client.impl;

import io.vertx.codegen.annotations.Nullable;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.net.impl.pool.Lease;
import io.vertx.core.spi.metrics.PoolMetrics;
import io.vertx.redis.client.RedisConnection;
import io.vertx.redis.client.Request;
import io.vertx.redis.client.Response;

import java.util.List;

/**
 * A pooled Redis connection
 */
public class PooledRedisConnection implements RedisConnection {

  private final Lease lease;
  private final RedisConnectionInternal connection;
  private final PoolMetrics metrics;
  private final Object metric;

  public PooledRedisConnection(Lease lease, PoolMetrics poolMetrics, Object metric) {
    this.lease = lease;
    this.connection = lease.get();
    this.metrics = poolMetrics;
    this.metric = metric;
  }

  public RedisConnection actual() {
    return connection;
  }

  @Override
  public RedisConnection exceptionHandler(Handler handler) {
    connection.exceptionHandler(handler);
    return this;
  }

  @Override
  public RedisConnection handler(Handler handler) {
    connection.handler(handler);
    return this;
  }

  @Override
  public RedisConnection pause() {
    connection.pause();
    return this;
  }

  @Override
  public RedisConnection resume() {
    connection.resume();
    return this;
  }

  @Override
  public RedisConnection fetch(long amount) {
    connection.fetch(amount);
    return this;
  }

  @Override
  public RedisConnection endHandler(@Nullable Handler endHandler) {
    connection.endHandler(endHandler);
    return this;
  }

  @Override
  public Future<@Nullable Response> send(Request command) {
    return connection.send(command);
  }

  @Override
  public Future> batch(List commands) {
    return connection.batch(commands);
  }

  @Override
  public Future close() {
    if (connection.reset()) {
      lease.recycle();
    }
    if (metrics != null) {
      metrics.end(metric, true);
    }

    return Future.succeededFuture();
  }

  @Override
  public boolean pendingQueueFull() {
    return connection.pendingQueueFull();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy