Class: CPEE::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/cpee/controller.rb

Overview

}}}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, opts) ⇒ Controller

Returns a new instance of Controller.



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/cpee/controller.rb', line 81

def initialize(id,opts)
  @directory = opts[:instances] + "/#{id}/"
  @id = id
  @events = {}
  @votes = {}
  @votes_results = {}
  @communication = {}
  @callbacks = {}
  @positions = []
  @attributes = {}
  @attributes_helper = AttributesHelper.new
  @thread = nil
  @mutex = Mutex.new
  @opts = opts

  @properties = Riddl::Utils::Properties::Backend.new(
    {
      :inactive => opts[:properties_schema_inactive],
      :active   => opts[:properties_schema_active],
      :finished => opts[:properties_schema_finished]
    },
    @directory + '/properties.xml',
    opts[:properties_init]
  )
  @notifications =  Riddl::Utils::Notifications::Producer::Backend.new(
    opts[:topics],
    @directory + '/notifications/',
    opts[:notifications_init]
  )
  unless ['stopped','ready','finished','abandoned'].include?(@properties.data.find("string(/p:properties/p:state)"))
    @properties.modify do |doc|
      doc.find("/p:properties/p:state").first.text = 'stopped'
    end
  end
  @uuid = sync_uuid!
  if @properties.data.find("string(/p:properties/p:state)") == "finished"
    @instance = nil
  else
    @instance = EmptyWorkflow.new(self)

    @notifications.subscriptions.keys.each do |key|
      self.unserialize_notifications!(:cre,key)
    end

    unserialize_handlerwrapper!
    unserialize_dataelements!
    unserialize_endpoints!
    unserialize_dsl!
    unserialize_positions!
    unserialize_attributes!
  end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



159
160
161
# File 'lib/cpee/controller.rb', line 159

def attributes
  @attributes
end

#callbacksObject (readonly)

Returns the value of attribute callbacks.



157
158
159
# File 'lib/cpee/controller.rb', line 157

def callbacks
  @callbacks
end

#idObject (readonly)

Returns the value of attribute id.



154
155
156
# File 'lib/cpee/controller.rb', line 154

def id
  @id
end

#mutexObject (readonly)

Returns the value of attribute mutex.



158
159
160
# File 'lib/cpee/controller.rb', line 158

def mutex
  @mutex
end

#notificationsObject (readonly)

Returns the value of attribute notifications.



155
156
157
# File 'lib/cpee/controller.rb', line 155

def notifications
  @notifications
end

#propertiesObject (readonly)

Returns the value of attribute properties.



156
157
158
# File 'lib/cpee/controller.rb', line 156

def properties
  @properties
end

#uuidObject (readonly)

Returns the value of attribute uuid.



160
161
162
# File 'lib/cpee/controller.rb', line 160

def uuid
  @uuid
end

Instance Method Details

#add_websocket(key, socket) ⇒ Object

}}}



662
663
664
665
666
667
668
669
670
671
672
673
674
# File 'lib/cpee/controller.rb', line 662

def add_websocket(key,socket)# {{{
  @communication[key] = socket
  @events.each do |a|
    if a[1].has_key?(key)
      a[1][key] = socket
    end
  end
  @votes.each do |a|
    if a[1].has_key?(key)
      a[1][key] = socket
    end
  end
end

#attributes_translatedObject



167
168
169
# File 'lib/cpee/controller.rb', line 167

def attributes_translated
  @attributes_helper.translate(attributes,dataelements,endpoints)
end

#baseObject



180
181
182
# File 'lib/cpee/controller.rb', line 180

def base
  base_url
end

#base_urlObject



174
175
176
# File 'lib/cpee/controller.rb', line 174

def base_url
  @opts[:url]
end

#call_vote(what, content = {}) ⇒ Object

}}}



596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
# File 'lib/cpee/controller.rb', line 596

