Class: EventStoreSubscriptions::Subscription
- Inherits:
-
Object
- Object
- EventStoreSubscriptions::Subscription
- Extended by:
- MakeAtomic
- Includes:
- WaitForFinish
- Defined in:
- lib/event_store_subscriptions/subscription.rb
Constant Summary collapse
- FORCED_SHUTDOWN_DELAY =
seconds
60
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#position ⇒ Object
readonly
Returns the value of attribute position.
-
#semaphore ⇒ Object
readonly
Returns the value of attribute semaphore.
-
#setup ⇒ Object
readonly
Returns the value of attribute setup.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
-
#statistic ⇒ Object
readonly
Returns the value of attribute statistic.
Instance Method Summary collapse
-
#initialize(position:, client:, setup:, statistic: SubscriptionStatistic.new) ⇒ Subscription
constructor
A new instance of Subscription.
-
#listen ⇒ EventStoreSubscriptions::Subscription
Start listening for the events.
-
#stop_listening ⇒ EventStoreSubscriptions::Subscription
Stops listening for events.
Methods included from MakeAtomic
Methods included from WaitForFinish
Constructor Details
#initialize(position:, client:, setup:, statistic: SubscriptionStatistic.new) ⇒ Subscription
Returns a new instance of Subscription.
18 19 20 21 22 23 24 25 26 |
# File 'lib/event_store_subscriptions/subscription.rb', line 18 def initialize(position:, client:, setup:, statistic: SubscriptionStatistic.new) @position = position @client = client @setup = setup @state = ObjectState.new @statistic = statistic @runner = nil @semaphore = Mutex.new end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
11 12 13 |
# File 'lib/event_store_subscriptions/subscription.rb', line 11 def client @client end |
#position ⇒ Object (readonly)
Returns the value of attribute position.
11 12 13 |
# File 'lib/event_store_subscriptions/subscription.rb', line 11 def position @position end |
#semaphore ⇒ Object (readonly)
Returns the value of attribute semaphore.
11 12 13 |
# File 'lib/event_store_subscriptions/subscription.rb', line 11 def semaphore @semaphore end |
#setup ⇒ Object (readonly)
Returns the value of attribute setup.
11 12 13 |
# File 'lib/event_store_subscriptions/subscription.rb', line 11 def setup @setup end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
11 12 13 |
# File 'lib/event_store_subscriptions/subscription.rb', line 11 def state @state end |
#statistic ⇒ Object (readonly)
Returns the value of attribute statistic.
11 12 13 |
# File 'lib/event_store_subscriptions/subscription.rb', line 11 def statistic @statistic end |
Instance Method Details
#listen ⇒ EventStoreSubscriptions::Subscription
Start listening for the events
30 31 32 |
# File 'lib/event_store_subscriptions/subscription.rb', line 30 make_atomic def listen _listen end |
#stop_listening ⇒ EventStoreSubscriptions::Subscription
Stops listening for events. This command is async - the result is not immediate. Use the #wait_for_finish method to wait until the runner has fully stopped.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/event_store_subscriptions/subscription.rb', line 37 make_atomic def stop_listening return self unless runner&.alive? state.halting! Thread.new do stopping_at = Time.now.utc loop do # Give Subscription up to FORCED_SHUTDOWN_DELAY seconds for graceful shutdown runner&.exit if Time.now.utc - stopping_at > FORCED_SHUTDOWN_DELAY unless runner&.alive? state.stopped! self.runner = nil break end sleep 0.1 end end self end |