Class: Tupelo::Client
- Inherits:
-
Funl::Client
- Object
- Funl::Client
- Tupelo::Client
show all
- Includes:
- Api
- Defined in:
- lib/tupelo/client.rb,
lib/tupelo/client/atdo.rb,
lib/tupelo/util/boolean.rb,
lib/tupelo/client/common.rb,
lib/tupelo/client/reader.rb,
lib/tupelo/client/worker.rb,
lib/tupelo/client/tuplespace.rb,
lib/tupelo/client/transaction.rb
Defined Under Namespace
Modules: Api
Classes: AtDo, Matcher, NotifyWaiter, NullTuplespace, Or, SimpleTuplespace, Transaction, TransactionAbort, TransactionError, TransactionFailure, TransactionStateError, Unwaiter, Waiter, WaiterBase, Worker
Constant Summary
collapse
- TUPELO_SUBSPACE_TAG =
"tupelo subspace"
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Api
#abort, #batch, #notifier, #pulse_nowait, #pulse_wait, #read_all, #read_nowait, #read_wait, #take, #take_nowait, #trans_class, #transaction, #write_nowait, #write_wait
Constructor Details
#initialize(tuplespace: SimpleTuplespace, subscribe: :all, **opts) ⇒ Client
Returns a new instance of Client.
15
16
17
18
19
20
|
# File 'lib/tupelo/client.rb', line 15
def initialize(tuplespace: SimpleTuplespace, subscribe: :all, **opts)
super **opts
@tuplespace = tuplespace
@worker = make_worker
@initial_subscriptions = subscribe
end
|
Instance Attribute Details
#tuplespace ⇒ Object
Returns the value of attribute tuplespace.
11
12
13
|
# File 'lib/tupelo/client.rb', line 11
def tuplespace
@tuplespace
end
|
Returns the value of attribute worker.
10
11
12
|
# File 'lib/tupelo/client.rb', line 10
def worker
@worker
end
|
Instance Method Details
#define_subspace(metatuple) ⇒ Object
do these belong in API module?
61
62
63
64
|
# File 'lib/tupelo/client.rb', line 61
def define_subspace metatuple
defaults = {__tupelo__: "subspace", addr: nil}
write_wait defaults.merge!(metatuple)
end
|
#log(*args) ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/tupelo/client.rb', line 52
def log *args
if args.empty?
super()
else
super().unknown *args
end
end
|
#make_queue ⇒ Object
26
27
28
|
# File 'lib/tupelo/client.rb', line 26
def make_queue
Queue.new
end
|
#make_scheduler(**opts) ⇒ Object
27
28
29
|
# File 'lib/tupelo/client/atdo.rb', line 27
def make_scheduler **opts
AtDo.new self, **opts
end
|
#make_worker ⇒ Object
22
23
24
|
# File 'lib/tupelo/client.rb', line 22
def make_worker
Worker.new self
end
|
#or(*templates) ⇒ Object
Also known as:
match_any
14
15
16
|
# File 'lib/tupelo/util/boolean.rb', line 14
def or *templates
Or.new(worker, templates)
end
|
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/tupelo/client.rb', line 30
def start
super
worker.start
case @initial_subscriptions
when :all
subscribe_all
when Array
subscribe @initial_subscriptions | [Tupelo::Client::TUPELO_SUBSPACE_TAG]
when String
@initial_subscriptions = [@initial_subscriptions]
subscribe @initial_subscriptions | [Tupelo::Client::TUPELO_SUBSPACE_TAG]
else
raise ArgumentError,
"bad subscription specifier: #{@initial_subscriptions}"
end
end
|
48
49
50
|
# File 'lib/tupelo/client.rb', line 48
def stop
worker.stop
end
|
#subspace(tag) ⇒ Object
81
82
83
84
|
# File 'lib/tupelo/client.rb', line 81
def subspace tag
tag = tag.to_s
worker.subspaces.find {|sp| sp.tag == tag}
end
|
#use_subspaces! ⇒ Object
call this just once at start of first client (it’s optional to preserve behavior of non-subspace-aware code)
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/tupelo/client.rb', line 68
def use_subspaces!
return if subspace(TUPELO_SUBSPACE_TAG)
define_subspace(
tag: TUPELO_SUBSPACE_TAG,
template: {
__tupelo__: {value: "subspace"},
tag: nil,
addr: nil,
template: nil
}
)
end
|