Example #1
0
func main() {
	flag.Parse()
	alexander.ExportTypes(Message{})

	err := alexander.Start()
	defer alexander.Stop()
	if err != nil {
		log.Fatalf("Could not start alexander %s", err)
	}

	exitChan := make(chan bool)

	if *isProducer {
		go func() {
			for count := 0; count < 10; count++ {
				msg := &Message{Msg: *message, Origin: *nodeName, Sent: time.Now()}
				_, _, err := alexander.Do(msg, "PrintMe")
				if err != nil {
					log.Printf("Error processing task: %s", err)
				}
				time.Sleep(*frequency)
			}
			exitChan <- true
		}()
	}

	<-exitChan
}
Example #2
0
func Dijkstra(g Graph, distributed bool, paths chan NodePath) {
	for nodeid, _ := range g {
		go func(start NodeId) {
			if !distributed {
				paths <- g.PathFrom(start)
			} else {
				_, pathResults, err := alexander.Do(g, "PathFrom", start)
				if len(pathResults) == 0 {
					log.Printf("WARNING: Empty path returned for node %d", start)
					return
				}

				if err != nil {
					log.Printf("ERROR calculating path %s", err)
					return
				}
				path := pathResults[0].(NodePath)
				paths <- path

			}
		}(nodeid)
	}
}