def call_vote(what,content={})# {{{
  voteid = Digest::MD5.hexdigest(Kernel::rand().to_s)
  item = @votes[what]
  if item && item.length > 0
    continue = WEEL::Continue.new
    @votes_results[voteid] = []
    inum = 0
    item.each do |key,url|
      if url.class == String
        inum += 1
      elsif url.class == Riddl::Utils::Notifications::Producer::WS
        inum += 1 unless url.closed?
      end
    end

    item.each do |key,url|

      Thread.new(key,url,content.dup) do |k,u,c|
        callback = Digest::MD5.hexdigest(Kernel::rand().to_s)
        c['callback'] = callback
        notf = build_notification(k,what,c,'vote',callback)
        if u.class == String
          client = Riddl::Client.new(u,'http://riddl.org/ns/common-patterns/notifications-consumer/1.0/consumer.xml')
          params = notf.map{|ke,va|Riddl::Parameter::Simple.new(ke,va)}
          params << Riddl::Header.new("CPEE-BASE",self.base_url)
          params << Riddl::Header.new("CPEE-INSTANCE",self.instance_url)
          params << Riddl::Header.new("CPEE-CALLBACK",self.instance_url + '/callbacks/' + callback)
          @mutex.synchronize do
            status, result, headers = client.post params
            if headers["CPEE_CALLBACK"] && headers["CPEE_CALLBACK"] == 'true'
              @callbacks[callback] = Callback.new("vote #{notf.find{|a,b| a == 'notification'}[1]}", self, :vote_callback, what, k, :http, continue, voteid, callback, inum)
            else
              vote_callback(result,nil,continue,voteid,callback,inum)
            end
          end
        elsif u.class == Riddl::Utils::Notifications::Producer::WS
          @callbacks[callback] = Callback.new("vote #{notf.find{|a,b| a == 'notification'}[1]}", self, :vote_callback, what, k, :ws, continue, voteid, callback, inum)
          e = XML::Smart::string("<vote/>")
          notf.each do |ke,va|
            e.root.add(ke,va)
          end
          u.send(e.to_s)
        end
      end

    end
    continue.wait

    !@votes_results.delete(voteid).include?(false)
  else
    true
  end
end

#console(cmd) ⇒ Object



162
163
164
165
# File 'lib/cpee/controller.rb', line 162

def console(cmd)
  x = eval(cmd)
  x.class == String ? x : x.pretty_inspect
end

#dataelementsObject



189
190
191
# File 'lib/cpee/controller.rb', line 189

def dataelements
  @instance.data
end

#endpointsObject



186
187
188
# File 'lib/cpee/controller.rb', line 186

def endpoints
  @instance.endpoints
end

#finalize_if_finishedObject



247
248
249
250
251
252
# File 'lib/cpee/controller.rb', line 247

def finalize_if_finished
  if @instance.state == :finished
    # TODO unlink engine, be careful race condition
    # @instance = nil
  end
end

#gcObject



145
146
147
148
149
150
151
152
# File 'lib/cpee/controller.rb', line 145

def gc
  x = GC.stat
  y = {}
  y[:heap_live_slots]         = x[:heap_live_slots]
  y[:total_allocated_objects] = x[:total_allocated_objects]
  y[:total_freed_objects]     = x[:total_freed_objects]
  y
end

#helpObject



134
135
136
137
138
# File 'lib/cpee/controller.rb', line 134

def help
  "\033[1m\033[31mpm or public_methods(false)\033[0m\033[0m\n  Methods.\n" +
  "\033[1m\033[31miv or instance_variables\033[0m\033[0m\n  Attributes.\n" +
  "\033[1m\033[31mgc or GC.stat\033[0m\033[0m\n  GC stats to look for memleaks. Google for 'GC.stat ruby'.\n"
end

#hostObject



171
172
173
# File 'lib/cpee/controller.rb', line 171

def host
  @opts[:host]
end

#infoObject

}}}



223
224
225
# File 'lib/cpee/controller.rb', line 223

def info
  @properties.data.find("string(/p:properties/p:attributes/p:info)")
end

#info=(text) ⇒ Object



226
227
228
229
230
231
# File 'lib/cpee/controller.rb', line 226

def info=(text)
  @properties.modify do |doc|
    node = doc.find("/p:properties/p:attributes/p:info").first
    node.text = text if node
  end
end

#instanceObject



183
184
185
# File 'lib/cpee/controller.rb', line 183

def instance
  instance_url
end

#instance_urlObject



177
178
179
# File 'lib/cpee/controller.rb', line 177

