Guest User

Untitled

a guest
Apr 15th, 2013
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 1.49 KB | None | 0 0
  1.     void run() {
  2.         def SECOND = 1000
  3.         def DOUBLE_INTERVAL = 5 * SECOND
  4.         def SUSPEND = 0
  5.         def INJECT = 1
  6.         def TIMER = 2
  7.         def INPUT = 3
  8.        
  9.         def timer = new CSTimer()
  10.         def scaleAlt = new ALT([suspend, injector, timer, inChannel])
  11.        
  12.         def preCon = new boolean[4]
  13.         preCon[SUSPEND] = true
  14.         preCon[INJECT] = false
  15.         preCon[TIMER] = true
  16.         preCon[INPUT] = true
  17.         def suspended = false
  18.        
  19.         def timeout = timer.read() + DOUBLE_INTERVAL
  20.         timer.setAlarm(timeout)
  21.        
  22.         while (true) {
  23.             preCon[INJECT] = (suspended) ? true : false
  24.             switch (scaleAlt.priSelect(preCon)) {
  25.                 case SUSPEND:
  26.                     // deal with suspend input
  27.                     suspend.read()
  28.                     factor.write(scaling)
  29.                     suspended = true
  30.                     println "Suspended"
  31.                     break
  32.                 case INJECT:
  33.                     // deal with inject input
  34.                     scaling = injector.read()
  35.                     println "Injected scaling is ${scaling}"
  36.                     suspended = false
  37.                     timeout = timer.read() + DOUBLE_INTERVAL
  38.                     timer.setAlarm(timeout)
  39.                     break
  40.                 case TIMER:
  41.                     // deal with Timer input
  42.                     timeout = timer.read() + DOUBLE_INTERVAL
  43.                     timer.setAlarm(timeout)
  44.                     scaling = scaling * 2
  45.                     println "Normal Timer: new scaling is ${scaling}"
  46.                     break
  47.                 case INPUT:
  48.                     // deal with Input channel
  49.                     def inValue = inChannel.read()
  50.                     def result = new ScaledData()
  51.                     result.original = inValue
  52.                     result.scaled = (suspended) ? inValue : inValue * scaling
  53.                     outChannel.write(result)
  54.                     break
  55.             } //end-switch
  56.         } //end-while
  57.     } //end-run
Advertisement
Add Comment
Please, Sign In to add comment