Module: PublicEventMethods
Overview
The PublicEventMethods module
Constant Summary
collapse
- RecordNotFoundErrorPattern =
%r{Record not found}.freeze
EventConstants::CallerPattern, EventConstants::EventActivityTemplate, EventConstants::EventAntecedantTemplate, EventConstants::EventCauseIdentityTemplate, EventConstants::EventNameTemplate, EventConstants::EventSourceFullTemplate, EventConstants::EventSourceTemplate
Instance Method Summary
collapse
-
#<<(event) ⇒ Object
-
#antecedent_cancelled? ⇒ Boolean
-
#call ⇒ Object
java_signature ‘V call()’.
-
#call_activity ⇒ Object
-
#cancelled? ⇒ Boolean
-
#concluded? ⇒ Boolean
-
#contextualize(from) ⇒ Object
-
#delay(delay, &block) ⇒ Object
(also: #after_delay)
Shortcut for using delays.
-
#elemental? ⇒ Boolean
-
#finally(&block) ⇒ Object
(also: #on_cancel, #when_completed, #when_done, #when_finished, #when_over, #ultimately)
-
#get ⇒ Object
-
#immediately? ⇒ Boolean
-
#inspect ⇒ Object
-
#integral? ⇒ Boolean
-
#java_get ⇒ Object
-
#mandate_cause_record_exists! ⇒ Object
-
#maybe_log_nilling_warning(callstack) ⇒ Object
-
#now(params = {}, &block) ⇒ Object
(also: #add_event, #event, #and_then, #chain, #eventually, #later)
-
#on_cancelled_antecedent ⇒ Object
-
#on_failure(_cause) ⇒ Object
-
#on_success(_result) ⇒ Object
-
#origin(x = self) ⇒ Object
-
#parse_activity ⇒ Object
-
#run ⇒ Object
java_signature ‘void run()’.
-
#termination(x = self) ⇒ Object
-
#to_s ⇒ Object
-
#warn_when_nilling_noun(from, to, attribute, value) ⇒ Object
Instance Method Details
#<<(event) ⇒ Object
114
115
116
117
|
# File 'lib/runtime/events.rb', line 114
def <<(event)
@successors.add event
event.antecedent = self
end
|
#antecedent_cancelled? ⇒ Boolean
146
147
148
149
150
151
152
|
# File 'lib/runtime/events.rb', line 146
def antecedent_cancelled?
return false if self.antecedent.nil?
return false unless self.antecedent.cancelled?
return false if self.terminus.nil?
log.warn "Event antecedent #{self.antecedent} was cancelled"
true
end
|
java_signature ‘V call()’
224
225
226
|
# File 'lib/runtime/events.rb', line 224
def call
process(self)
end
|
#call_activity ⇒ Object
218
219
220
221
|
# File 'lib/runtime/events.rb', line 218
def call_activity
return self.activity.call(self) if self.activity.arity == 1
self.activity.call(*self.args)
end
|
#cancelled? ⇒ Boolean
141
142
143
144
|
# File 'lib/runtime/events.rb', line 141
def cancelled?
return true if future.nil?
future.cancelled?
end
|
#concluded? ⇒ Boolean
154
155
156
|
# File 'lib/runtime/events.rb', line 154
def concluded?
semaphore.synchronize { concluded == true }
end
|
#delay(delay, &block) ⇒ Object
Also known as:
after_delay
Shortcut for using delays
199
200
201
|
# File 'lib/runtime/events.rb', line 199
def delay(delay, &block)
Inform::Event.new({ cause: cause, antecedent: self, delay: delay }, &block)
end
|
#elemental? ⇒ Boolean
129
130
131
|
# File 'lib/runtime/events.rb', line 129
def elemental?
@type == :elemental
end
|
#finally(&block) ⇒ Object
Also known as:
on_cancel, when_completed, when_done, when_finished, when_over, ultimately
204
205
206
|
# File 'lib/runtime/events.rb', line 204
def finally(&block)
Inform::Event.new({ cause: cause, antecedent: self, terminus: true }, &block)
end
|
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
|
# File 'lib/runtime/events.rb', line 158
def get
if future.respond_to?(:get)
future.get
elsif future.respond_to?(:call)
future.call
end
future
rescue SystemExit => e
raise e
rescue StandardError => e
log.error "Event execution exception: #{e.message}"
end
|
137
138
139
|
# File 'lib/runtime/events.rb', line 137
def immediately?
@when == :immediately
end
|
250
251
252
|
# File 'lib/runtime/events.rb', line 250
def inspect
format(EventCauseIdentityTemplate, identity: @cause.identity, name: @cause.name)
end
|
#integral? ⇒ Boolean
133
134
135
|
# File 'lib/runtime/events.rb', line 133
def integral?
@type == :integral
end
|
174
175
176
177
178
179
180
181
182
183
184
|
# File 'lib/runtime/events.rb', line 174
def java_get
self.future.get
self.future
rescue SystemExit => e
raise e
rescue Java::JavaUtilConcurrent::CancellationException => e
log.warn "Cancelled #{event}"
log.debug "Reason for event cancellation: #{e}"
rescue Java::JavaUtilConcurrent::ExecutionException => e
log.error "Event execution exception: #{e.message}"
end
|
#mandate_cause_record_exists! ⇒ Object
256
257
258
259
260
261
262
263
264
|
# File 'lib/runtime/events.rb', line 256
def mandate_cause_record_exists!
self.cause.refresh
rescue StandardError => e
if RecordNotFoundErrorPattern.match?(e.message)
message = e.message + ' for cause of event ' + self.to_s
raise Inform::EventCauseRecordNotFoundError, message
end
log.warn "Unexpected error refreshing event cause object: #{e.message}"
end
|
#maybe_log_nilling_warning(callstack) ⇒ Object
109
110
111
112
|
# File 'lib/runtime/events.rb', line 109
def maybe_log_nilling_warning(callstack)
return if callstack.grep('channel_read')
['===========', (caller[-4...] + callstack), '==========='].each { |t| log.warn t unless t.nil? }
end
|
#now(params = {}, &block) ⇒ Object
Also known as:
add_event, event, and_then, chain, eventually, later
186
187
188
189
190
|
# File 'lib/runtime/events.rb', line 186
def now(params = {}, &block)
Inform::Event.new({ cause: cause, antecedent: self }.merge(params), &block)
end
|
#on_cancelled_antecedent ⇒ Object
241
242
243
244
|
# File 'lib/runtime/events.rb', line 241
def on_cancelled_antecedent
schedule self unless terminus.nil?
successors.each(&:on_cancelled_antecedent)
end
|
#on_failure(_cause) ⇒ Object
233
234
235
|
# File 'lib/runtime/events.rb', line 233
def on_failure(_cause)
cancelled
end
|
#on_success(_result) ⇒ Object
237
238
239
|
# File 'lib/runtime/events.rb', line 237
def on_success(_result)
completed
end
|
#origin(x = self) ⇒ Object
119
120
121
122
|
# File 'lib/runtime/events.rb', line 119
def origin(x = self)
x = origin x.antecedent if x.antecedent
x.object? ? x : x.cause
end
|
#parse_activity ⇒ Object
214
215
216
|
# File 'lib/runtime/events.rb', line 214
def parse_activity
self.cause.parse(self.activity)
end
|
java_signature ‘void run()’
229
230
231
|
# File 'lib/runtime/events.rb', line 229
def run
call
end
|
#termination(x = self) ⇒ Object
124
125
126
127
|
# File 'lib/runtime/events.rb', line 124
def termination(x = self)
event = x.successors.first
event || x.terminus
end
|
246
247
248
|
# File 'lib/runtime/events.rb', line 246
def to_s
self.identity
end
|
#warn_when_nilling_noun(from, to, attribute, value) ⇒ Object
98
99
100
101
102
103
104
105
106
|
# File 'lib/runtime/events.rb', line 98
def warn_when_nilling_noun(from, to, attribute, value)
return unless attribute == :noun
return unless value.nil?
return if (current_value = to.send(attribute)).nil?
return if attribute == :parameters && current_value <= 1
log.debug "Overwriting #{to}.#{attribute} (#{current_value}) with #{from}.#{attribute} (nil)!"
log.debug " #{to}.context: #{to.context.inspect}"
maybe_log_nilling_warning(to.callstack)
end
|