Class: Pho::Status

Inherits:
Object
  • Object
show all
Defined in:
lib/pho/status.rb

Overview

Captures status information relating to a store

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(retry_interval, status_message, access_mode) ⇒ Status

Returns a new instance of Status.



25
26
27
28
29
# File 'lib/pho/status.rb', line 25

def initialize(retry_interval, status_message, access_mode)
  @retry_interval = retry_interval
  @status_message = status_message
  @access_mode = access_mode
end

Instance Attribute Details

#access_modeObject (readonly)

Current access mode uri

This will be one of Pho::READ_ONLY, Pho::READ_WRITE, or Pho::UNAVAILABLE. Use the readable and writeable methods to test for the different modes



23
24
25
# File 'lib/pho/status.rb', line 23

def access_mode
  @access_mode
end

#retry_intervalObject (readonly)

Interval before status should be requested again.



14
15
16
# File 'lib/pho/status.rb', line 14

def retry_interval
  @retry_interval
end

#status_messageObject (readonly)

Status message



17
18
19
# File 'lib/pho/status.rb', line 17

def status_message
  @status_message
end

Class Method Details

.read_from_store(store) ⇒ Object

Create a Status object by reading the response from a store access status request

The code parses the JSON output from the Platform API to create a Status object.

store

the store whose status is to be read



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/pho/status.rb', line 36

def Status.read_from_store(store)
  response = store.get_status()
  if (response.status != 200)
    raise "Cannot read store status"
  end
  
  u = store.build_uri("/config/access-status")
  json = JSON.parse( response.content )
  retry_interval = json[u]["http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#retryInterval"][0]["value"]
  status_message = json[u]["http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#statusMessage"][0]["value"]
  access_mode = json[u]["http:\/\/schemas.talis.com\/2006\/bigfoot\/configuration#accessMode"][0]["value"]
  
  state = Status.new(retry_interval.to_i, status_message, access_mode)
  return state
      
end

Instance Method Details

#readable?Boolean

Is the store readable?

Returns:

  • (Boolean)


54
55
56
# File 'lib/pho/status.rb', line 54

def readable?
  return @access_mode != Pho::UNAVAILABLE
end

#writeable?Boolean

Is the store writeable?

Returns:

  • (Boolean)


59
60
61
# File 'lib/pho/status.rb', line 59

def writeable?
  return @access_mode == Pho::READ_WRITE
end