def instance_url
  File.join(@opts[:url].to_s,@id.to_s)
end

#ivObject



142
143
144
# File 'lib/cpee/controller.rb', line 142

def iv
  instance_variables
end

#notify(what, content = {}) ⇒ Object

}}}



571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
# File 'lib/cpee/controller.rb', line 571

def notify(what,content={})# {{{
  item = @events[what]

  if item
    item.each do |ke,ur|
      Thread.new(ke,ur) do |key,url|
        notf = build_notification(key,what,content,'event')
        if url.class == String
          client = Riddl::Client.new(url,'http://riddl.org/ns/common-patterns/notifications-consumer/1.0/consumer.xml')
          params = notf.map{|ke,va|Riddl::Parameter::Simple.new(ke,va)}
          params << Riddl::Header.new("CPEE-BASE",self.base)
          params << Riddl::Header.new("CPEE-INSTANCE",self.instance)
          client.post params
        elsif url.class == Riddl::Utils::Notifications::Producer::WS
          e = XML::Smart::string("<event/>")
          notf.each do |k,v|
            e.root.add(k,v)
          end
          url.send(e.to_s) rescue nil
        end
      end
    end
  end
end

#pmObject



139
140
141
# File 'lib/cpee/controller.rb', line 139

def pm
  public_methods(false)
end

#serialize_dataelements!Object

{{{



254
255
256
257
258
259
260
261
262
# File 'lib/cpee/controller.rb', line 254

def serialize_dataelements! #{{{
  @properties.modify do |doc|
    node = doc.find("/p:properties/p:dataelements").first
    node.children.delete_all!
    @instance.data.each do |k,v|
      node.add(k.to_s,ValueHelper::generate(v))
    end
  end
end

#serialize_endpoints!Object

}}}



263
264
265
266
267
268
269
270
271
# File 'lib/cpee/controller.rb', line 263

def serialize_endpoints! #{{{
  @properties.modify do |doc|
    node = doc.find("/p:properties/p:endpoints").first
    node.children.delete_all!
    @instance.endpoints.each do |k,v|
      node.add(k.to_s,v)
    end
  end
end

#serialize_positions!Object

}}}



280
281
282
283
284
285
286
287
288
289
# File 'lib/cpee/controller.rb', line 280

def serialize_positions! # {{{
  @properties.modify do |doc|
    pos = doc.find("/p:properties/p:positions").first
    pos.children.delete_all!
    @positions = @instance.positions
    @instance.positions.each do |p|
      pos.add("#{p.position}",p.detail,'passthrough' => p.passthrough)
    end
  end
end

#serialize_state!Object

}}}



272
273
274
275
276
277
278
279
# File 'lib/cpee/controller.rb', line 272

def serialize_state! # {{{
  @properties.activate_schema(:finished) if @instance.state == :finished || @instance.state == :abandoned
  @properties.activate_schema(:inactive) if @instance.state == :stopped  || @instance.state == :ready
  @properties.activate_schema(:active)   if @instance.state == :running  || @instance.state == :simulating
  if [:finished, :stopped, :ready, :abandoned].include?(@instance.state)
    state_change! @instance.state
  end
end

#serialize_status!Object

}}}



290
291
292
293
294
295
296
297
# File 'lib/cpee/controller.rb', line 290

def serialize_status! #{{{
  @properties.modify do |doc|
    node = doc.find("/p:properties/p:status/p:id").first
    node.text = @instance.status.id
    node = doc.find("/p:properties/p:status/p:message").first
    node.text = @instance.status.message
  end
end

#simObject

{{{



193
194
195
196
# File 'lib/cpee/controller.rb', line 193

def sim # {{{
  @thread.join if !@thread.nil? && @thread.alive?
  @thread = @instance.sim
end

#startObject

}}}



198
199
200
201
202
203
204
# File 'lib/cpee/controller.rb', line 198

def start # {{{
  @thread.join if !@thread.nil? && @thread.alive?
  unless @positions.empty?
    @instance.search(@positions)
  end
  @thread = @instance.start
end

#stateObject



232
233
234
# File 'lib/cpee/controller.rb', line 232

def state
  @properties.data.find("string(/p:properties/p:state)")
end

#state_change!(state = nil) ⇒ Object



238
239
240
241
242
243
244
245
# File 'lib/cpee/controller.rb', line 238

def state_change!(state=nil)
  @properties.modify do |doc|
    doc.find("/p:properties/p:state").each do |ele|
      ele.attributes['changed'] = Time.now.xmlschema
      ele.text = state if state
    end
  end
end

#state_changedObject



235
236
237
# File 'lib/cpee/controller.rb', line 235

def state_changed
  (str = @properties.data.find("string(/p:properties/p:state/@changed)")).empty? ? Time.at(0).xmlschema : str
end

#stopObject

}}}



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
# File 'lib/cpee/controller.rb', line 206

def stop # {{{
  t = @instance.stop
  t.run
  @callbacks.delete_if do |k,c|
    # only remove vote_callbacks, the other stuff is removed by
    # the instance stopping cleanup
    if c.method == :vote_callback
      c.callback
      true
    else
      false
    end
  end
  @thread.join if !@thread.nil? && @thread.alive?
  @callback = [] # everything should be empty now
end

#sync_uuid!Object

}}}



560
561
562
563
564
565
566
567
568
569
# File 'lib/cpee/controller.rb', line 560

def sync_uuid! #{{{
  val = SecureRandom.uuid
  uuid = @properties.data.find("/p:properties/p:attributes/p:uuid")
  if uuid.empty?
    @properties.modify { |doc| doc.find("/p:properties/p:attributes").first.prepend('p:uuid',val) }
    val
  else
    uuid.first.text
  end
end

#unserialize_attributes!Object

}}}



367
368
369
370
371
372
373
374
375
376
377
378
379
380
# File 'lib/cpee/controller.rb', line 367

def unserialize_attributes! #{{{
  @attributes = {}
  @properties.data.find("/p:properties/p:attributes/p:*").map do |ele|
    @attributes[ele.qname.name.to_sym] = ele.text
  end
  uuid = @properties.data.find("/p:properties/p:attributes/p:uuid")
  if uuid.empty? || uuid.length != 1 || uuid.first.text != @uuid
    @properties.modify do |doc|
      attr = doc.find("/p:properties/p:attributes").first
      attr.find('p:uuid').delete_all!
      attr.prepend('uuid',@uuid)
    end
  end
end

#unserialize_dataelements!Object

}}}



381
382
383
384
385
386
# File 'lib/cpee/controller.rb', line 381

def unserialize_dataelements! #{{{
  @instance.data.clear
  @properties.data.find("/p:properties/p:dataelements/p:*").each do |e|
    @instance.data[e.qname.to_sym] = ValueHelper::parse(e.text)
  end
end

#unserialize_description!Object

}}}



441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
# File 'lib/cpee/controller.rb', line 441

