-
-
Save nicholasf/9334e4f835657b2ed82b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;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