skipcheck

TM1 client · Docs · Sessions and logins

Tm1SessionPool

import { Tm1SessionPool } from "@skipcheck/tm1-client";

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
const pool = Tm1SessionPool.builder(Tm1Session.builder().baseUrl("http://tm1:8010/api/v1/").basicAuth("service", secret))
  .idleTimeout(10 * 60_000)
  .build();
// Each time it's needed: the user's session, which logs in on its first request
const session = pool.session(Tm1Identity.impersonating(user));
return new CubeService(session).list();

  • 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.
  • close 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

Tm1SessionPool constructor@internal Made by Tm1SessionPoolBuilder.build.
builder staticA builder for a pool of sessions with these settings.
sessionThe session for identity (the pool's own credentials by default).
evictExpiredEvicts every session that has been idle too long or is too old.
statsWhat the pool holds and has done so far, for metrics.
closeCloses every session, including evicted ones still in their grace period, and refuses new ones.
[Symbol.asyncDispose]Closes the pool, for await using.
toStringThe pool, its service root and how many sessions it holds, for logs.

Tm1SessionPool

constructor
constructor( private readonly sessions: Tm1SessionBuilder, private readonly idleTimeout: number, private readonly maxAge: number, private readonly maxSize: number, private readonly closeGrace: number, private readonly sweepInterval: number, private readonly clock: Tm1Clock, )

@internal Made by Tm1SessionPoolBuilder.build.

builder

static
static builder(sessions: Tm1SessionBuilder): Tm1SessionPoolBuilder

A builder for a pool of sessions with these settings: server, credentials, timeouts and the rest. Each identity's session is built from a copy of them.

Parameters

sessions
the settings every session starts from; the pool keeps a copy

session

session(identity: Tm1Identity = Tm1Identity.serviceAccount()): Tm1Session

The session for identity (the pool's own credentials by default): the pool's, or a new one if it has none (or the one it had has expired). Sends nothing: a new session logs in on its first request.

Throws

Tm1SessionClosedException if the pool is closed

evictExpired

evictExpired(): void

Evicts every session that has been idle too long or is too old. Runs every sweepInterval on its own; call it to evict now.

stats

stats(): Tm1SessionPool.Stats

What the pool holds and has done so far, for metrics.

close

close(): Promise<void>

Closes every session, including evicted ones still in their grace period, and refuses new ones. Every call returns the same promise; a session that fails to close doesn't fail it.

[Symbol.asyncDispose]

[Symbol.asyncDispose](): Promise<void>

Closes the pool, for await using: the same as close.

toString

toString(): string

The pool, its service root and how many sessions it holds, for logs.