Skip to content

Commit b070cbf

Browse files
ehsavoieclaude
andcommitted
docs: Add comprehensive javadoc to server-common module
- Fix @param error in PushNotificationConfigStore (blocking javadoc build) - Add complete javadoc to EventQueue and all public/protected members - Add javadoc to EventEnqueueHook, EventQueueClosedException - Add javadoc to TaskStore, JSONRPCException, NoTaskQueueException - Add javadoc to InMemoryTaskStore, Internal annotation - Fix typo in PushNotificationConfigStore ("emty" -> "empty") Reduces javadoc errors from 1 to 0 and warnings from 101 to 100. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
1 parent b741fd5 commit b070cbf

File tree

9 files changed

+251
-2
lines changed

9 files changed

+251
-2
lines changed

server-common/src/main/java/io/a2a/server/JSONRPCException.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,30 @@
22

33
import io.a2a.spec.JSONRPCError;
44

5+
/**
6+
* Exception wrapper for JSON-RPC protocol errors.
7+
* <p>
8+
* This exception encapsulates a {@link JSONRPCError} for handling
9+
* protocol-level errors during JSON-RPC request processing.
10+
* </p>
11+
*/
512
public class JSONRPCException extends Exception{
613
private final JSONRPCError error;
714

15+
/**
16+
* Creates a JSONRPCException wrapping the specified error.
17+
*
18+
* @param error the JSON-RPC error
19+
*/
820
public JSONRPCException(JSONRPCError error) {
921
this.error = error;
1022
}
1123

24+
/**
25+
* Returns the wrapped JSON-RPC error.
26+
*
27+
* @return the JSON-RPC error
28+
*/
1229
public JSONRPCError getError() {
1330
return error;
1431
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
package io.a2a.server.events;
22

3+
/**
4+
* Hook interface for event queue enqueue operations.
5+
* Implementations can be notified when items are enqueued to the event queue,
6+
* allowing for custom behavior such as event replication or logging.
7+
*/
38
public interface EventEnqueueHook {
9+
/**
10+
* Called when an item is enqueued to the event queue.
11+
*
12+
* @param item the event queue item being enqueued
13+
*/
414
void onEnqueue(EventQueueItem item);
515
}

server-common/src/main/java/io/a2a/server/events/EventQueue.java

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,50 @@
1616
import org.slf4j.Logger;
1717
import org.slf4j.LoggerFactory;
1818

19+
/**
20+
* Abstract base class for event queues that manage task event streaming.
21+
* <p>
22+
* An EventQueue provides a thread-safe mechanism for enqueueing and dequeueing events
23+
* related to task execution. It supports backpressure through semaphore-based throttling
24+
* and hierarchical queue structures via MainQueue and ChildQueue implementations.
25+
* </p>
26+
* <p>
27+
* Use {@link #builder()} to create configured instances or extend MainQueue/ChildQueue directly.
28+
* </p>
29+
*/
1930
public abstract class EventQueue implements AutoCloseable {
2031

2132
private static final Logger LOGGER = LoggerFactory.getLogger(EventQueue.class);
2233

34+
/**
35+
* Default maximum queue size for event queues.
36+
*/
2337
public static final int DEFAULT_QUEUE_SIZE = 1000;
2438

2539
private final int queueSize;
40+
/**
41+
* Internal blocking queue for storing event queue items.
42+
*/
2643
protected final BlockingQueue<EventQueueItem> queue = new LinkedBlockingDeque<>();
44+
/**
45+
* Semaphore for backpressure control, limiting the number of pending events.
46+
*/
2747
protected final Semaphore semaphore;
2848
private volatile boolean closed = false;
2949

50+
/**
51+
* Creates an EventQueue with the default queue size.
52+
*/
3053
protected EventQueue() {
3154
this(DEFAULT_QUEUE_SIZE);
3255
}
3356

57+
/**
58+
* Creates an EventQueue with the specified queue size.
59+
*
60+
* @param queueSize the maximum number of events that can be queued
61+
* @throws IllegalArgumentException if queueSize is less than or equal to 0
62+
*/
3463
protected EventQueue(int queueSize) {
3564
if (queueSize <= 0) {
3665
throw new IllegalArgumentException("Queue size must be greater than 0");
@@ -40,6 +69,11 @@ protected EventQueue(int queueSize) {
4069
LOGGER.trace("Creating {} with queue size: {}", this, queueSize);
4170
}
4271

72+
/**
73+
* Creates an EventQueue as a child of the specified parent queue.
74+
*
75+
* @param parent the parent event queue
76+
*/
4377
protected EventQueue(EventQueue parent) {
4478
this(DEFAULT_QUEUE_SIZE);
4579
LOGGER.trace("Creating {}, parent: {}", this, parent);
@@ -49,40 +83,82 @@ static EventQueueBuilder builder() {
4983
return new EventQueueBuilder();
5084
}
5185

86+
/**
87+
* Builder for creating configured EventQueue instances.
88+
* <p>
89+
* Supports configuration of queue size, enqueue hooks, task association,
90+
* close callbacks, and task state providers.
91+
* </p>
92+
*/
5293
public static class EventQueueBuilder {
5394
private int queueSize = DEFAULT_QUEUE_SIZE;
5495
private @Nullable EventEnqueueHook hook;
5596
private @Nullable String taskId;
5697
private List<Runnable> onCloseCallbacks = new java.util.ArrayList<>();
5798
private @Nullable TaskStateProvider taskStateProvider;
5899

100+
/**
101+
* Sets the maximum queue size.
102+
*
103+
* @param queueSize the maximum number of events that can be queued
104+
* @return this builder
105+
*/
59106
public EventQueueBuilder queueSize(int queueSize) {
60107
this.queueSize = queueSize;
61108
return this;
62109
}
63110

111+
/**
112+
* Sets the enqueue hook for event replication or logging.
113+
*
114+
* @param hook the hook to be invoked when items are enqueued
115+
* @return this builder
116+
*/
64117
public EventQueueBuilder hook(EventEnqueueHook hook) {
65118
this.hook = hook;
66119
return this;
67120
}
68121

122+
/**
123+
* Associates this queue with a specific task ID.
124+
*
125+
* @param taskId the task identifier
126+
* @return this builder
127+
*/
69128
public EventQueueBuilder taskId(String taskId) {
70129
this.taskId = taskId;
71130
return this;
72131
}
73132

133+
/**
134+
* Adds a callback to be executed when the queue is closed.
135+
*
136+
* @param onCloseCallback the callback to execute on close
137+
* @return this builder
138+
*/
74139
public EventQueueBuilder addOnCloseCallback(Runnable onCloseCallback) {
75140
if (onCloseCallback != null) {
76141
this.onCloseCallbacks.add(onCloseCallback);
77142
}
78143
return this;
79144
}
80145

146+
/**
147+
* Sets the task state provider for tracking task finalization.
148+
*
149+
* @param taskStateProvider the task state provider
150+
* @return this builder
151+
*/
81152
public EventQueueBuilder taskStateProvider(TaskStateProvider taskStateProvider) {
82153
this.taskStateProvider = taskStateProvider;
83154
return this;
84155
}
85156

157+
/**
158+
* Builds and returns the configured EventQueue.
159+
*
160+
* @return a new MainQueue instance
161+
*/
86162
public EventQueue build() {
87163
if (hook != null || !onCloseCallbacks.isEmpty() || taskStateProvider != null) {
88164
return new MainQueue(queueSize, hook, taskId, onCloseCallbacks, taskStateProvider);
@@ -92,18 +168,48 @@ public EventQueue build() {
92168
}
93169
}
94170

171+
/**
172+
* Returns the configured queue size.
173+
*
174+
* @return the maximum number of events that can be queued
175+
*/
95176
public int getQueueSize() {
96177
return queueSize;
97178
}
98179

180+
/**
181+
* Waits for the queue poller to start consuming events.
182+
* This method blocks until signaled by {@link #signalQueuePollerStarted()}.
183+
*
184+
* @throws InterruptedException if the thread is interrupted while waiting
185+
*/
99186
public abstract void awaitQueuePollerStart() throws InterruptedException ;
100187

188+
/**
189+
* Signals that the queue poller has started consuming events.
190+
* This unblocks any threads waiting in {@link #awaitQueuePollerStart()}.
191+
*/
101192
public abstract void signalQueuePollerStarted();
102193

194+
/**
195+
* Enqueues an event for processing.
196+
*
197+
* @param event the event to enqueue
198+
*/
103199
public void enqueueEvent(Event event) {
104200
enqueueItem(new LocalEventQueueItem(event));
105201
}
106202

203+
/**
204+
* Enqueues an event queue item for processing.
205+
* <p>
206+
* This method will block if the queue is full, waiting to acquire a semaphore permit.
207+
* If the queue is closed, the event will not be enqueued and a warning will be logged.
208+
* </p>
209+
*
210+
* @param item the event queue item to enqueue
211+
* @throws RuntimeException if interrupted while waiting to acquire the semaphore
212+
*/
107213
public void enqueueItem(EventQueueItem item) {
108214
Event event = item.getEvent();
109215
if (closed) {
@@ -121,6 +227,16 @@ public void enqueueItem(EventQueueItem item) {
121227
LOGGER.debug("Enqueued event {} {}", event instanceof Throwable ? event.toString() : event, this);
122228
}
123229

230+
/**
231+
* Creates a child queue that shares events with this queue.
232+
* <p>
233+
* For MainQueue: creates a ChildQueue that receives all events enqueued to the parent.
234+
* For ChildQueue: throws IllegalStateException (only MainQueue can be tapped).
235+
* </p>
236+
*
237+
* @return a new ChildQueue instance
238+
* @throws IllegalStateException if called on a ChildQueue
239+
*/
124240
public abstract EventQueue tap();
125241

126242
/**
@@ -172,12 +288,24 @@ public void enqueueItem(EventQueueItem item) {
172288
}
173289
}
174290

291+
/**
292+
* Placeholder method for task completion notification.
293+
* Currently not used as BlockingQueue.poll()/take() automatically remove events.
294+
*/
175295
public void taskDone() {
176296
// TODO Not sure if needed yet. BlockingQueue.poll()/.take() remove the events.
177297
}
178298

299+
/**
300+
* Closes this event queue gracefully, allowing pending events to be consumed.
301+
*/
179302
public abstract void close();
180303

304+
/**
305+
* Closes this event queue with control over immediate shutdown.
306+
*
307+
* @param immediate if true, clears all pending events immediately; if false, allows graceful drain
308+
*/
181309
public abstract void close(boolean immediate);
182310

183311
/**
@@ -191,14 +319,28 @@ public void taskDone() {
191319
*/
192320
public abstract void close(boolean immediate, boolean notifyParent);
193321

322+
/**
323+
* Checks if this queue has been closed.
324+
*
325+
* @return true if the queue is closed, false otherwise
326+
*/
194327
public boolean isClosed() {
195328
return closed;
196329
}
197330

331+
/**
332+
* Internal method to close the queue gracefully.
333+
* Delegates to {@link #doClose(boolean)} with immediate=false.
334+
*/
198335
protected void doClose() {
199336
doClose(false);
200337
}
201338

339+
/**
340+
* Internal method to close the queue with control over immediate shutdown.
341+
*
342+
* @param immediate if true, clears all pending events immediately; if false, allows graceful drain
343+
*/
202344
protected void doClose(boolean immediate) {
203345
synchronized (this) {
204346
if (closed) {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
package io.a2a.server.events;
22

3+
/**
4+
* Exception thrown when attempting to dequeue from a closed and empty event queue.
5+
* This signals to consumers that no more events will be available from the queue.
6+
*/
37
public class EventQueueClosedException extends Exception {
48
}

server-common/src/main/java/io/a2a/server/events/NoTaskQueueException.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,56 @@
11
package io.a2a.server.events;
22

3+
/**
4+
* Exception thrown when attempting to access a task queue that does not exist.
5+
* <p>
6+
* This exception is typically thrown when trying to retrieve or operate on
7+
* an event queue for a task that has not been created or has been removed.
8+
* </p>
9+
*/
310
public class NoTaskQueueException extends RuntimeException {
11+
/**
12+
* Creates a NoTaskQueueException with no message.
13+
*/
414
public NoTaskQueueException() {
515
}
616

17+
/**
18+
* Creates a NoTaskQueueException with the specified detail message.
19+
*
20+
* @param message the detail message
21+
*/
722
public NoTaskQueueException(String message) {
823
super(message);
924
}
1025

26+
/**
27+
* Creates a NoTaskQueueException with the specified detail message and cause.
28+
*
29+
* @param message the detail message
30+
* @param cause the cause
31+
*/
1132
public NoTaskQueueException(String message, Throwable cause) {
1233
super(message, cause);
1334
}
1435

36+
/**
37+
* Creates a NoTaskQueueException with the specified cause.
38+
*
39+
* @param cause the cause
40+
*/
1541
public NoTaskQueueException(Throwable cause) {
1642
super(cause);
1743
}
1844

45+
/**
46+
* Creates a NoTaskQueueException with the specified message, cause,
47+
* suppression enabled or disabled, and writable stack trace enabled or disabled.
48+
*
49+
* @param message the detail message
50+
* @param cause the cause
51+
* @param enableSuppression whether suppression is enabled or disabled
52+
* @param writableStackTrace whether the stack trace should be writable
53+
*/
1954
public NoTaskQueueException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
2055
super(message, cause, enableSuppression, writableStackTrace);
2156
}

server-common/src/main/java/io/a2a/server/tasks/InMemoryTaskStore.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@
1414
import io.a2a.spec.Task;
1515
import org.jspecify.annotations.Nullable;
1616

17+
/**
18+
* In-memory implementation of {@link TaskStore} and {@link TaskStateProvider}.
19+
* <p>
20+
* This implementation uses a {@link ConcurrentHashMap} to store tasks in memory.
21+
* Tasks are lost on application restart. For persistent storage, use a database-backed
22+
* implementation such as the JPA TaskStore in the extras module.
23+
* </p>
24+
* <p>
25+
* This is the default TaskStore used when no other implementation is provided.
26+
* </p>
27+
*/
1728
@ApplicationScoped
1829
public class InMemoryTaskStore implements TaskStore, TaskStateProvider {
1930

0 commit comments

Comments
 (0)