skipcheck

TM1 client · Docs · Sessions and logins

Tm1SessionPool

using Skipcheck.Tm1.Client.Session;

Sessions on one TM1 server, one per Tm1Identity, for applications that act on behalf of many users. In TM1 identity is the session, so the number of sessions grows with the number of users; the pool keeps that bounded.

// One pool for the application, built once
var pool = Tm1SessionPool
    .Builder(Tm1Session.Builder().BaseUrl("http://tm1:8010/api/v1/").BasicAuth("service", secret))
    .IdleTimeout(TimeSpan.FromMinutes(10))
    .Build();
// Each time it's needed: the user's session, which logs in on its first request
var session = pool.Session(Tm1Identity.Impersonating(user));
return new CubeService(session).ListAsync();

  • Get a session for each piece of work and don't keep it: the pool may evict it. Getting one never blocks and sends nothing; the session logs in on its first request.
  • Eviction happens when a session has been idle for IdleTimeout, is older than MaxAge, or the pool is over MaxSize (least recently used first). It's checked on each Session call and every SweepInterval. A session with a request running isn't idle, however long ago it was asked for.
  • An evicted session is closed after CloseGrace, or when the requests running on it have finished, if that's later: closing it would end them on TM1. The next request for that identity gets a new session.
  • CloseAsync closes every session at once, and the pool refuses new ones.
  • Nothing falls back: a refused identity fails, and the pool never uses another identity in its place.

Thread-safe. Stats reports what the pool holds and has done, for metrics; each eviction is also a tm1.session.pool.evict observation, tagged with its reason.

Members

Builder staticA pool building its sessions from sessions (copied.
SessionThe session for identity.
SessionThe service account's own session.
EvictExpiredEvicts the sessions that are idle or old now, as the sweep does.
StatsThe pool's counts now.
CloseAsyncCloses every session, held or waiting out its grace, and refuses more.
DisposeAsyncCloses the pool.
ToString

Builder

static
Tm1SessionPoolBuilder Builder(Tm1SessionBuilder sessions)

A pool building its sessions from sessions (copied: later changes to it don't reach the pool). Its authenticator is the service account's.

Session

Tm1Session Session(Tm1Identity identity)

The session for identity: the one held for it, unless that has expired, or a new one.

Throws

Tm1SessionClosedException
The pool is closed.

Session

Tm1Session Session()

The service account's own session.

EvictExpired

void EvictExpired()

Evicts the sessions that are idle or old now, as the sweep does.

Stats

Tm1SessionPoolStats Stats()

The pool's counts now.

CloseAsync

Task CloseAsync(CancellationToken cancellationToken = default)

Closes every session, held or waiting out its grace, and refuses more. A session that fails to close doesn't stop the others; closing twice closes once.

DisposeAsync

ValueTask DisposeAsync()

Closes the pool: CloseAsync.

ToString

string ToString()