예제 #1
0
파일: urp.go 프로젝트: rpeer-denis/tcgl
// 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
파일: cells.go 프로젝트: rpeer-denis/tcgl
// 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
파일: web.go 프로젝트: rpeer-denis/tcgl
// 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
파일: cells.go 프로젝트: rpeer-denis/tcgl
// 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
파일: util.go 프로젝트: rpeer-denis/tcgl
// NewId generates an identifier based on the given parts.
func NewId(parts ...interface{}) Id {
	return Id(identifier.Identifier(parts...))
}