示例#1
0
文件: resources.go 项目: igalic/mgmt
// ReadEvent processes events when a select gets one, and handles the pause
// code too! The return values specify if we should exit and poke respectively.
func (obj *BaseRes) ReadEvent(ev *event.Event) (exit, poke bool) {
	ev.ACK()
	switch ev.Name {
	case event.EventStart:
		return false, true

	case event.EventPoke:
		return false, true

	case event.EventBackPoke:
		return false, true // forward poking in response to a back poke!

	case event.EventExit:
		return true, false

	case event.EventPause:
		// wait for next event to continue
		select {
		case e := <-obj.Events():
			e.ACK()
			if e.Name == event.EventExit {
				return true, false
			} else if e.Name == event.EventStart { // eventContinue
				return false, false // don't poke on unpause!
			} else {
				// if we get a poke event here, it's a bug!
				log.Fatalf("%v[%v]: Unknown event: %v, while paused!", obj.Kind(), obj.GetName(), e)
			}
		}

	default:
		log.Fatal("Unknown event: ", ev)
	}
	return true, false // required to keep the stupid go compiler happy
}
示例#2
0
// ReadEvent processes events when a select gets one, and handles the pause
// code too! The return values specify if we should exit and poke respectively.
func (obj *BaseRes) ReadEvent(ev *event.Event) (exit, send bool) {
	ev.ACK()
	var poke bool
	// ensure that a CheckApply runs by sending with a dirty state...
	if ev.GetActivity() { // if previous node did work, and we were notified...
		obj.StateOK(false) // dirty
		poke = true        // poke!
		// XXX: this should be elsewhere in case Watch isn't used (eg: Polling instead...)
		// XXX: unless this is used in our "fallback" polling implementation???
		//obj.SetRefresh(true) // TODO: is this redundant?
	}

	switch ev.Name {
	case event.EventStart:
		send = true || poke
		return

	case event.EventPoke:
		send = true || poke
		return

	case event.EventBackPoke:
		send = true || poke
		return // forward poking in response to a back poke!

	case event.EventExit:
		// FIXME: what do we do if we have a pending refresh (poke) and an exit?
		return true, false

	case event.EventPause:
		// wait for next event to continue
		select {
		case e, ok := <-obj.Events():
			if !ok { // shutdown
				return true, false
			}
			e.ACK()
			if e.Name == event.EventExit {
				return true, false
			} else if e.Name == event.EventStart { // eventContinue
				return false, false // don't poke on unpause!
			} else {
				// if we get a poke event here, it's a bug!
				log.Fatalf("%s[%s]: Unknown event: %v, while paused!", obj.Kind(), obj.GetName(), e)
			}
		}

	default:
		log.Fatal("Unknown event: ", ev)
	}
	return true, false // required to keep the stupid go compiler happy
}