Class: Dovado::Router::Traffic
- Inherits:
-
Object
- Object
- Dovado::Router::Traffic
- Includes:
- Celluloid
- Defined in:
- lib/dovado/router/traffic.rb,
lib/dovado/router/traffic/amount.rb
Overview
Defined Under Namespace
Classes: Amount
Class Method Summary collapse
- .setup_supervision! ⇒ Object private
Instance Method Summary collapse
-
#Amount(value = 0, base = DEFAULT_KILO_BASE) ⇒ Object
Create a new Amount object.
-
#down ⇒ Amount+
Data download traffic amount.
-
#down_total ⇒ Amount
Data download total traffic amount.
-
#initialize ⇒ Traffic
constructor
Create a new Traffic object.
-
#up ⇒ Amount+
Data upload traffic amount.
-
#up_total ⇒ Amount
Data upload total traffic amount.
-
#update! ⇒ Object
Update the data in this Traffic object.
-
#valid? ⇒ Boolean
Determine if this traffic object is valid.
Constructor Details
#initialize ⇒ Traffic
Create a new Dovado::Router::Traffic object.
32 33 34 35 36 37 38 |
# File 'lib/dovado/router/traffic.rb', line 32 def initialize @data = ThreadSafe::Cache.new @client = Actor[:client] unless @client @last_update = nil @data[:down] = Traffic::Amount.new @data[:up] = Traffic::Amount.new end |
Class Method Details
.setup_supervision! ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
99 100 101 |
# File 'lib/dovado/router/traffic.rb', line 99 def self.setup_supervision! supervise as: :traffic, size: 1 unless Actor[:traffic] end |
Instance Method Details
#Amount(value = 0, base = DEFAULT_KILO_BASE) ⇒ Object
Create a new Amount object.
77 78 79 |
# File 'lib/dovado/router/traffic/amount.rb', line 77 def Amount(value=0, base=DEFAULT_KILO_BASE) Amount.new(value, base) end |
#down ⇒ Amount+
Data download traffic amount.
If two modems are used, the returned value is an array with Amount objects.
57 58 59 60 |
# File 'lib/dovado/router/traffic.rb', line 57 def down update! @data[:down] end |
#down_total ⇒ Amount
Data download total traffic amount. Useful with multiple modems.
65 66 67 68 |
# File 'lib/dovado/router/traffic.rb', line 65 def down_total up, down = update_total_traffic_from_router_info Traffic::Amount.new down end |
#up ⇒ Amount+
Data upload traffic amount.
If two modems are used, the returned value is an array with Amount objects.
46 47 48 49 |
# File 'lib/dovado/router/traffic.rb', line 46 def up update! @data[:up] end |
#up_total ⇒ Amount
Data upload total traffic amount. Useful with multiple modems.
73 74 75 76 |
# File 'lib/dovado/router/traffic.rb', line 73 def up_total up, down = update_total_traffic_from_router_info Traffic::Amount.new up end |
#update! ⇒ Object
Update the data in this Dovado::Router::Traffic object.
79 80 81 82 83 84 85 86 87 88 |
# File 'lib/dovado/router/traffic.rb', line 79 def update! unless valid? begin fetch_from_router rescue @data[:up], @data[:down] = fetch_from_router_info end touch! end end |
#valid? ⇒ Boolean
Determine if this traffic object is valid.
93 94 95 96 |
# File 'lib/dovado/router/traffic.rb', line 93 def valid? return false if @last_update.nil? (@last_update + SecureRandom.random_number(9) + 1 <= Time.now.to_i) end |