Class: VertxPgClient::PgSubscriber

Inherits:
Object
  • Object
show all
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)

Instance Method Summary (collapse)

Class Method Details

+ (Boolean) accept?(obj)

Returns:

  • (Boolean)


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.

Parameters:

  • vertx (::Vertx::Vertx)
    the vertx instance
  • options (Hash{String => Object})
    the connect options

Returns:



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

Returns:



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.

Parameters:

  • name (String)
    the channel name

    This will be the name of the channel exactly as held by Postgres for sending notifications. Internally this name will be truncated to the Postgres identifier maxiumum length of (NAMEDATALEN = 64) - 1 == 63 characters, and prepared as a quoted identifier without unicode escape sequence support for use in LISTEN/UNLISTEN commands. Examples of channel names and corresponding NOTIFY commands:

    • when name == "the_channel": NOTIFY the_channel, 'msg', NOTIFY The_Channel, 'msg', or NOTIFY "the_channel", 'msg' succeed in delivering a message to the created channel
    • when name == "The_Channel": NOTIFY "The_Channel", 'msg', succeeds in delivering a message to the created channel

Returns:



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.

Yields:

  • the handler

Returns:

  • (self)


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

Returns:

  • (true, false)
    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.

Yields:

  • the handler notified of the connection success or failure

Returns:

  • (self)


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 after amountOfTime milliseconds

The default policy does not perform any retries.

Yields:

  • the policy to set

Returns:

  • (self)


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