Tm1Session
import io.skipcheck.tm1.client.session.Tm1Session;Used in the walkthroughs Connect and list your cubes, Test your code against a real TM1, Add TM1 to a Spring Boot application.
One TM1 session, shared by every service. Thread-safe, and safe to share between any number of concurrent callers: TM1 runs requests on one session in parallel.
- Login is lazy and happens once. The first request logs in, and concurrent first requests share that login. Only the login carries the credentials; every other request carries just the session cookie, since a request with credentials and no cookie makes TM1 open another session.
- Close it.
closeends the TM1 session. Otherwise it stays open on the server, counting against its sessions, until it times out. - Any request.
executeandstreamsend anyTm1Request, so anything the services don't cover yet is still reachable.
Build a session with CAM security and a label:
// CAM security, with a label that shows in Sessions and Threads
return Tm1Session.builder()
.address("https://tm1.example.com:8010")
.authenticator(Tm1Authenticator.camNamespace("alice", password, "LDAP"))
.sessionContext("Sales planning")
.build();
Or log in with a CAM passport, such as one from exchanging an OIDC token with Cognos:
// CAM passports expire, so the session asks for a current one on every login
return Tm1Session.builder()
.address("https://tm1.example.com:8010")
.authenticator(Tm1Authenticator.camPassport(cognos))
.build();
Send a request no service covers yet, here streaming a collection:
// GET MessageLogEntries, which has no service yet: the latest 20 entries
return session.stream(Tm1Request.list(ODataPath.of("MessageLogEntries"),
ODataQuery.none().orderByDescending(MessageLogEntry.TIME_STAMP).top(20), MessageLogEntry.class));
Run a service's requests in a sandbox by giving it a sandbox view of the session:
// The cell: every dimension, in the cube's order
Map<String, String> cell = new LinkedHashMap<>();
cell.put("Region", "North");
cell.put("Month", "Jan");
return new SandboxService(session).create(SandboxPatch.builder().name("What-if").build())
.then(new CellService(session.withSandbox("What-if")).update("Sales", cell, 1200));
Members
builder static | A builder for a session on one TM1 server. |
execute | Sends a request and reads its response. |
stream | Sends a Tm1Request.Response.COLLECTION request and streams its items as they're decoded, never holding the whole response. |
version | The server's product version, such as 11.8.03500.6, read from Server.ProductVersion once per login. |
capabilities | What the server supports, from its own $metadata. |
withSandbox | A view of this session whose requests run in sandbox name. |
withoutSandbox | A view of this session whose requests run outside any sandbox, in base data. |
batch | Starts a JSON $batch. |
withAsync | A view of this session whose requests TM1 runs asynchronously (OData's Prefer. |
withoutAsync | A view of this session whose requests run synchronously, as usual. |
async | How often this view polls an async request's monitor, if it's async. |
sandbox | The sandbox this view's requests run in, if any. |
withChangeSet | A view of this session whose writes are recorded in change set id. |
withoutChangeSet | A view of this session whose writes go into no change set. |
changeSet | The change set this view's writes are recorded in, if any. |
connect | Logs in now, rather than on the first request, and completes with this session. |
sessionId | The TM1 session's ID, as listed in Sessions. |
close | Closes the TM1 session. |
isClosed | Whether close has been called. |
serviceRoot | The service root, such as http://localhost:8010/api/v1/. |
toString |
builder
staticstatic Tm1Session.Builder builder()A builder for a session on one TM1 server.
Returns
- a new builder
execute
<T> Mono<T> execute(Tm1Request<T> request) Sends a request and reads its response: the entity or value for
Tm1Request.Response.SINGLE, the text for Tm1Request.Response.TEXT,
or nothing for Tm1Request.Response.NONE. Logs in first if needed.
TM1's errors arrive as Tm1ApiException,
failures below HTTP as Tm1TransportException.
Parameters
request- the request to send; not a collection request
Returns
- the response, empty for
Tm1Request.Response.NONE, or anIllegalArgumentExceptionfor a collection request
stream
<T> Flux<T> stream(Tm1Request<T> request) Sends a Tm1Request.Response.COLLECTION request and streams its items as
they're decoded, never holding the whole response. Follows @odata.nextLink
if TM1 pages. A Tm1Request.Response.BYTES request streams the body's
buffers as they arrive.
Parameters
request- the collection request to send
Returns
- the items, or an
IllegalArgumentExceptionfor a request that isn't a collection request
version
Mono<Tm1Version> version() The server's product version, such as 11.8.03500.6, read from
Server.ProductVersion once per login. Logs in first if needed.
Returns
- the version
capabilities
Mono<Tm1Capabilities> capabilities() What the server supports, from its own $metadata. Fetched once per server
version and shared by every session built from the same settings, a pool's
included. A request that declares Tm1Request.requires is checked against it
before it's sent.
Returns
- the capabilities
withSandbox
Tm1Session withSandbox(String name) A view of this session whose requests run in sandbox name: each gets TM1's
!sandbox query option, unless the request sets its own. The view shares
this session's login, cookie and connections, so it costs nothing; closing either
closes both.
Derived rather than set on the session, so one caller's sandbox can't leak into
another caller's requests. TM1 evaluates NON EMPTY and filters in the
request's sandbox, so every request of an operation needs it, cellset reads and
deletes included; a service given this view gets that for free.
Parameters
name- the sandbox's name; not blank
Returns
- a view of this session in that sandbox
Throws
IllegalArgumentException- if
nameis blank
withoutSandbox
Tm1Session withoutSandbox()A view of this session whose requests run outside any sandbox, in base data.
Returns
- the view, or this session if it has no sandbox
batch
Tm1SessionBatch batch() Starts a JSON $batch: its session is a
view of this one (same sandbox and change set) whose requests are queued, and
Tm1SessionBatch.run sends them together.
Returns
- the batch
withAsync
Tm1Session withAsync(Duration every) A view of this session whose requests TM1 runs asynchronously (OData's
Prefer: respond-async): each returns at once with a monitor, which the
client polls every every until the result is there, so a long process or
chore never holds a request open for its whole run. Methods return what they always
do. Cancelling the subscription before the result deletes the monitor, which stops
the work on TM1: a process run ends as TM1UserException: Cancel.
Raw byte requests (document content) aren't sent async. TM1 (11.8) sends no
Retry-After, so every is the only pace.
Parameters
every- how long to wait between polls of the monitor
Returns
- the view
Throws
IllegalArgumentException- if
everyisn't positive
withoutAsync
Tm1Session withoutAsync()A view of this session whose requests run synchronously, as usual.
Returns
- the view, or this session if it isn't async
async
Optional<Duration> async()How often this view polls an async request's monitor, if it's async.
Returns
- the interval, or empty for a synchronous view
sandbox
Optional<String> sandbox()The sandbox this view's requests run in, if any.
Returns
- the sandbox's name, or empty for base data
withChangeSet
Tm1Session withChangeSet(String id) A view of this session whose writes are recorded in change set id: each
request gets TM1's !ChangeSet query option, unless it sets its own, so
UndoChangeSet can revert them together. Like withSandbox, the view
shares this session's login and connections; it keeps the sandbox, if any.
Parameters
id- the change set's ID, from
BeginChangeSet; not blank
Returns
- a view of this session recording into that change set
Throws
IllegalArgumentException- if
idis blank
withoutChangeSet
Tm1Session withoutChangeSet()A view of this session whose writes go into no change set.
Returns
- the view, or this session if it has no change set
changeSet
Optional<String> changeSet()The change set this view's writes are recorded in, if any.
Returns
- the change set's ID, or empty
connect
Mono<Tm1Session> connect()Logs in now, rather than on the first request, and completes with this session.
Returns
- this session, once logged in
sessionId
Mono<Long> sessionId() The TM1 session's ID, as listed in Sessions. Logs in first if needed.
Returns
- the session ID
close
Mono<Void> close() Closes the TM1 session. A login in progress is waited for and then closed, so a
close that races the first request can't leave a session open. If no login ever
started, nothing is sent. Afterwards every request fails with
Tm1SessionClosedException. Calling it again returns the same result.
Returns
- completes once the session is closed
isClosed
boolean isClosed() Whether close has been called.
Returns
trueonce closed
serviceRoot
String serviceRoot() The service root, such as http://localhost:8010/api/v1/.
Returns
- the service root, always ending in
/
toString
String toString()Also in the Javadoc.