Example #1
0
// command performs a Redis command.
func (urp *unifiedRequestProtocol) command(rs *ResultSet, multi bool, command string, args ...interface{}) {
	m := monitoring.BeginMeasuring(identifier.Identifier("redis", "command", command))
	doneChan := make(chan bool)
	urp.commandChan <- &envCommand{rs, multi, command, args, doneChan}
	<-doneChan
	m.EndMeasuring()
}
Example #2
0
// handleFunc is the main function of the web server dispatching the
// requests to registered resource handler.
func handleFunc(rw http.ResponseWriter, r *http.Request) {
	ctx := newContext(rw, r)
	resources := srv.domains[ctx.Domain]
	if resources != nil {
		handlers := resources[ctx.Resource]
		if handlers != nil {
			m := monitoring.BeginMeasuring(identifier.Identifier("web", ctx.Domain, ctx.Resource, ctx.Request.Method))
			for _, h := range handlers {
				if !dispatch(ctx, h) {
					break
				}
			}
			m.EndMeasuring()
			return
		}
	}
	// No valid configuration, redirect to default (if not already).
	if ctx.Domain == srv.defaultDomain && ctx.Resource == srv.defaultResource {
		// No default handler registered.
		msg := fmt.Sprintf("domain '%v' and resource '%v' not found!", ctx.Domain, ctx.Resource)
		applog.Errorf(msg)
		http.Error(ctx.ResponseWriter, msg, http.StatusNotFound)
	} else {
		// Redirect to default handler.
		applog.Warningf("domain '%v' and resource '%v' not found, redirecting to default", ctx.Domain, ctx.Resource)
		ctx.Redirect(srv.defaultDomain, srv.defaultResource, "")
	}
}
Example #3
0
// process processes one event.
func (a *agentRunner) process(event Event) (err error) {
	// Error recovering.
	defer func() {
		if r := recover(); r != nil {
			applog.Errorf("agent %q has panicked: %v", a.agent.Id(), r)
			err = a.agent.Recover(r, event)
		}
	}()
	// Handle the event inside a measuring.
	measuring := monitoring.BeginMeasuring(a.measuringId)
	defer measuring.EndMeasuring()
	if err = a.agent.Process(event); err != nil {
		applog.Errorf("agent %q has failed: %v", a.agent.Id(), err)
		return a.agent.Recover(err, event)
	}
	return nil
}
Example #4
0
// process encapsulates event processing including error
// recovery and measuring.
func (c *cell) process(e Event) {
	// Error recovering.
	defer func() {
		if r := recover(); r != nil {
			if e != nil {
				applog.Errorf("cell %q has error '%v' with event '%+v'", c.id, r, EventString(e))

			} else {
				applog.Errorf("cell %q has error '%v'", c.id, r)
			}
			c.behavior.Recover(r, e)
		}
	}()
	defer e.Context().decrActivity()
	// Handle the event inside a measuring.
	measuring := monitoring.BeginMeasuring(c.measuringId)
	emitter := &cellEventEmitter{c.subscribers, e.Context()}
	c.behavior.ProcessEvent(e, emitter)
	measuring.EndMeasuring()
}