func (c *commandStrategy) msgBroadcast() error { c.app.RWMutex.RLock() defer c.app.RWMutex.RUnlock() var id string content := c.body["content"] logging.Debug("Sending message broadcast from %s", c.app.Manifest.InstanceId) if id_, ok := getString(c.body, "id"); ok { id = id_ } else { return errors.New("No id found") } msg_archive.RecordMsg(c.app, id) toSend := make(jsonData) toSend["fromInstanceId"] = c.app.Manifest.InstanceId toSend["id"] = id toSend["content"] = content for _, cpb := range c.app.Manifest.Capabilities { for _, dep := range registry.GetDependents(cpb) { dep.Send("MSG_BROADCAST", toSend) } } return nil }
// send this message query to all targeted apps func (c *commandStrategy) msgQuery() error { c.app.RWMutex.RLock() defer c.app.RWMutex.RUnlock() logging.Debug("Processing query from %s", c.app.Manifest.InstanceId) mq, err := parseMsgQuery(c) if err != nil { return err } msg_archive.RecordMsg(c.app, mq.id) body := make(jsonData) body["fromInstanceId"] = c.app.Manifest.InstanceId body["id"] = mq.id body["priority"] = mq.priority body["data"] = mq.data body["instanceId"] = mq.instanceIds body["action"] = mq.action body["capability"] = mq.capability.Name // if this is an undirected query if len(mq.instanceIds) == 0 { // send to all providers of the capability for _, provider := range registry.GetProviders(mq.capability) { provider.Send("MSG_QUERY", body) } } else { // this is a directed query, send to all given instance ids for _, instName := range mq.instanceIds { if inst, ok := registry.GetInstance(instName); ok { inst.Send("MSG_QUERY", body) } } } return nil }