Пример #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()
}
Пример #2
0
// processLoop is the backend for the processing of events.
func (c *cell) processLoop() {
	for {
		message := c.queue.pull()
		switch {
		case message.event != nil:
			// Process the event.
			c.process(message.event)
		case message.cells != nil:
			// Change the subscriptions.
			for id, sc := range message.cells {
				if message.add {
					c.subscribers[id] = sc
				} else {
					delete(c.subscribers, id)
				}
			}
		case message.event == nil && message.cells == nil:
			// Stop the cell.
			c.queue.close()
			break
		}
	}
	monitoring.DecrVariable(c.measuringId)
	monitoring.DecrVariable(identifier.Identifier("cells", c.env.id, "total-cells"))
	c.behavior.Stop()
}
Пример #3
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, "")
	}
}
Пример #4
0
// newCell create a new cell around a behavior.
func newCell(env *Environment, id Id, b Behavior) (*cell, error) {
	c := &cell{
		env:         env,
		id:          id,
		behavior:    b,
		subscribers: make(cellMap),
		queue:       newCellMessageQueue(),
		measuringId: identifier.Identifier("cells", env.id, "cell", identifier.TypeAsIdentifierPart(b)),
	}
	// Init behavior.
	if err := b.Init(env, id); err != nil {
		return nil, CellInitError{id, err}
	}
	go c.processLoop()
	monitoring.IncrVariable(identifier.Identifier("cells", c.env.id, "total-cells"))
	monitoring.IncrVariable(c.measuringId)
	return c, nil
}
Пример #5
0
// NewId generates an identifier based on the given parts.
func NewId(parts ...interface{}) Id {
	return Id(identifier.Identifier(parts...))
}