seapig-server 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c905efc44aa76da5c00106b2154f698730c21898
4
- data.tar.gz: 4e147803a3b3f639e5a0000f664939c0dcfe6943
3
+ metadata.gz: b946a0834e2eba8cd49a00ceec8e851c757955f6
4
+ data.tar.gz: 5466488806f71b47122e604224f7f8ca8d560963
5
5
  SHA512:
6
- metadata.gz: dc75d376d5eb2a0d6e554fe8c258946dfcd6ed7aea9d2693b48b17aa313ddb66a23ab7a858df3d2b7fa68d97e62a9cbb90cce2ad0f047dda14206e42e90a709a
7
- data.tar.gz: ee97cba3688df53c65688b324d98f1f8cd07514fe158dcc92aa54bb48cd90f080d7988a7854447551ac3f2ef8fa376aca4f766d677feb706ca5ec06b94aeee82
6
+ metadata.gz: 5d0378f7d671db57df6366d5e1f58051a45fa7eeacda6aa9c222dde0a337c7e6d363d38d65d7a3c95d03f99258b9cbfa9091cc53c806c7071f79ae21b5ad0217
7
+ data.tar.gz: 34de72650fad7d8b8476757927c40abe2b8f79ba130035c2a07c3aa316f33cb7464edd97eb06da12379c9db2a294d1a53dac1babb4fc26446a1919404ef87a6c
data/bin/seapig-server CHANGED
@@ -57,6 +57,7 @@ class SeapigObject
57
57
  @valid = false
58
58
  @object = {}
59
59
  @version = 0
60
+ @stall_after = nil
60
61
  @@objects_by_id[@id] = self
61
62
  end
62
63
 
@@ -78,34 +79,45 @@ class SeapigObject
78
79
 
79
80
 
80
81
  def patch(patch, value, from_version, new_version)
81
- print "Patching:\n\tversion:"+@version.inspect+"\n\tfrom_version: "+from_version.inspect+"\n\tnew_version: "+new_version.inspect+"\n\tpatch_size: "+(patch and patch.size.to_s or "nil")+"\n\t--> "
82
+ print "Patching:\n version:"+@version.inspect+"\n from_version: "+from_version.inspect+"\n new_version: "+new_version.inspect+"\n patch_size: "+(patch and patch.size.to_s or "nil")+"\n --> "
82
83
  if from_version == @version or from_version == 0
83
- puts 'Clean'
84
+ puts 'clean'
85
+ if value and @stall_after
86
+ puts ' UNSTALL'
87
+ @version = @stall_after
88
+ @stall_after = nil
89
+ end
84
90
  old_object = JSON.load(JSON.dump(@object))
85
91
  old_version = @version
86
- @object.clear if from_version == 0 or value
92
+ @object.clear if from_version == 0 or value != nil
87
93
  begin
88
94
  Hana::Patch.new(patch).apply(@object) if patch
89
95
  rescue Exception => e
90
- puts "Patching failed!\n\tOld object: "+old_object.inspect+"\n\tPatch: "+patch.inspect
96
+ puts "Patching failed!\n Old object: "+old_object.inspect+"\n Patch: "+patch.inspect
91
97
  raise e
92
98
  end
99
+ if value == false and not @stall_after
100
+ puts ' STALL'
101
+ @stall_after = old_version
102
+ end
93
103
  @object.merge!(value) if value
94
104
  @version = new_version
95
- Client.all.each { |client| send(client, old_version, old_object) }
105
+ Client.all.each { |client| upload(client, old_version, old_object) }
96
106
  SeapigObject.all.each { |object| object.check_validity }
97
107
  elsif from_version > @version
98
- puts "Lost some updates, reinitializing object"
108
+ puts "lost some updates, reinitializing object"
99
109
  @version = 0
100
110
  @object.clear
101
111
  @valid = false
112
+ #assign mb?
102
113
  else
103
- puts "Late update, ignoring"
114
+ puts "late update, ignoring"
104
115
  end
105
116
  end
106
117
 
107
118
 
108
- def send(client, old_version, old_object, patch = nil)
119
+ def upload(client, old_version, old_object, patch = nil)
120
+ return false if @stall_after
109
121
  return false if not client.consumes.find { |object| (object == self) or self.matches?(object.id) }
110
122
  puts 'Sending '+self.id
111
123
  client.socket.send JSON.dump(
@@ -125,7 +137,7 @@ class SeapigObject
125
137
 
126
138
 
127
139
  def inspect
128
- '<SO:%s:%s:%s>'%[@id, @version, (@valid and 'V' or 'I')]
140
+ '<SO:%s:%s:%s%s>'%[@id, @version, (@valid and 'V' or 'I'), (@stall_after and 'S' or 'U')]
129
141
  end
130
142
 
131
143
  end
@@ -187,7 +199,7 @@ class Client
187
199
  Client.all.each { |client| client.produces.each { |pattern| SeapigObject[pattern] if (not pattern.starexp?) and (pattern =~ object.id.starexp) } } if object.id.starexp?
188
200
  SeapigObject.matching(object.id).each { |object|
189
201
  Client.all.find { |client| client.assign(object) }
190
- object.send(self,0,{}) if object.valid
202
+ object.upload(self,0,{}) if object.valid
191
203
  }
192
204
  end
193
205
 
@@ -277,9 +289,10 @@ EM.run {
277
289
  end
278
290
  processing_times << (Time.new.to_f - started_at.to_f)
279
291
  processing_times_sum += processing_times[-1]
280
- puts "Clients:\n"+Client.all.map { |client| "\t%-20s produces:%s consumes:%s"%[client.id,client.produces.inspect,client.consumes.map { |obj| obj.id }] }.join("\n")+"\n"
281
- puts "Objects:\n"+SeapigObject.all.map { |object| "\t%s"%[object.inspect] }.join("\n")+"\n"
282
- puts "Processing:\n\ttime: %.3fs\n\tcount: %i\n\taverage: %.3fs\n\ttotal: %.3fs"%[processing_times[-1], processing_times.size, processing_times_sum / processing_times.size, processing_times_sum]
292
+ puts "Clients:\n"+Client.all.map { |client| " %-20s produces:%s consumes:%s"%[client.id,client.produces.inspect,client.consumes.map { |obj| obj.id }] }.join("\n")+"\n"
293
+ puts "Objects:\n"+SeapigObject.all.map { |object| " %s"%[object.inspect] }.join("\n")+"\n"
294
+ puts "Processing:\n time: %.3fs\n count: %i\n average: %.3fs\n total: %.3fs"%[processing_times[-1], processing_times.size, processing_times_sum / processing_times.size, processing_times_sum]
295
+ STDOUT.flush
283
296
  }
284
297
 
285
298
 
@@ -1,3 +1,3 @@
1
1
  module Seapig
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seapig-server
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - yunta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-06 00:00:00.000000000 Z
11
+ date: 2016-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: websocket-eventmachine-server