Class: ReactivePgClient::PgSubscriber
- Inherits:
-
Object
- Object
- ReactivePgClient::PgSubscriber
- Defined in:
- /Users/julien/java/reactive-pg-client/target/classes/reactive-pg-client/pg_subscriber.rb
Overview
A class for managing subscriptions using
LISTEN/UNLISTEN
to Postgres channels.
The subscriber manages a single connection to Postgres.
Constant Summary
- @@j_api_type =
Object.new
Class Method Summary (collapse)
- + (Boolean) accept?(obj)
- + (Object) j_api_type
- + (Object) j_class
-
+ (::ReactivePgClient::PgSubscriber) subscriber(vertx = nil, options = nil)
Create a subscriber.
- + (Object) unwrap(obj)
- + (Object) wrap(obj)
Instance Method Summary (collapse)
-
- (::ReactivePgClient::PgConnection) actual_connection
The actual connection to Postgres, it might be null.
-
- (::ReactivePgClient::PgChannel) channel(name = nil)
Return a channel for the given name.
-
- (void) close
Close the subscriber, the retry policy will not be invoked.
-
- (self) close_handler { ... }
Set an handler called when the subscriber is closed.
-
- (true, false) closed?
Whether the subscriber is closed.
-
- (self) connect { ... }
Connect the subscriber to Postgres.
-
- (self) reconnect_policy(policy = nil) { ... }
Set the reconnect policy that is executed when the subscriber is disconnected.
Class Method Details
+ (Boolean) accept?(obj)
22 23 24 |
# File '/Users/julien/java/reactive-pg-client/target/classes/reactive-pg-client/pg_subscriber.rb', line 22 def @@j_api_type.accept?(obj) obj.class == PgSubscriber end |
+ (Object) j_api_type
31 32 33 |
# File '/Users/julien/java/reactive-pg-client/target/classes/reactive-pg-client/pg_subscriber.rb', line 31 def self.j_api_type @@j_api_type end |
+ (Object) j_class
34 35 36 |
# File '/Users/julien/java/reactive-pg-client/target/classes/reactive-pg-client/pg_subscriber.rb', line 34 def self.j_class Java::IoReactiversePgclientPubsub::PgSubscriber.java_class end |
+ (::ReactivePgClient::PgSubscriber) subscriber(vertx = nil, options = nil)
Create a subscriber.
41 42 43 44 45 46 |
# File '/Users/julien/java/reactive-pg-client/target/classes/reactive-pg-client/pg_subscriber.rb', line 41 def self.subscriber(vertx=nil,=nil) if vertx.class.method_defined?(:j_del) && .class == Hash && !block_given? return ::Vertx::Util::Utils.safe_create(Java::IoReactiversePgclientPubsub::PgSubscriber.java_method(:subscriber, [Java::IoVertxCore::Vertx.java_class,Java::IoReactiversePgclient::PgConnectOptions.java_class]).call(vertx.j_del,Java::IoReactiversePgclient::PgConnectOptions.new(::Vertx::Util::Utils.to_json_object())),::ReactivePgClient::PgSubscriber) end raise ArgumentError, "Invalid arguments when calling subscriber(#{vertx},#{})" end |
+ (Object) unwrap(obj)
28 29 30 |
# File '/Users/julien/java/reactive-pg-client/target/classes/reactive-pg-client/pg_subscriber.rb', line 28 def @@j_api_type.unwrap(obj) obj.j_del end |
+ (Object) wrap(obj)
25 26 27 |
# File '/Users/julien/java/reactive-pg-client/target/classes/reactive-pg-client/pg_subscriber.rb', line 25 def @@j_api_type.wrap(obj) PgSubscriber.new(obj) end |
Instance Method Details
- (::ReactivePgClient::PgConnection) actual_connection
Returns the actual connection to Postgres, it might be
null
97 98 99 100 101 102 |
# File '/Users/julien/java/reactive-pg-client/target/classes/reactive-pg-client/pg_subscriber.rb', line 97 def actual_connection if !block_given? return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:actualConnection, []).call(),::ReactivePgClient::PgConnection) end raise ArgumentError, "Invalid arguments when calling actual_connection()" end |
- (::ReactivePgClient::PgChannel) channel(name = nil)
Return a channel for the given
name
.
50 51 52 53 54 55 |
# File '/Users/julien/java/reactive-pg-client/target/classes/reactive-pg-client/pg_subscriber.rb', line 50 def channel(name=nil) if name.class == String && !block_given? return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:channel, [Java::java.lang.String.java_class]).call(name),::ReactivePgClient::PgChannel) end raise ArgumentError, "Invalid arguments when calling channel(#{name})" end |
- (void) close
This method returns an undefined value.
Close the subscriber, the retry policy will not be invoked.
112 113 114 115 116 117 |
# File '/Users/julien/java/reactive-pg-client/target/classes/reactive-pg-client/pg_subscriber.rb', line 112 def close if !block_given? return @j_del.java_method(:close, []).call() end raise ArgumentError, "Invalid arguments when calling close()" end |
- (self) close_handler { ... }
Set an handler called when the subscriber is closed.
89 90 91 92 93 94 95 |
# File '/Users/julien/java/reactive-pg-client/target/classes/reactive-pg-client/pg_subscriber.rb', line 89 def close_handler if block_given? @j_del.java_method(:closeHandler, [Java::IoVertxCore::Handler.java_class]).call(Proc.new { yield }) return self end raise ArgumentError, "Invalid arguments when calling close_handler()" end |
- (true, false) closed?
Returns whether the subscriber is closed
104 105 106 107 108 109 |
# File '/Users/julien/java/reactive-pg-client/target/classes/reactive-pg-client/pg_subscriber.rb', line 104 def closed? if !block_given? return @j_del.java_method(:closed, []).call() end raise ArgumentError, "Invalid arguments when calling closed?()" end |
- (self) connect { ... }
Connect the subscriber to Postgres.
59 60 61 62 63 64 65 |
# File '/Users/julien/java/reactive-pg-client/target/classes/reactive-pg-client/pg_subscriber.rb', line 59 def connect if block_given? @j_del.java_method(:connect, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |ar| yield(ar.failed ? ar.cause : nil) })) return self end raise ArgumentError, "Invalid arguments when calling connect()" end |
- (self) reconnect_policy(policy = nil) { ... }
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 afteramountOfTime
milliseconds
79 80 81 82 83 84 85 |
# File '/Users/julien/java/reactive-pg-client/target/classes/reactive-pg-client/pg_subscriber.rb', line 79 def reconnect_policy(policy=nil) if block_given? && policy == nil @j_del.java_method(:reconnectPolicy, [Java::JavaUtilFunction::Function.java_class]).call((Proc.new { |event| yield(event) })) return self end raise ArgumentError, "Invalid arguments when calling reconnect_policy(#{policy})" end |