Class: Monitors::Neighborhood

Inherits:
BaseMonitor show all
Defined in:
lib/poolparty/monitors/monitors/neighborhood_monitor.rb

Instance Attribute Summary

Attributes inherited from BaseMonitor

#last_cloud_loaded_time, #log_file_path

Instance Method Summary collapse

Methods inherited from BaseMonitor

#after_close_callbacks, #before_close_callbacks, #env, inherited, #initialize, #log, #my_cloud

Constructor Details

This class inherits a constructor from Monitors::BaseMonitor

Instance Method Details

#get(data = nil) ⇒ Object



10
11
12
13
# File 'lib/poolparty/monitors/monitors/neighborhood_monitor.rb', line 10

def get(data=nil)
  reset!
  neighborhood      
end

#post(data) ⇒ Object



28
29
30
31
32
# File 'lib/poolparty/monitors/monitors/neighborhood_monitor.rb', line 28

def post(data)
  received = JSON.parse(data)
  @neighborhood = JSON.parse(data)
  save
end

#put(data, from = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/poolparty/monitors/monitors/neighborhood_monitor.rb', line 15

def put(data, from=nil)
  @neighborhood_instances = merge_array_of_hashes_with_key(neighborhood.instances, JSON.parse(data), 'ip')
  @neighborhood = {@neighborhood[:instances] => @neighborhood_instances}
  # after_close do
  #   if @neighborhood.instances.size>1
  #     # TODO: Add logger here
  #     puts "Pinging #{"#{@neighborhood.instances.rand.ip}/neighborhood"}"
  #     RestClient.put "#{@neighborhood.instances.rand.ip}/neighborhood", @neighborhood, :content_type => 'text/x-json'
  #   end
  # end
  save
end