Beispiel #1
0
func (mh *mcpHandler) HandleClientInput(s string) error {
	m, err := mh.client.router.MCP(mh.user.Resource)
	if err != nil {
		return err
	}
	var merr *messages.Error
	if err := m.Call(mh.user.Resource, mh.user.Resource, "HandleClientInput", []string{s}, &[]interface{}{&merr}); err != nil {
		return err
	}
	return merr.ToErr()
}
Beispiel #2
0
func (r *Router) Decomission(resourceId string) (bool, error) {
	r.handlerLock.RLock()
	hd, found := r.handlerDataByResource[resourceId]
	r.handlerLock.RUnlock()
	if found {
		m, err := r.MCP(resourceId)
		if err != nil {
			return false, err
		}
		var sd *messages.ShortDesc
		var merr *messages.Error
		if err := m.Call(resourceId, resourceId, messages.MethodGetShortDesc, nil, &[]interface{}{&sd, &merr}); err != nil {
			return false, err
		}
		if merr != nil {
			return false, merr.ToErr()
		}
		r.handlerLock.Lock()
		if err := func() error {
			defer r.handlerLock.Unlock()
			hd, found = r.handlerDataByResource[resourceId]
			if found {
				res := &resource.Resource{}
				if err := r.persister.Get(resourceId, res); err != nil {
					return err
				}
				if _, err := hd.m.Destruct(resourceId); err != nil {
					return err
				}
				go r.Broadcast(res.Container, &messages.Event{
					Type:            messages.EventTypeDestruct,
					Source:          resourceId,
					SourceShortDesc: sd,
				})
				delete(r.handlerDataByResource, resourceId)
				if hd.m.Count() == 0 {
					if err := hd.m.Stop(); err != nil {
						return err
					}
					delete(r.handlerByOwnerCode, hd.oc)
				}
			}
			return nil
		}(); err != nil {
			return false, err
		}
	}
	return found, nil
}