def unserialize_description! #{{{
  dsl = nil
  nots = []
  @properties.modify do |doc|
    begin
      dsl   = doc.find("/p:properties/p:dsl").first
      dslx  = doc.find("/p:properties/p:dslx").first
      desc  = doc.find("/p:properties/p:description").first
      tdesc = doc.find("/p:properties/p:transformation/p:description").first
      tdata = doc.find("/p:properties/p:transformation/p:dataelements").first
      tendp = doc.find("/p:properties/p:transformation/p:endpoints").first

      tdesctype = tdesc.attributes['type']
      tdatatype = tdata.attributes['type']
      tendptype = tendp.attributes['type']

      if desc.children.empty?
        tdesctype = tdatatype = tendptype = 'clean'
      end

      ### description transformation, including dslx to dsl
      addit = if tdesctype == 'copy' || tdesc.empty?
        desc.children.first.to_doc.root
      elsif tdesctype == 'rest' && !tdesc.empty?
        srv = Riddl::Client.interface(tdesc.text,@opts[:transformation_service])
        status, res = srv.post [
          Riddl::Parameter::Complex.new("description","text/xml",desc.children.first.dump),
          Riddl::Parameter::Simple.new("type","description")
        ]
        if status >= 200 && status < 300
          XML::Smart::string(res[0].value.read).root
        else
          raise 'Could not extract dslx'
        end
      elsif tdesctype == 'xslt' && !tdesc.empty?
        trans = XML::Smart::open_unprotected(tdesc.text)
        desc.children.first.to_doc.transform_with(trans).root
      elsif tdesctype == 'clean'
        XML::Smart::open_unprotected(@opts[:empty_dslx]).root
      else
        nil
      end
      unless addit.nil?
        dslx.children.delete_all!
        dslx.add addit
        trans = XML::Smart::open_unprotected(@opts[:transformation_dslx])
        dsl.text = dslx.to_doc.transform_with(trans)
        @instance.description = dsl.text
      end

      ### dataelements extraction
      addit = if tdatatype == 'rest' && !tdata.empty?
        srv = Riddl::Client.interface(tdata.text,@opts[:transformation_service])
        status, res = srv.post [
          Riddl::Parameter::Complex.new("description","text/xml",desc.children.first.dump),
          Riddl::Parameter::Simple.new("type","dataelements")
        ]
        if status >= 200 && status < 300
          res
        else
          raise 'Could not extract dataelements'
        end
      elsif tdatatype == 'xslt' && !tdata.empty?
        trans = XML::Smart::open_unprotected(tdata.text)
        desc.children.first.to_doc.transform_with(trans)
      elsif tdatatype == 'clean'
        []
      else
        nil
      end
      unless addit.nil?
        node = doc.find("/p:properties/p:dataelements").first
        node.children.delete_all!
        @instance.data.clear
        addit.each_slice(2).each do |k,v|
          @instance.data[k.value.to_sym] = ValueHelper::parse(v.value)
          node.add(k.value,ValueHelper::generate(v.value))
        end
        nots << ["dataelements/change", {:instance => instance, :changed => JSON::generate(@instance.data)}]
      end

      ### endpoints extraction
      addit = if tendptype == 'rest' && !tdata.empty?
        srv = Riddl::Client.interface(tendp.text,@opts[:transformation_service])
        status, res = srv.post [
          Riddl::Parameter::Complex.new("description","text/xml",desc.children.first.dump),
          Riddl::Parameter::Simple.new("type","endpoints")
        ]
        if status >= 200 && status < 300
          res
        else
          raise 'Could not extract endpoints'
        end
      elsif tendptype == 'xslt' && !tdata.empty?
        trans = XML::Smart::open_unprotected(tendp.text)
        desc.children.first.to_doc.transform_with(trans)
      elsif tendptype == 'clean'
        []
      else
        nil
      end
      unless addit.nil?
        node = doc.find("/p:properties/p:endpoints").first
        node.children.delete_all!
        @instance.endpoints.clear
        addit.each_slice(2).each do |k,v|
          @instance.endpoints[k.value.to_sym] = ValueHelper::parse(v.value)
          node.add(k.value,ValueHelper::generate(v.value))
        end
        nots << ["endpoints/change", {:instance => instance, :changed => JSON::generate(@instance.endpoints)}]
      end
      nots << ["description/change", { :instance => instance }]
    rescue => err
      nots << ["description/error", { :instance => instance, :message => err.message }]
    end
  end
  nots
end

#unserialize_dsl!Object

}}}



438
439
440
# File 'lib/cpee/controller.rb', line 438

def unserialize_dsl! #{{{
  @instance.description = @properties.data.find("string(/p:properties/p:dsl)")
end

#unserialize_endpoints!Object

}}}



387
388
389
390
391
392
# File 'lib/cpee/controller.rb', line 387

def unserialize_endpoints! #{{{
  @instance.endpoints.clear
  @properties.data.find("/p:properties/p:endpoints/p:*").each do |e|
    @instance.endpoints[e.qname.to_sym] = e.text
  end
end

#unserialize_handlerwrapper!Object

}}}



416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
# File 'lib/cpee/controller.rb', line 416

def unserialize_handlerwrapper! #{{{
  hw = nil
  begin
    hw = @properties.data.find("string(/p:properties/p:handlerwrapper)")
    @instance.handlerwrapper = eval(hw)
  rescue => e
    @instance.handlerwrapper = DefaultHandlerWrapper
  end
  if hw != @instance.handlerwrapper
    @properties.modify do |doc|
      node = doc.find("/p:properties/p:handlerwrapper").first
      node.text = @instance.handlerwrapper.to_s
    end
  end
