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
Traffic Counters.
Defined Under Namespace
Classes: Amount
Instance Method Summary collapse
-
#Amount(value, base = DEFAULT_KILO_BASE) ⇒ Object
Create a new Amount object.
-
#down ⇒ Amount
Data download traffic amount.
-
#initialize ⇒ Traffic
constructor
Create a new Internet object.
-
#up ⇒ Amount
Data upload traffic amount.
-
#update! ⇒ Object
Update this Traffic object.
-
#valid? ⇒ Boolean
Determine if this traffic object is valid.
Constructor Details
#initialize ⇒ Traffic
Create a new Internet object.
12 13 14 15 16 17 18 |
# File 'lib/dovado/router/traffic.rb', line 12 def initialize @data = ThreadSafe::Cache.new @client = Actor[:client] unless @client @last_update = nil @data[:down] = Traffic::Amount.new(0) @data[:up] = Traffic::Amount.new(0) end |
Instance Method Details
#Amount(value, base = DEFAULT_KILO_BASE) ⇒ Object
Create a new Amount object.
50 51 52 |
# File 'lib/dovado/router/traffic/amount.rb', line 50 def Amount(value, base=DEFAULT_KILO_BASE) Amount.new(value, base) end |
#down ⇒ Amount
Data download traffic amount.
31 32 33 34 |
# File 'lib/dovado/router/traffic.rb', line 31 def down update! @data[:down] end |
#up ⇒ Amount
Data upload traffic amount.
23 24 25 26 |
# File 'lib/dovado/router/traffic.rb', line 23 def up update! @data[:up] end |
#update! ⇒ Object
Update this Dovado::Router::Traffic object.
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/dovado/router/traffic.rb', line 37 def update! unless valid? begin up, down = fetch_from_router rescue up, down = fetch_from_router_info end @data[:down] = Traffic::Amount.new(down) @data[:up] = Traffic::Amount.new(up) touch! end end |
#valid? ⇒ Boolean
Determine if this traffic object is valid.
53 54 55 56 |
# File 'lib/dovado/router/traffic.rb', line 53 def valid? return false if @last_update.nil? (@last_update + SecureRandom.random_number(9) + 1 <= Time.now.to_i) end |