Class: VertxPgClient::PgSubscriber
- Inherits:
-
Object
- Object
- VertxPgClient::PgSubscriber
- Defined in:
- /Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-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
-
+ (::VertxPgClient::PgSubscriber) subscriber(vertx, options)
Create a subscriber.
- + (Object) unwrap(obj)
- + (Object) wrap(obj)
Instance Method Summary (collapse)
-
- (::VertxPgClient::PgConnection) actualConnection
The actual connection to Postgres, it might be null.
-
- (::VertxPgClient::PgChannel) channel(name)
Return a channel for the given name.
-
- (void) close
Close the subscriber, the retry policy will not be invoked.
-
- (self) closeHandler(handler) { ... }
Set an handler called when the subscriber is closed.
-
- (true, false) closed
Whether the subscriber is closed.
-
- (self) connect(handler) { ... }
Connect the subscriber to Postgres.
-
- (self) reconnectPolicy(policy) { ... }
Set the reconnect policy that is executed when the subscriber is disconnected.
Class Method Details
+ (Boolean) accept?(obj)
23 24 25 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-pg-client/pg_subscriber.rb', line 23 def @@j_api_type.accept?(obj) obj.class == PgSubscriber end |
+ (Object) j_api_type
32 33 34 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-pg-client/pg_subscriber.rb', line 32 def self.j_api_type @@j_api_type end |
+ (Object) j_class
35 36 37 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-pg-client/pg_subscriber.rb', line 35 def self.j_class Java::IoVertxPgclientPubsub::PgSubscriber.java_class end |
+ (::VertxPgClient::PgSubscriber) subscriber(vertx, options)
Create a subscriber.
43 44 45 46 47 48 49 50 51 52 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-pg-client/pg_subscriber.rb', line 43 def self.subscriber(*args) if args[0].class.method_defined?(:j_del) && args[1].class == Hash && !block_given? return ::Vertx::Util::Utils.safe_create(Java::IoVertxPgclientPubsub::PgSubscriber.java_method(:subscriber, [Java::IoVertxCore::Vertx.java_class,Java::IoVertxPgclient::PgConnectOptions.java_class]).call(args[0].j_del,Java::IoVertxPgclient::PgConnectOptions.new(::Vertx::Util::Utils.to_json_object(args[1]))),::VertxPgClient::PgSubscriber) end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling subscriber(#{args[0]},#{args[1]})" end end |
+ (Object) unwrap(obj)
29 30 31 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-pg-client/pg_subscriber.rb', line 29 def @@j_api_type.unwrap(obj) obj.j_del end |
+ (Object) wrap(obj)
26 27 28 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-pg-client/pg_subscriber.rb', line 26 def @@j_api_type.wrap(obj) PgSubscriber.new(obj) end |
Instance Method Details
- (::VertxPgClient::PgConnection) actualConnection
Returns the actual connection to Postgres, it might be
null
134 135 136 137 138 139 140 141 142 143 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-pg-client/pg_subscriber.rb', line 134 def actual_connection if !block_given? return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:actualConnection, []).call(),::VertxPgClient::PgConnection) end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling actual_connection()" end end |
- (::VertxPgClient::PgChannel) channel(name)
Return a channel for the given
name
.
57 58 59 60 61 62 63 64 65 66 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-pg-client/pg_subscriber.rb', line 57 def channel(*args) if args[0].class == String && !block_given? return ::Vertx::Util::Utils.safe_create(@j_del.java_method(:channel, [Java::java.lang.String.java_class]).call(args[0]),::VertxPgClient::PgChannel) end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling channel(#{args[0]})" end end |
- (void) close
This method returns an undefined value.
Close the subscriber, the retry policy will not be invoked.
122 123 124 125 126 127 128 129 130 131 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-pg-client/pg_subscriber.rb', line 122 def close if !block_given? return @j_del.java_method(:close, []).call() end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling close()" end end |
- (self) closeHandler(handler) { ... }
Set an handler called when the subscriber is closed.
83 84 85 86 87 88 89 90 91 92 93 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-pg-client/pg_subscriber.rb', line 83 def close_handler if true @j_del.java_method(:closeHandler, [Java::IoVertxCore::Handler.java_class]).call((Proc.new { |event| yield(nil) unless !block_given? })) return self end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling close_handler()" end end |
- (true, false) closed
Returns whether the subscriber is closed
69 70 71 72 73 74 75 76 77 78 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-pg-client/pg_subscriber.rb', line 69 def closed? if !block_given? return @j_del.java_method(:closed, []).call() end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling closed?()" end end |
- (self) connect(handler) { ... }
Connect the subscriber to Postgres.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-pg-client/pg_subscriber.rb', line 148 def connect if true if (block_given?) @j_del.java_method(:connect, [Java::IoVertxCore::Handler.java_class]).call(block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? nil : nil) } : promise) return self else promise = ::Vertx::Util::Utils.promise @j_del.java_method(:connect, [Java::IoVertxCore::Handler.java_class]).call(block_given? ? Proc.new { |ar| yield(ar.failed ? ar.cause : nil, ar.succeeded ? nil : nil) } : promise) return ::Vertx::Util::Utils.safe_create(promise.future(),::Vertx::Future, nil) end end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling connect()" end end |
- (self) reconnectPolicy(policy) { ... }
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
108 109 110 111 112 113 114 115 116 117 118 |
# File '/Users/julien/java/vertx-aggregator/modules/vertx-lang-ruby/vertx-lang-ruby/target/classes/vertx-pg-client/pg_subscriber.rb', line 108 def reconnect_policy(*args) if block_given? && args[0] == nil @j_del.java_method(:reconnectPolicy, [Java::JavaUtilFunction::Function.java_class]).call((Proc.new { |event| yield(event) unless !block_given? })) return self end if defined?(super) super else raise ArgumentError, "Invalid arguments when calling reconnect_policy(#{args[0]})" end end |