func multiCastInstanceCacheChange(w http.ResponseWriter, r *http.Request, mkk string) { c := appengine.NewContext(r) ii := instance_mgt.Get(w, r, map[string]interface{}{}) /* 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 // note that Hostname already has VersionMajor and Module name as prefixed subdomains url := fmt.Sprintf("https://%v.%v/_ah/invalidate-instance-cache?mkk=%v&senderInstanceId=%v", i, ii.Hostname, mkk, ii.InstanceID) _ = url c.Infof(" 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 { c.Infof(" could not launch get request; %v", err) } else { defer response.Body.Close() contents, err := ioutil.ReadAll(response.Body) if err != nil { c.Infof(" could not read response; %v", err) } c.Infof("%s\n", string(contents)) } } }
func invalidate(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) ii := instance_mgt.Get(w, r, map[string]interface{}{}) mkk := r.FormValue("mkk") sii := r.FormValue("senderInstanceId") c.Infof(" %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)) } }