Class: MINT::AIOUTContinuous

Inherits:
AIOUT show all
Defined in:
lib/MINT-core/model/aui/AIOUTContinuous.rb

Constant Summary

Constants inherited from Interactor

Interactor::PUBLISH_ATTRIBUTES

Instance Method Summary collapse

Methods inherited from AIO

#exists_next, #exists_parent, #exists_prev, #focus_next, #focus_parent, #focus_previous, getModel, #inform_parent_presenting, #next, #next2str, #parent, #parent2str, #parent=, #previous, #previous2str

Methods inherited from Interactor

class_from_channel_name, #create_attribute_channel_name, create_channel_name, #create_channel_w_name, get, getModel, get_dm, #init_statemachine, #is_in?, #new_states, notify, #process_event, #process_event!, #process_event_vars, #publish_update, #states, #states=, #sync_event, #sync_states, #to_dot, wait

Methods included from InteractorHelpers

#restart_timeout, #start_timeout, #stop_timeout

Instance Method Details

#consume(attribute) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/MINT-core/model/aui/AIOUTContinuous.rb', line 26

def consume(attribute)
  @d = 0

  channel_name = create_attribute_channel_name(attribute)
  p "subscribed #{channel_name}"

  redis = RedisConnector.redis

  fiber = Fiber.current

  redis.pubsub.subscribe(channel_name) { |message|
    found=MultiJson.decode message

    if self.name.eql? found['name']
      if found['data']
        @d = found['data'].to_i
        @data = attribute_get(:data)

        process_event "move"
        restart_timeout(1,:halt)

        attribute_set(:data,@d)
        RedisConnector.redis.publish("out_channel:#{create_channel_w_name}:testuser",@data)
      end
    end
  }.callback {  fiber.resume}
  Fiber.yield
  @d
end

#data=(value) ⇒ Object

functions called from scxml



16
17
18
19
# File 'lib/MINT-core/model/aui/AIOUTContinuous.rb', line 16

def data=(value)
  super  # use original method instead of accessing @ivar directly
  publish_update_new
end

#getSCXMLObject



8
9
10
# File 'lib/MINT-core/model/aui/AIOUTContinuous.rb', line 8

def getSCXML
  "#{File.dirname(__FILE__)}/aioutcontinuous.scxml"
end

#halt(id) ⇒ Object



56
57
58
# File 'lib/MINT-core/model/aui/AIOUTContinuous.rb', line 56

def halt(id)
  RedisConnector.sub.unsubscribe(self.class.create_channel_name+".#{id}")
end

#publish_update_newObject



21
22
23
# File 'lib/MINT-core/model/aui/AIOUTContinuous.rb', line 21

def publish_update_new
  RedisConnector.redis.publish create_attribute_channel_name('data'), self.to_json(:only => self.class::PUBLISH_ATTRIBUTES)
end