Exemplo n.º 1
0
func invalidate(w http.ResponseWriter, r *http.Request) {

	c := appengine.NewContext(r)

	ii := instance_mgt.GetByContext(c)

	mkk := r.FormValue("mkk")
	sii := r.FormValue("senderInstanceId")

	if ll > 2 {
		aelog.Infof(c, " %s  ---------  %s\n", sii, mkk)
	}

	w.WriteHeader(http.StatusOK)

	if ii.InstanceID == sii {
		w.Write([]byte("Its ME " + mkk + "\n"))
		w.Write([]byte(sii))
	} else {
		w.Write([]byte("got it " + mkk + "\n"))
		w.Write([]byte(sii + "\n"))
		w.Write([]byte(ii.InstanceID))
	}

}
Exemplo n.º 2
0
func multiCastInstanceCacheChange(c context.Context, mkk string) {

	ii := instance_mgt.GetByContext(c)

	/*
		making a get request to all instances
		submitting the key and the sender instance id
	*/
	for i := 0; i < ii.NumInstances; i++ {

		// http://[inst0-2].[v2].default.libertarian-islands.appspot.com/instance-info

		url := fmt.Sprintf("https://%v.%v/_ah/invalidate-instance-cache?mkk=%v&senderInstanceId=%v",
			i,
			ii.Hostname,
			mkk, ii.InstanceID)
		_ = url
		if ll > 2 {
			aelog.Infof(c, " url\n%v", url)
		}

		//response, err := http.Get(url)  // not available in gae
		// instead:
		client := urlfetch.Client(c)
		response, err := client.Get(url)

		// with task queues - things would look similar:
		// t     := taskqueue.NewPOSTTask("/_ah/namespaced-counters/queue-pop", m)
		// but we could not enforce each instance getting
		// one and exactly one message

		// xmpp chat messages have the same disadvantage
		// the handler is the same for all instances
		//    /_ah/xmpp/message/chat/

		if err != nil {
			aelog.Errorf(c, "  could not launch get request; %v", err)
		} else {
			defer response.Body.Close()
			contents, err := ioutil.ReadAll(response.Body)
			if err != nil {
				aelog.Errorf(c, "  could not read response; %v", err)
			}
			if ll > 2 {
				aelog.Infof(c, "%s\n", string(contents))
			}
		}

	}

}