// See ManagedHandle for documentation.
323818
func (c *managedHandleImpl) ReleaseUnderlyingHandle() interface{} {
	if atomic.CompareAndSwapInt32(&c.isActive, 1, 0) {
		return c.handle
	}
	return nil
}
1309277
func (d *Driver) GetHandle(taskID string) *taskHandle {
	h, _ := d.tasks.Get(taskID)
	return h
}
33114
func (l *Limiter) WrapHandle(h http.Handler) {
	l.rateLimiter.Wrap(h)
	l.ConnLimiter.Wrap(l.rateLimiter)
}
811596
func (m *Method) PostHandle(handler Handler) *Method {
	m.postHandlers = append(m.postHandlers, handler)
	return m
}
737221
func AccessHandler(f func(r *http.Request, status, size int, duration time.Duration)) func(next http.Handler) http.Handler {
	return func(next http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			start := time.Now()
			lw := mutil.WrapWriter(w)
			next.ServeHTTP(lw, r)
			f(r, lw.Status(), lw.BytesWritten(), time.Since(start))
		})
	}
}
165002
func (m *Module) DefaultHandle500(rw http.ResponseWriter, req *http.Request, err error) {
	m.Logger.Errorf("%s: %s", req.URL, err)
	http.Error(rw, "internal server error", http.StatusInternalServerError)
}
864439
func NewHandle(nlFamilies ...int) (*Handle, error) {
	return newHandle(netns.None(), netns.None(), nlFamilies...)
}
454309
func (k *Kite) HandleFunc(method string, handler HandlerFunc) *Method {
	return k.addHandle(method, handler)
}
528246
func (provider *VersionedDBProvider) GetDBHandle(dbName string) (statedb.VersionedDB, error) {
	provider.mux.Lock()
	defer provider.mux.Unlock()
	vdb := provider.databases[dbName]
	if vdb == nil {
		var err error
		vdb, err = newVersionedDB(provider.couchInstance, dbName)
		if err != nil {
			return nil, err
		}
		provider.databases[dbName] = vdb
	}
	return vdb, nil
}
16110
func (exchange *Exchange) getHandle(topic Topic) (Handle, error) {
	overflow := exchange.nextHandle - 1
	for next := exchange.nextHandle; next != overflow; next++ {
		if _, ok := exchange.topicForHandle[next]; !ok {
			exchange.nextHandle = next + 1
			exchange.topicForHandle[next] = topic
			return next, nil
		}
	}
	return 0, ErrHandlesDepleted
}
1125857
func (do *Domain) StatsHandle() *handle.Handle {
	return (*handle.Handle)(atomic.LoadPointer(&do.statsHandle))
}
207133
func (j journalMDOps) GetIDForHandle(
	ctx context.Context, handle *tlfhandle.Handle) (id tlf.ID, err error) {
	id, err = j.MDOps.GetIDForHandle(ctx, handle)
	if err != nil {
		return tlf.NullID, err
	}
	if id == tlf.NullID {
		return id, nil
	}
	// Create the journal if needed, while we have access to `handle`.
	_, _ = j.jManager.getTLFJournal(id, handle)
	return id, nil
}
382715
func (k *Kite) addHandle(method string, handler Handler) *Method {
	authenticate := true
	if k.Config.DisableAuthentication {
		authenticate = false
	}

	m := &Method{
		name:         method,
		handler:      handler,
		authenticate: authenticate,
		handling:     k.MethodHandling,
	}

	k.handlers[method] = m
	return m
}
940749
func (c ConstIDGetter) GetIDForHandle(_ context.Context, _ *Handle) (
	tlf.ID, error) {
	return c.ID, nil
}
96000
func (m *PathRecorderMux) UnlistedHandle(path string, handler http.Handler) {
	m.lock.Lock()
	defer m.lock.Unlock()
	m.trackCallers(path)

	m.pathToHandler[path] = handler
	m.refreshMuxLocked()
}
317940
func NewHandle(app string, ds datastore.DataStore, id string, numElements uint64) (*Handle, error) {
	h := &Handle{
		app:        app,
		id:         id,
		store:      ds,
		bits:       numElements,
		unselected: numElements,
		head: &sequence{
			block: 0x0,
			count: getNumBlocks(numElements),
		},
	}

	if h.store == nil {
		return h, nil
	}

	// Get the initial status from the ds if present.
	if err := h.store.GetObject(datastore.Key(h.Key()...), h); err != nil && err != datastore.ErrKeyNotFound {
		return nil, err
	}

	// If the handle is not in store, write it.
	if !h.Exists() {
		if err := h.writeToStore(); err != nil {
			return nil, fmt.Errorf("failed to write bitsequence to store: %v", err)
		}
	}

	return h, nil
}
1343887
func HandleCommand(helper Helper, key string, in io.Reader, out io.Writer) error {
	switch key {
	case "store":
		return Store(helper, in)
	case "get":
		return Get(helper, in, out)
	case "erase":
		return Erase(helper, in)
	case "list":
		return List(helper, out)
	case "version":
		return PrintVersion(out)
	}
	return fmt.Errorf("Unknown credential action `%s`", key)
}