Class Tm1Session
- 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.
close()ends the TM1 session. Otherwise it stays open on the server, counting against its sessions, until it times out. - Any request.
execute(Tm1Request)andstream(Tm1Request)send 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));
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionasync()How often this view polls an async request's monitor, if it's async.batch()Starts a JSON$batch: itssessionis a view of this one (same sandbox and change set) whose requests are queued, andTm1SessionBatch.run()sends them together.static Tm1Session.Builderbuilder()A builder for a session on one TM1 server.reactor.core.publisher.Mono<Tm1Capabilities> What the server supports, from its own$metadata.The change set this view's writes are recorded in, if any.reactor.core.publisher.Mono<Void> close()Closes the TM1 session.reactor.core.publisher.Mono<Tm1Session> connect()Logs in now, rather than on the first request, and completes with this session.<T> reactor.core.publisher.Mono<T> execute(Tm1Request<T> request) Sends a request and reads its response: the entity or value forTm1Request.Response.SINGLE, the text forTm1Request.Response.TEXT, or nothing forTm1Request.Response.NONE.booleanisClosed()Whetherclose()has been called.sandbox()The sandbox this view's requests run in, if any.The service root, such ashttp://localhost:8010/api/v1/.reactor.core.publisher.Mono<Long> The TM1 session's ID, as listed inSessions.<T> reactor.core.publisher.Flux<T> stream(Tm1Request<T> request) Sends aTm1Request.Response.COLLECTIONrequest and streams its items as they're decoded, never holding the whole response.toString()reactor.core.publisher.Mono<Tm1Version> version()The server's product version, such as11.8.03500.6, read fromServer.ProductVersiononce per login.A view of this session whose requests TM1 runs asynchronously (OData'sPrefer: respond-async): each returns at once with a monitor, which the client polls everyeveryuntil the result is there, so a long process or chore never holds a request open for its whole run.withChangeSet(String id) A view of this session whose writes are recorded in change setid: each request gets TM1's!ChangeSetquery option, unless it sets its own, soUndoChangeSetcan revert them together.A view of this session whose requests run synchronously, as usual.A view of this session whose writes go into no change set.A view of this session whose requests run outside any sandbox, in base data.withSandbox(String name) A view of this session whose requests run in sandboxname: each gets TM1's!sandboxquery option, unless the request sets its own.
-
Method Details
-
builder
A builder for a session on one TM1 server.- Returns:
- a new builder
-
execute
Sends a request and reads its response: the entity or value forTm1Request.Response.SINGLE, the text forTm1Request.Response.TEXT, or nothing forTm1Request.Response.NONE. Logs in first if needed.TM1's errors arrive as
Tm1ApiException, failures below HTTP asTm1TransportException.- Type Parameters:
T- the type the response is read as- Parameters:
request- the request to send; not a collection request- Returns:
- the response, empty for
Tm1Request.Response.NONE, or anIllegalArgumentExceptionfor a collection request
-
stream
Sends aTm1Request.Response.COLLECTIONrequest and streams its items as they're decoded, never holding the whole response. Follows@odata.nextLinkif TM1 pages. ATm1Request.Response.BYTESrequest streams the body's buffers as they arrive.- Type Parameters:
T- the type of each item- Parameters:
request- the collection request to send- Returns:
- the items, or an
IllegalArgumentExceptionfor a request that isn't a collection request
-
version
The server's product version, such as11.8.03500.6, read fromServer.ProductVersiononce per login. Logs in first if needed.- Returns:
- the version
-
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 declaresTm1Request.requiresis checked against it before it's sent.- Returns:
- the capabilities
-
withSandbox
A view of this session whose requests run in sandboxname: each gets TM1's!sandboxquery 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 EMPTYand 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- ifnameis blank
-
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
Starts a JSON$batch: itssessionis a view of this one (same sandbox and change set) whose requests are queued, andTm1SessionBatch.run()sends them together.- Returns:
- the batch
-
withAsync
A view of this session whose requests TM1 runs asynchronously (OData'sPrefer: respond-async): each returns at once with a monitor, which the client polls everyeveryuntil 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 asTM1UserException: Cancel.Raw byte requests (document content) aren't sent async. TM1 (11.8) sends no
Retry-After, soeveryis the only pace.- Parameters:
every- how long to wait between polls of the monitor- Returns:
- the view
- Throws:
IllegalArgumentException- ifeveryisn't positive
-
withoutAsync
A view of this session whose requests run synchronously, as usual.- Returns:
- the view, or this session if it isn't async
-
async
-
sandbox
-
withChangeSet
A view of this session whose writes are recorded in change setid: each request gets TM1's!ChangeSetquery option, unless it sets its own, soUndoChangeSetcan revert them together. LikewithSandbox(String), the view shares this session's login and connections; it keeps the sandbox, if any.- Parameters:
id- the change set's ID, fromBeginChangeSet; not blank- Returns:
- a view of this session recording into that change set
- Throws:
IllegalArgumentException- ifidis blank
-
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
-
connect
Logs in now, rather than on the first request, and completes with this session.- Returns:
- this session, once logged in
-
sessionId
The TM1 session's ID, as listed inSessions. Logs in first if needed.- Returns:
- the session ID
-
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 withTm1SessionClosedException. Calling it again returns the same result.- Returns:
- completes once the session is closed
-
isClosed
-
serviceRoot
The service root, such ashttp://localhost:8010/api/v1/.- Returns:
- the service root, always ending in
/
-
toString
-