evt-message_store 1.0.1.1 → 1.0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23b4e429e5c187e8de005adf7a2f148de18c4893e76456f50075e1f2d6dd782d
4
- data.tar.gz: 94135a7d2f2c4f11014cf5bd3d564571ecc665d8d7cd8e93c728793fd9b3f107
3
+ metadata.gz: b6f8bc3eff87f99068e4ce07e8eb16e432a94670a98efc1f0c5c8bf9f088eac0
4
+ data.tar.gz: 5f3e8a3652909a57c67e32af2255452bd2e08a4805f21dd070cd05b8653439b2
5
5
  SHA512:
6
- metadata.gz: 5aedd66443542670741cf422a2e4ab4836dd26a882e8c453e3365112fb2060a4ccbb07162fd0c226575459f5ff91c1a421005fdfc4b9a84c0ee71bbb5fde31e6
7
- data.tar.gz: dc8dee30c6c22c1d5a2206b380cff2edd2d4e968b5687b5f071480d107802f0aae07363b303d5676967769700ad37755bff46151757eb48fbaa657accf279a5c
6
+ metadata.gz: f1ac5dd9d08309e768d47d826e2b8efd0a7b61f039d89f9f4da9c74a623aa6dac1f779fc228fa7d07acf0fd55543a64d9a88bdcb95db23bd399f6390deeec9a0
7
+ data.tar.gz: f2d459e14781ec06b7936135fdb2db46b39ea3ed01523f3c01217aaf3c4f3b11f3db3718277bba82b4e5c58bafff78d0eb413696a4eaeba034427f9247f5a996
@@ -19,14 +19,22 @@ module MessageStore
19
19
  end
20
20
  end
21
21
 
22
- attr_accessor :starting_position
23
22
  attr_accessor :batch
24
23
 
24
+ def starting_position
25
+ @starting_position ||= 0
26
+ end
27
+ attr_writer :starting_position
28
+
25
29
  def batch_index
26
30
  @batch_index ||= 0
27
31
  end
28
32
  attr_writer :batch_index
29
33
 
34
+ def batch_size
35
+ get.batch_size
36
+ end
37
+
30
38
  module Build
31
39
  def build(stream_name, position: nil)
32
40
  new(stream_name).tap do |instance|
@@ -47,7 +55,9 @@ module MessageStore
47
55
  def next
48
56
  logger.trace { "Getting next message data (Batch Length: #{(batch &.length).inspect}, Batch Index: #{batch_index})" }
49
57
 
50
- resupply if batch_depleted?
58
+ if batch_depleted?
59
+ resupply
60
+ end
51
61
 
52
62
  message_data = batch[batch_index]
53
63
 
@@ -59,35 +69,14 @@ module MessageStore
59
69
  message_data
60
70
  end
61
71
 
62
- def advance_batch_index
63
- logger.trace { "Advancing batch index (Batch Index: #{batch_index})" }
64
- self.batch_index += 1
65
- logger.debug { "Advanced batch index (Batch Index: #{batch_index})" }
66
- end
67
-
68
- def batch_depleted?
69
- if batch.nil?
70
- logger.debug { "Batch is depleted (Batch is nil)" }
71
- return true
72
- end
73
-
74
- if batch.empty?
75
- logger.debug { "Batch is depleted (Batch is empty)" }
76
- return true
77
- end
78
-
79
- if batch_index == batch.length
80
- logger.debug { "Batch is depleted (Batch Index: #{batch_index}, Batch Length: #{batch.length})" }
81
- return true
82
- end
83
-
84
- false
85
- end
86
-
87
72
  def resupply
88
73
  logger.trace { "Resupplying batch (Current Batch Length: #{(batch &.length).inspect})" }
89
74
 
90
- batch = get_batch
75
+ batch = []
76
+ unless stream_depleted?
77
+ batch = get_batch
78
+ end
79
+
91
80
  reset(batch)
92
81
 
93
82
  logger.debug { "Batch resupplied (Next Batch Length: #{(batch &.length).inspect})" }
@@ -98,10 +87,7 @@ module MessageStore
98
87
 
99
88
  logger.trace "Getting batch (Position: #{position.inspect})"
100
89
 
101
- batch = []
102
- if position.nil? || position >= 0
103
- batch = get.(stream_name, position: position)
104
- end
90
+ batch = get.(stream_name, position: position)
105
91
 
106
92
  logger.debug { "Finished getting batch (Count: #{batch.length}, Position: #{position.inspect})" }
107
93
 
@@ -109,8 +95,8 @@ module MessageStore
109
95
  end
110
96
 
111
97
  def next_batch_starting_position
112
- if batch.nil?
113
- logger.debug { "Batch is nil (Next batch starting position: #{starting_position.inspect})" }
98
+ if not batch_initialized?
99
+ logger.debug { "Batch is not initialized (Next batch starting position: #{starting_position.inspect})" }
114
100
  return starting_position
115
101
  end
116
102
 
@@ -132,6 +118,51 @@ module MessageStore
132
118
  logger.debug { "Done resetting batch" }
133
119
  end
134
120
 
121
+ def advance_batch_index
122
+ logger.trace { "Advancing batch index (Batch Index: #{batch_index})" }
123
+ self.batch_index += 1
124
+ logger.debug { "Advanced batch index (Batch Index: #{batch_index})" }
125
+ end
126
+
127
+ def batch_initialized?
128
+ not batch.nil?
129
+ end
130
+
131
+ def batch_depleted?
132
+ if not batch_initialized?
133
+ logger.debug { "Batch is depleted (Batch is not initialized)" }
134
+ return true
135
+ end
136
+
137
+ if batch.empty?
138
+ logger.debug { "Batch is depleted (Batch is empty)" }
139
+ return true
140
+ end
141
+
142
+ if batch_index == batch.length
143
+ logger.debug { "Batch is depleted (Batch Index: #{batch_index}, Batch Length: #{batch.length})" }
144
+ return true
145
+ end
146
+
147
+ logger.debug { "Batch is not depleted (Batch Index: #{batch_index}, Batch Length: #{batch.length})" }
148
+ false
149
+ end
150
+
151
+ def stream_depleted?
152
+ if not batch_initialized?
153
+ logger.debug { "Stream is not depleted (Batch Length: (batch is nil), Batch Size: #{batch_size})" }
154
+ return false
155
+ end
156
+
157
+ if batch.length < batch_size
158
+ logger.debug { "Stream is depleted (Batch Length: #{batch.length}, Batch Size: #{batch_size})" }
159
+ return true
160
+ end
161
+
162
+ logger.debug { "Stream is not depleted (Batch Length: #{batch.length}, Batch Size: #{batch_size})" }
163
+ false
164
+ end
165
+
135
166
  class Substitute
136
167
  include Read::Iterator
137
168
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: evt-message_store
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1.1
4
+ version: 1.0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Eventide Project
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-20 00:00:00.000000000 Z
11
+ date: 2019-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: evt-casing
@@ -178,8 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
178
  - !ruby/object:Gem::Version
179
179
  version: '0'
180
180
  requirements: []
181
- rubyforge_project:
182
- rubygems_version: 2.7.3
181
+ rubygems_version: 3.0.1
183
182
  signing_key:
184
183
  specification_version: 4
185
184
  summary: Common primitives for platform-specific message store implementations