Submit an observation from Java

Use a twin that already contains an individual subject with geometry, such as a study region. Choose a quality offered by the loaded worldview and by a model with coverage for that subject. The example reopens an existing twin and makes an observation under your user identity. The submission creates or reuses a result in that twin.

Locate the twin and subject

Use the service ID shown by your selected Runtime. From the example project directory, replace the uppercase arguments with identifiers from your deployment.

mvn compile exec:java "-Dexec.args=RUNTIME_ID"
mvn compile exec:java "-Dexec.args=RUNTIME_ID TWIN_ID"

The first command lists accessible twin IDs and names. The second gets the saved twin configuration from that Runtime, connects using the user scope, and lists root observations. You can also obtain a subject ID from the twin's inspector. Use a committed individual subject from the same twin. Child subjects can be selected by ID even if the root list shows only their enclosing observation.

Copy the confirmed quality declaration from the Modeler composer. Pass it as one argument. For a worldview defining earth:Elevation, the invocation can take this form:

mvn compile exec:java "-Dexec.args=RUNTIME_ID TWIN_ID SUBJECT_ID 'earth:Elevation in m'"

From declaration to result

The sample looks up the subject with twin.getObservation(subjectId), checks its type and geometry, and derives twin.within(subject). The Reasoner interprets the declaration in that scope. The central submission is:

var context = twin.within(subject);
var quality = context.getService(Reasoner.class).resolveObservable(declaration);
var submission = context.observation(quality)
        .geometry(subject.getGeometry())
        .submit();

Use the full example for input checks, authentication, startup and cleanup. The returned CompletableFuture<Observation> can complete with a valid observation, an empty observation carrying notifications, or an exception. Inspect notifications before consuming the result. A caller-side timeout stops the wait. Check the Runtime activity before retrying because the original work may still complete. Complete example

For a successful submission, record the returned observation ID and twin ID. Reopen that observation in Modeler to inspect its geometry, time state and provenance. Reused observations can satisfy a request, so a successful call does not imply a new data acquisition. Read the result

Create a working twin when needed

In an authenticated application with a selected operational RuntimeService runtime and UserScope user, the session creates a new context. This follows the Modeler creation path:

var configuration = DigitalTwin.Configuration.builder()
        .name("Elevation study")
        .serverUrl(runtime.getUrl())
        .serviceId(runtime.serviceId())
        .accessRights(ResourcePrivileges.create(user))
        .persistence(Persistence.IDLE_TIMEOUT)
        .build();
var context = user.getUserSession(runtime).createContext(configuration);

The builder is in org.integratedmodelling.klab.api.digitaltwin.DigitalTwin, persistence in org.integratedmodelling.klab.api.scope.Persistence, and the access-rights class is org.integratedmodelling.klab.api.authentication.ResourcePrivileges. Check the returned context and its ID before continuing. A new twin still needs a suitable observation or extent for meaningful work.

Manage scope lifetime

Treat closing a context as a Runtime lifecycle operation. In the reference client, ClientContextScope.close() can request release from the hosting Runtime. Use the hosting application's lifecycle for a shared context. The standalone example finishes its application-owned Engine with shutdown() and does not explicitly close the shared twin. Use deliberate deletion through an authorized workflow when the data should actually be removed.