skipcheck

TM1 client · Docs · Sessions and logins

Tm1SessionPool

import io.skipcheck.tm1.client.session.Tm1SessionPool;

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

  • 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

builder staticA builder for a pool of sessions with these settings.
sessionThe session for identity.
sessionThe session for the pool's own credentials.
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.

builder

static
static Tm1SessionPool.Builder builder(Tm1Session.Builder sessions)

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

Returns

a new builder

session

Tm1Session session(Tm1Identity identity)

The session for identity: 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.

Parameters

identity
who the session is for

Returns

the session

Throws

Tm1SessionClosedException
if the pool is closed

session

Tm1Session session()

The session for the pool's own credentials: session(Tm1Identity.serviceAccount()).

Returns

the session

Throws

Tm1SessionClosedException
if the pool is closed

evictExpired

void evictExpired()

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

Tm1SessionPool.Stats stats()

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

Returns

a snapshot

close

Mono<Void> close()

Closes every session, including evicted ones still in their grace period, and refuses new ones. Every call returns the same result.

Returns

completes when every session is closed

Also in the Javadoc.