Class: Microkit::NetworkController

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/microkit/network_controller.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNetworkController

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

#changeObject (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_intervalObject



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_intervalObject



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