Class: Microkit::NetworkController
- Inherits:
-
Object
- Object
- Microkit::NetworkController
- Includes:
- Singleton
- Defined in:
- lib/microkit/network_controller.rb
Instance Attribute Summary collapse
-
#change ⇒ Object
readonly
Returns the value of attribute change.
Instance Method Summary collapse
- #get_latest_data(action) ⇒ Object
-
#initialize ⇒ NetworkController
constructor
A new instance of NetworkController.
- #start_update_interval ⇒ Object
- #stop_update_interval ⇒ Object
Constructor Details
#initialize ⇒ NetworkController
Returns a new instance of NetworkController.
6 7 8 |
# File 'lib/microkit/network_controller.rb', line 6 def initialize @change = Publisher.new end |
Instance Attribute Details
#change ⇒ Object (readonly)
Returns the value of attribute change.
5 6 7 |
# File 'lib/microkit/network_controller.rb', line 5 def change @change end |
Instance Method Details
#get_latest_data(action) ⇒ Object
10 11 12 |
# File 'lib/microkit/network_controller.rb', line 10 def get_latest_data(action) return HttpClient.instance.post(action, nil, {"user" => Config.instance.get("user")}) end |
#start_update_interval ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/microkit/network_controller.rb', line 14 def start_update_interval () @t = Thread.new do loop do sleep Config.instance.get('polling_interval') res = self.get_latest_data('update') @change.publish(res, "") end end end |
#stop_update_interval ⇒ Object
24 25 26 27 28 |
# File 'lib/microkit/network_controller.rb', line 24 def stop_update_interval () if @t == Thread then @t.kill end end |