Skip to content

Commit 14280e7

Browse files
authored
Add javadocs (mostly) (#210)
Also clarify an exception and remove a dead file.
1 parent 7519d8e commit 14280e7

14 files changed

Lines changed: 142 additions & 133 deletions

transact/src/main/java/dev/dbos/transact/context/DBOSContextHolder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package dev.dbos.transact.context;
22

33
public class DBOSContextHolder {
4-
// CB: I think this default ctor business will bite us.
54
private static final ThreadLocal<DBOSContext> contextHolder =
65
ThreadLocal.withInitial(DBOSContext::new);
76

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
package dev.dbos.transact.context;
22

3+
/**
4+
* Contains identifying information about the parent of a workflow.
5+
*
6+
* <p>If provided, this record encapsulates the parent's workflow id and the calling step number
7+
* that started the workflow.
8+
*
9+
* @param workflowId The unique id for the parent workflow.
10+
* @param functionId The step number within the parent workflow that created the child.
11+
*/
312
public record WorkflowInfo(String workflowId, int functionId) {}

transact/src/main/java/dev/dbos/transact/database/ExternalState.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@
44
import java.math.BigInteger;
55
import java.util.Objects;
66

7+
/**
8+
* Represents a piece of state associated with an external service such as an event dispatcher.
9+
*
10+
* <p>This record models a key/value entry stored by the DBOS system database on behalf of an
11+
* external service It includes identifying information (service name, fully qualified workflow
12+
* name, key within), a value, and optional metadata for versioning the update.
13+
*
14+
* <p>The canonical constructor enforces that {@code service}, {@code workflowName}, and {@code key}
15+
* are non-null.
16+
*
17+
* @param service The name of the external service that owns or stores the state.
18+
* @param workflowName The fully qualified function name of the workflow that this state belongs to.
19+
* @param key The key under which the external state is stored, allowing multiple values per service
20+
* and workflow combination.
21+
* @param value The current value associated with the key.
22+
* @param updateTime The timestamp of the last update, represented as a decimal (e.g., UNIX epoch
23+
* seconds), or {@code null} if unused.
24+
* @param updateSeq A monotonic sequence number for updates, used to detect the latest version, or
25+
* {@code null} if not applicable.
26+
*/
727
public record ExternalState(
828
String service,
929
String workflowName,
@@ -18,18 +38,40 @@ public record ExternalState(
1838
Objects.requireNonNull(key, "key must not be null");
1939
}
2040

41+
/**
42+
* Create an external state
43+
*
44+
* @param service service storing the state
45+
* @param workflowName fully qualified name of the workflow storine for which the state applies
46+
* @param key key allowing multiple values to be stored per service per workflow
47+
*/
2148
public ExternalState(String service, String workflowName, String key) {
2249
this(service, workflowName, key, null, null, null);
2350
}
2451

52+
/**
53+
* Create an {@code ExternalState} like this one, but with a new value
54+
*
55+
* @param value
56+
*/
2557
public ExternalState withValue(String value) {
2658
return new ExternalState(service, workflowName, key, value, updateTime, updateSeq);
2759
}
2860

61+
/**
62+
* Create an {@code ExternalState} like this one, but with a new update time
63+
*
64+
* @param updateTime update time to use, as a decimal number of seconds since the Unix epoch
65+
*/
2966
public ExternalState withUpdateTime(BigDecimal updateTime) {
3067
return new ExternalState(service, workflowName, key, value, updateTime, updateSeq);
3168
}
3269

70+
/**
71+
* Create an {@code ExternalState} like this one, but with a new sequence number
72+
*
73+
* @param updateSeq sequence number to use
74+
*/
3375
public ExternalState withUpdateSeq(BigInteger updateSeq) {
3476
return new ExternalState(service, workflowName, key, value, updateTime, updateSeq);
3577
}

transact/src/main/java/dev/dbos/transact/database/UpdateWorkflowOptions.java

Lines changed: 0 additions & 125 deletions
This file was deleted.

transact/src/main/java/dev/dbos/transact/exceptions/DBOSAwaitedWorkflowCancelledException.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package dev.dbos.transact.exceptions;
22

3+
/**
4+
* {@code DBOSAwaitedWorkflowCancelledException} is thrown by DBOS when a call requests the return
5+
* value of a workflow that was cancelled.
6+
*
7+
* <p>Calls such as {@code DBOS.getResult} and {@code WorkflowHandle.getResult} may throw this
8+
* exception.
9+
*/
310
public class DBOSAwaitedWorkflowCancelledException extends RuntimeException {
411
private String workflowId;
512

@@ -8,6 +15,7 @@ public DBOSAwaitedWorkflowCancelledException(String workflowId) {
815
this.workflowId = workflowId;
916
}
1017

18+
/** The workflow ID of the awaited, cancelled workflow */
1119
public String workflowId() {
1220
return workflowId;
1321
}

transact/src/main/java/dev/dbos/transact/exceptions/DBOSConflictingWorkflowException.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
package dev.dbos.transact.exceptions;
22

3+
/**
4+
* {@code DBOSConflictingWorkflowException} is thrown by DBOS when an attempt is made to start a
5+
* workflow, a workflow with that ID that already exists, and the existing workflow is incompatible
6+
* with the attempted workflow initiation.
7+
*
8+
* <p>{@code DBOSConflictingWorkflowException} generally indicates a programmer error, such as
9+
* attempting to invoke two entirely different workflow functions with the same workflow ID.
10+
*
11+
* <p>Direct workflow invocation, workflow enqueue, and {@code DBOS.startWorkflow} may throw this
12+
* exception.
13+
*/
314
public class DBOSConflictingWorkflowException extends RuntimeException {
415
private final String workflowId;
516

@@ -8,6 +19,7 @@ public DBOSConflictingWorkflowException(String workflowId, String msg) {
819
this.workflowId = workflowId;
920
}
1021

22+
/** The workflow ID that already exists, with a conflicting invocation */
1123
public String workflowId() {
1224
return this.workflowId;
1325
}

transact/src/main/java/dev/dbos/transact/exceptions/DBOSMaxRecoveryAttemptsExceededException.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package dev.dbos.transact.exceptions;
22

3+
/**
4+
* {@code DBOSMaxRecoveryAttemptsExceededException} is thrown when workflow recovery is attempted,
5+
* but the maximum number of recovery attempts have already been made.
6+
*/
37
public class DBOSMaxRecoveryAttemptsExceededException extends RuntimeException {
48

59
private String workflowId;
@@ -12,10 +16,14 @@ public DBOSMaxRecoveryAttemptsExceededException(String workflowId, int maxRetrie
1216
workflowId, maxRetries));
1317
}
1418

19+
/**
20+
* The ID of the workflow for which a maximum number of recovery attempts have already been made
21+
*/
1522
public String workflowId() {
1623
return workflowId;
1724
}
1825

26+
/** The number of retries allowed */
1927
public int maxRetries() {
2028
return maxRetries;
2129
}

transact/src/main/java/dev/dbos/transact/exceptions/DBOSNonExistentWorkflowException.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
package dev.dbos.transact.exceptions;
22

3+
/**
4+
* {@code DBOSNonExistentWorkflowException} is thrown by DBOS functions such as `send` or
5+
* `executeWorkflowById` that require a workflow to exist prior to invocation.
6+
*
7+
* <p>Unless the workflow ID was taken from the user, receipt of this error generally indicates a
8+
* programmer error.
9+
*/
310
public class DBOSNonExistentWorkflowException extends RuntimeException {
411
private String workflowId;
512

@@ -8,6 +15,7 @@ public DBOSNonExistentWorkflowException(String workflowId) {
815
this.workflowId = workflowId;
916
}
1017

18+
/** ID of the workflow that was targeted, but did not exist */
1119
public String workflowId() {
1220
return workflowId;
1321
}

transact/src/main/java/dev/dbos/transact/exceptions/DBOSQueueDuplicatedException.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package dev.dbos.transact.exceptions;
22

3+
/**
4+
* {@code DBOSQueueDuplicatedException} is thrown when an attempt is made to enqueue a workflow into
5+
* a queue with deduplication. DBOSQueueDuplicatedException is thrown to indicate that a queued
6+
* workflow with this `deduplicationId` already exists.
7+
*/
38
public class DBOSQueueDuplicatedException extends RuntimeException {
49
private final String workflowId;
510
private final String queueName;
@@ -15,14 +20,20 @@ public DBOSQueueDuplicatedException(String workflowId, String queueName, String
1520
this.deduplicationId = deduplicationId;
1621
}
1722

23+
/** ID of the workflow for which enqueue was attempted (This is not the existing workflow ID) */
1824
public String workflowId() {
1925
return workflowId;
2026
}
2127

28+
/** The name of the queue into which enqueueing was attempted */
2229
public String queueName() {
2330
return queueName;
2431
}
2532

33+
/**
34+
* The deduplication ID within the queue; a workflow with this deduplication ID was already
35+
* enqueued.
36+
*/
2637
public String deduplicationId() {
2738
return deduplicationId;
2839
}

transact/src/main/java/dev/dbos/transact/exceptions/DBOSSystemDatabaseException.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
import java.sql.SQLException;
44

5+
/**
6+
* This exception is thrown by DBOS when the system database cannot be reached, despite numerous
7+
* retries. Handling this exception is unlikely to end well. A new execution should be started once
8+
* system database connectivity is restored.
9+
*/
510
public class DBOSSystemDatabaseException extends RuntimeException {
611
Throwable underlyingException;
712

@@ -14,6 +19,7 @@ public DBOSSystemDatabaseException(Throwable e) {
1419
this.underlyingException = e;
1520
}
1621

22+
/** A recent exception received from the system database connection */
1723
public Throwable databaseException() {
1824
return underlyingException;
1925
}

0 commit comments

Comments
 (0)