end

#unserialize_notifications!(op, key) ⇒ Object

}}}



299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
# File 'lib/cpee/controller.rb', line 299

def unserialize_notifications!(op,key)# {{{
  case op
    when :del
      @notifications.subscriptions[key].delete if @notifications.subscriptions.include?(key)

      @communication[key].io.close_connection if @communication[key].class == Riddl::Utils::Notifications::Producer::WS
      @communication.delete(key)

      @events.each do |eve,keys|
        keys.delete_if{|k,v| key == k}
      end
      @votes.each do |eve,keys|
        keys.delete_if do |k,v|
          if key == k
            @callbacks.each{|voteid,cb|cb.delete_if!(eve,k)}
            true
          end
        end
      end
    when :upd
      if @notifications.subscriptions.include?(key)
        url = @communication[key]
        evs = []
        vos = []
        @events.each { |e,v| evs << e }
        @votes.each { |e,v| vos << e }
        @notifications.subscriptions[key].read do |doc|
          turl = doc.find('string(/n:subscription/@url)')
          url = turl == '' ? url : turl
          @communication[key] = url
          doc.find('/n:subscription/n:topic').each do |t|
            t.find('n:event').each do |e|
              @events["#{t.attributes['id']}/#{e}"] ||= {}
              @events["#{t.attributes['id']}/#{e}"][key] = url
              evs.delete("#{t.attributes['id']}/#{e}")
            end
            t.find('n:vote').each do |e|
              @votes["#{t.attributes['id']}/#{e}"] ||= {}
              @votes["#{t.attributes['id']}/#{e}"][key] = url
              vos.delete("#{t.attributes['id']}/#{e}")
            end
          end
        end
        evs.each { |e| @events[e].delete(key) if @events[e] }
        vos.each do |e|
          @callbacks.each{|voteid,cb|cb.delete_if!(e,key)}
          @votes[e].delete(key) if @votes[e]
        end
      end
    when :cre
      @notifications.subscriptions[key].read do |doc|
        turl = doc.find('string(/n:subscription/@url)')
        url = turl == '' ? nil : turl
        @communication[key] = url
        doc.find('/n:subscription/n:topic').each do |t|
          t.find('n:event').each do |e|
            @events["#{t.attributes['id']}/#{e}"] ||= {}
            @events["#{t.attributes['id']}/#{e}"][key] = (url == "" ? nil : url)
          end
          t.find('n:vote').each do |e|
            @votes["#{t.attributes['id']}/#{e}"] ||= {}
            @votes["#{t.attributes['id']}/#{e}"][key] = url
          end
        end
      end
  end
end

#unserialize_positions!Object

}}}



431
432
433
434
435
436
437
# File 'lib/cpee/controller.rb', line 431

def unserialize_positions! #{{{
  @positions = []
  @properties.data.find("/p:properties/p:positions/p:*").each do |e|
    val = e.text.split(';')
    @positions << ::WEEL::Position.new(e.qname.to_s.to_sym,e.text.to_sym,e.attributes['passthrough'])
  end
end

#unserialize_state!Object

}}}



393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# File 'lib/cpee/controller.rb', line 393

def unserialize_state! #{{{
  state = 'ready'
  @properties.modify do |doc|
    node = doc.find("/p:properties/p:state").first
    state = node.text
  end
  if call_vote("state/change", :instance => @id, :info => info, :state => state)
    case state
      when 'stopping'
        stop
      when 'running'
        start
      when 'simulating'
        sim
      when 'ready'
        @instance.state_signal
    end
  else
    if node = @properties.data.find("/p:properties/p:state").first
      node.text = @instance.state_signal
    end
  end
end

#vote_callback(result, options, continue, voteid, callback, num) ⇒ Object

}}}



650
651
652
653
654
655
656
657
658
659
660
# File 'lib/cpee/controller.rb', line 650

def vote_callback(result,options,continue,voteid,callback,num)# {{{
  @callbacks.delete(callback)
  if result == :DELETE
    @votes_results[voteid] << true
  else
    @votes_results[voteid] << (result && result[0] && result[0].value == 'true')
  end
  if (num == @votes_results[voteid].length)
    continue.continue
  end
end