Ejemplo n.º 1
0
func main() {
	dcams.ManifestFileName = "springdata.manifest"
	testserver, err := dcams.Open()
	if err != nil {
		//What do we need: 1 pub, 1 REP
		pub, err := dcams.NewPub("springData")
		dieOnErr(err)
		testserver.Add(pub)
		REP, err := dcams.NewREP("springInput")
		dieOnErr(err)
		testserver.Add(REP)
		testserver.WriteFile()
		log.Printf("springdata  publish key: [\"%s\"]", pub.PublicKey)
		log.Printf("springInput REP key:     [\"%s\"]", REP.PublicKey)
		log.Fatal("Manually swap keys with remote client trusted list!")
	}
	//log.Println(testserver)
	log.Println("Connect")

	//subscribe to model
	go modelDataSub()

	//Connect to upstream visualization server
	testserver.Connect()

	// Connect to model for shuttling upstream requests
	shuttleRequests, _ := zmq.NewSocket(zmq.PUSH)
	shuttleRequests.Bind("tcp://127.0.0.1:5560")

	// async recv upstream visualization requests
	go upstreamRequests(testserver)

	log.Println("Shuttle Model Data forever")
	for i := 0; ; i++ {
		select {
		case d := <-modelData:
			//
			mmsg, _ := json.Marshal(d)
			//log.Println("shuttling", string(mmsg))
			//log.Println("shuttling", d[0])
			err := testserver.Resource("springData").Write(string(mmsg))
			dieOnErr(err)

		case modelUpdate := <-changerequests:
			//shuttle updates to the model
			log.Println("Got request", modelUpdate)
			mmsg, err := json.Marshal(modelUpdate)
			dieOnErr(err)

			//log.Println("shuttling", string(mmsg))
			_, err = shuttleRequests.Send(string(mmsg), 0)
			dieOnErr(err)
		}
	}
}
Ejemplo n.º 2
0
func main() {
	dcams.ManifestFileName = "springdata.manifest"
	testserver, err := dcams.Open()
	if err != nil {
		//What do we need: 1 pub, 1 REP
		pub, err := dcams.NewPub("springData")
		dieOnErr(err)
		testserver.Add(pub)
		REP, err := dcams.NewREP("springInput")
		dieOnErr(err)
		testserver.Add(REP)
		testserver.WriteFile()
		log.Printf("springdata  publish key: [\"%s\"]", pub.PublicKey)
		log.Printf("springInput REP key:     [\"%s\"]", REP.PublicKey)
		log.Fatal("Manually swap keys with remote client trusted list!")
	}
	//log.Println(testserver)
	log.Println("Connect")
	testserver.Connect()
	go handleClientChange(testserver)

	var c Map
	dieOnErr(c.readData("http://localhost:9000/public/rsrc/substations.json"))

	log.Println("Fake data forever")
	for i := 0; ; i++ {
		select {
		case _ = <-time.After(time.Millisecond * 500):

			msg := c.nextEvent()
			mmsg, _ := json.Marshal(msg)
			//log.Println(string(mmsg))
			//fmt.Printf(".")
			err := testserver.Resource("springData").Write(string(mmsg))
			dieOnErr(err)
		case e := <-publish:
			//log.Println("Got", e)
			c.SetfrqByName(e.Id, e.Frq)
		}
	}
}