Class Tm1SessionPool
java.lang.Object
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 thanmaxAge, or the pool is overmaxSize(least recently used first). It's checked on eachsession(Tm1Identity)call and everysweepInterval. 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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilds aTm1SessionPool.static final recordWhat a pool holds and has done. -
Method Summary
Modifier and TypeMethodDescriptionstatic Tm1SessionPool.Builderbuilder(Tm1Session.Builder sessions) A builder for a pool of sessions with these settings: server, credentials, timeouts and the rest.reactor.core.publisher.Mono<Void> close()Closes every session, including evicted ones still in their grace period, and refuses new ones.voidEvicts every session that has been idle too long or is too old.session()The session for the pool's own credentials:session(Tm1Identity.serviceAccount()).session(Tm1Identity identity) The session foridentity: the pool's, or a new one if it has none (or the one it had has expired).stats()What the pool holds and has done so far, for metrics.
-
Method Details
-
builder
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
The session foridentity: 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
The session for the pool's own credentials:session(Tm1Identity.serviceAccount()).- Returns:
- the session
- Throws:
Tm1SessionClosedException- if the pool is closed
-
evictExpired
public void evictExpired()Evicts every session that has been idle too long or is too old. Runs everysweepIntervalon its own; call it to evict now. -
stats
What the pool holds and has done so far, for metrics.- Returns:
- a snapshot
-
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
-