Skip to content

Instantly share code, notes, and snippets.

@nicholasf
Created July 6, 2012 04:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicholasf/9334e4f835657b2ed82b to your computer and use it in GitHub Desktop.
Save nicholasf/9334e4f835657b2ed82b to your computer and use it in GitHub Desktop.
;not for production - move this file somewhere else a bit later
(ns util.device_emulator
(:use somnium.congomongo))
(def ^:const PROCESS_STATES ["ACTIVE" "ASLEEP" "AWAKE" "DISCONNECTED"])
(def conn
(make-connection "deviceRegistry"
:host "127.0.0.1"
:port 27017))
(set-connection! conn)
(defn n-devices [number-of-devices]
;1. create n device-emulations (a device emulation should be a function)
; - place them in a set, each to their id
;2. register each device in the set in mongo with an initial status
;3. begin a timed lifecycle, interval x, randomize accessing the devices
; and randomize their status
(let [devices ()]
(loop [n number-of-devices]
(register-device n)
(if neg? n)
n
(recur (dec n))))
)
;the device should act independently in a timed interval
;on creation the device will record itself in redis
;on shutdown it would be nice if it cleaned up its data trail
;changing its state, updating the redis channel
(defn register-device [id]
(insert! :devices {:clientId id :status "AWAKE"})
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment