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

com.julienviet.reactivex.pgclient.pubsub.PgSubscriber Maven / Gradle / Ivy

/*
 * Copyright 2014 Red Hat, Inc.
 *
 * Red Hat licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package com.julienviet.reactivex.pgclient.pubsub;

import java.util.Map;
import io.reactivex.Observable;
import io.reactivex.Flowable;
import io.reactivex.Single;
import io.reactivex.Completable;
import io.reactivex.Maybe;
import io.vertx.reactivex.core.Vertx;
import com.julienviet.pgclient.PgConnectOptions;
import com.julienviet.reactivex.pgclient.PgConnection;
import io.vertx.core.AsyncResult;
import io.vertx.core.Handler;
import java.util.function.Function;

/**
 * A class for managing subscriptions using LISTEN/UNLISTEN to Postgres channels.
 * 

* The subscriber manages a single connection to Postgres. * *

* NOTE: This class has been automatically generated from the {@link com.julienviet.pgclient.pubsub.PgSubscriber original} non RX-ified interface using Vert.x codegen. */ @io.vertx.lang.reactivex.RxGen(com.julienviet.pgclient.pubsub.PgSubscriber.class) public class PgSubscriber { public static final io.vertx.lang.reactivex.TypeArg __TYPE_ARG = new io.vertx.lang.reactivex.TypeArg<>( obj -> new PgSubscriber((com.julienviet.pgclient.pubsub.PgSubscriber) obj), PgSubscriber::getDelegate ); private final com.julienviet.pgclient.pubsub.PgSubscriber delegate; public PgSubscriber(com.julienviet.pgclient.pubsub.PgSubscriber delegate) { this.delegate = delegate; } public com.julienviet.pgclient.pubsub.PgSubscriber getDelegate() { return delegate; } /** * Create a subscriber. * @param vertx the vertx instance * @param options the connect options * @return the subscriber */ public static PgSubscriber subscriber(Vertx vertx, PgConnectOptions options) { PgSubscriber ret = PgSubscriber.newInstance(com.julienviet.pgclient.pubsub.PgSubscriber.subscriber(vertx.getDelegate(), options)); return ret; } /** * Return a channel for the given name. * @param name the channel name * @return the channel */ public PgChannel channel(String name) { PgChannel ret = PgChannel.newInstance(delegate.channel(name)); return ret; } /** * Connect the subscriber to Postgres. * @param handler the handler notified of the connection success or failure * @return a reference to this, so the API can be used fluently */ public PgSubscriber connect(Handler> handler) { delegate.connect(handler); return this; } /** * Connect the subscriber to Postgres. * @return */ public Completable rxConnect() { return new io.vertx.reactivex.core.impl.AsyncResultCompletable(handler -> { connect(handler); }); } /** * Set the reconnect policy that is executed when the subscriber is disconnected. *

* When the subscriber is disconnected, the policy function is called with the actual * number of retries and returns an amountOfTime value: *

    *
  • when amountOfTime < 0: the subscriber is closed and there is no retry
  • *
  • when amountOfTime == 0: the subscriber retries to connect immediately
  • *
  • when amountOfTime > 0: the subscriber retries after amountOfTime milliseconds
  • *
*

* The default policy does not perform any retries. * @param policy the policy to set * @return a reference to this, so the API can be used fluently */ public PgSubscriber reconnectPolicy(Function policy) { delegate.reconnectPolicy(new java.util.function.Function() { public java.lang.Long apply(java.lang.Integer arg) { Long ret = policy.apply(arg); return ret; } }); return this; } /** * Set an handler called when the subscriber is closed. * @param handler the handler * @return a reference to this, so the API can be used fluently */ public PgSubscriber closeHandler(Handler handler) { delegate.closeHandler(handler); return this; } /** * @return the actual connection to Postgres, it might be null */ public PgConnection actualConnection() { PgConnection ret = PgConnection.newInstance(delegate.actualConnection()); return ret; } /** * @return whether the subscriber is closed */ public boolean closed() { boolean ret = delegate.closed(); return ret; } /** * Close the subscriber, the retry policy will not be invoked. */ public void close() { delegate.close(); } public static PgSubscriber newInstance(com.julienviet.pgclient.pubsub.PgSubscriber arg) { return arg != null ? new PgSubscriber(arg) : null; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy