Skip to content

Commit b6712e8

Browse files
authored
fix: remove printlns and use logging (#159)
# Description Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [x] Follow the [`CONTRIBUTING` Guide](../CONTRIBUTING.md). - [x] Make your Pull Request title in the <https://www.conventionalcommits.org/> specification. - Important Prefixes for [release-please](https://github.com/googleapis/release-please): - `fix:` which represents bug fixes, and correlates to a [SemVer](https://semver.org/) patch. - `feat:` represents a new feature, and correlates to a SemVer minor. - `feat!:`, or `fix!:`, `refactor!:`, etc., which represent a breaking change (indicated by the `!`) and will result in a SemVer major. - [x] Ensure the tests pass - [x] Appropriate READMEs were updated (if necessary) Fixes #<issue_number_goes_here> 🦕
1 parent 9a8e9e5 commit b6712e8

File tree

6 files changed

+38
-38
lines changed

6 files changed

+38
-38
lines changed

sdk-jakarta/src/main/java/io/a2a/server/apps/jakarta/A2AServerResource.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020

2121
import com.fasterxml.jackson.core.JsonParseException;
2222
import com.fasterxml.jackson.databind.JsonMappingException;
23-
2423
import io.a2a.server.ExtendedAgentCard;
2524
import io.a2a.server.requesthandlers.JSONRPCHandler;
25+
import io.a2a.server.util.async.Internal;
2626
import io.a2a.spec.AgentCard;
2727
import io.a2a.spec.CancelTaskRequest;
2828
import io.a2a.spec.GetTaskPushNotificationConfigRequest;
@@ -46,11 +46,14 @@
4646
import io.a2a.spec.StreamingJSONRPCRequest;
4747
import io.a2a.spec.TaskResubscriptionRequest;
4848
import io.a2a.spec.UnsupportedOperationError;
49-
import io.a2a.server.util.async.Internal;
49+
import org.slf4j.Logger;
50+
import org.slf4j.LoggerFactory;
5051

5152
@Path("/")
5253
public class A2AServerResource {
5354

55+
private static final Logger LOGGER = LoggerFactory.getLogger(A2AServerResource.class);
56+
5457
@Inject
5558
JSONRPCHandler jsonRpcHandler;
5659

@@ -76,7 +79,12 @@ public class A2AServerResource {
7679
@Consumes(MediaType.APPLICATION_JSON)
7780
@Produces(MediaType.APPLICATION_JSON)
7881
public JSONRPCResponse<?> handleNonStreamingRequests(NonStreamingJSONRPCRequest<?> request) {
79-
return processNonStreamingRequest(request);
82+
LOGGER.debug("Handling non-streaming request");
83+
try {
84+
return processNonStreamingRequest(request);
85+
} finally {
86+
LOGGER.debug("Completed non-streaming request");
87+
}
8088
}
8189

8290
/**
@@ -87,9 +95,9 @@ public JSONRPCResponse<?> handleNonStreamingRequests(NonStreamingJSONRPCRequest<
8795
@Consumes(MediaType.APPLICATION_JSON)
8896
@Produces(MediaType.SERVER_SENT_EVENTS)
8997
public void handleStreamingRequests(StreamingJSONRPCRequest<?> request, @Context SseEventSink sseEventSink, @Context Sse sse) {
90-
System.out.println("=====> Streaming");
98+
LOGGER.debug("Handling streaming request");
9199
executor.execute(() -> processStreamingRequest(request, sseEventSink, sse));
92-
System.out.println("=====> Streaming - done");
100+
LOGGER.debug("Submitted streaming request for async processing");
93101
}
94102

95103
/**
@@ -167,7 +175,6 @@ private void handleStreamingResponse(Flow.Publisher<? extends JSONRPCResponse<?>
167175
public void onSubscribe(Flow.Subscription subscription) {
168176
this.subscription = subscription;
169177
subscription.request(Long.MAX_VALUE);
170-
System.out.println("SUBSCRIBING!");
171178
// Notify tests that we are subscribed
172179
Runnable runnable = streamingIsSubscribedRunnable;
173180
if (runnable != null) {

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

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.a2a.server.events;
22

33
import java.util.List;
4-
import java.util.concurrent.ArrayBlockingQueue;
54
import java.util.concurrent.BlockingQueue;
65
import java.util.concurrent.CopyOnWriteArrayList;
76
import java.util.concurrent.CountDownLatch;
@@ -16,7 +15,7 @@
1615

1716
public abstract class EventQueue implements AutoCloseable {
1817

19-
private static final Logger log = LoggerFactory.getLogger(EventQueue.class);
18+
private static final Logger LOGGER = LoggerFactory.getLogger(EventQueue.class);
2019

2120
// TODO decide on a capacity
2221
private static final int queueSize = 1000;
@@ -34,7 +33,7 @@ protected EventQueue() {
3433
}
3534

3635
protected EventQueue(EventQueue parent) {
37-
log.trace("Creating {}, parent: {}", this, parent);
36+
LOGGER.trace("Creating {}, parent: {}", this, parent);
3837
this.parent = parent;
3938
}
4039

@@ -48,7 +47,7 @@ public static EventQueue create() {
4847

4948
public void enqueueEvent(Event event) {
5049
if (closed) {
51-
log.warn("Queue is closed. Event will not be enqueued. {} {}", this, event);
50+
LOGGER.warn("Queue is closed. Event will not be enqueued. {} {}", this, event);
5251
return;
5352
}
5453
// Call toString() since for errors we don't really want the full stacktrace
@@ -59,22 +58,22 @@ public void enqueueEvent(Event event) {
5958
throw new RuntimeException("Unable to acquire the semaphore to enqueue the event", e);
6059
}
6160
queue.add(event);
62-
log.debug("Enqueued event {} {}", event instanceof Throwable ? event.toString() : event, this);
61+
LOGGER.debug("Enqueued event {} {}", event instanceof Throwable ? event.toString() : event, this);
6362
}
6463

6564
abstract EventQueue tap();
6665

6766
public Event dequeueEvent(int waitMilliSeconds) throws EventQueueClosedException {
6867
if (closed && queue.isEmpty()) {
69-
log.debug("Queue is closed, and empty. Sending termination message. {}", this);
68+
LOGGER.debug("Queue is closed, and empty. Sending termination message. {}", this);
7069
throw new EventQueueClosedException();
7170
}
7271
try {
7372
if (waitMilliSeconds <= 0) {
7473
Event event = queue.poll();
7574
if (event != null) {
7675
// Call toString() since for errors we don't really want the full stacktrace
77-
log.debug("Dequeued event (no wait) {} {}", this, event instanceof Throwable ? event.toString() : event);
76+
LOGGER.debug("Dequeued event (no wait) {} {}", this, event instanceof Throwable ? event.toString() : event);
7877
semaphore.release();
7978
}
8079
return event;
@@ -83,12 +82,12 @@ public Event dequeueEvent(int waitMilliSeconds) throws EventQueueClosedException
8382
Event event = queue.poll(waitMilliSeconds, TimeUnit.MILLISECONDS);
8483
if (event != null) {
8584
// Call toString() since for errors we don't really want the full stacktrace
86-
log.debug("Dequeued event (waiting) {} {}", this, event instanceof Throwable ? event.toString() : event);
85+
LOGGER.debug("Dequeued event (waiting) {} {}", this, event instanceof Throwable ? event.toString() : event);
8786
semaphore.release();
8887
}
8988
return event;
9089
} catch (InterruptedException e) {
91-
log.debug("Interrupted dequeue (waiting) {}", this);
90+
LOGGER.debug("Interrupted dequeue (waiting) {}", this);
9291
Thread.currentThread().interrupt();
9392
return null;
9493
}
@@ -108,7 +107,7 @@ public void doClose() {
108107
if (closed) {
109108
return;
110109
}
111-
log.debug("Closing {}", this);
110+
LOGGER.debug("Closing {}", this);
112111
closed = true;
113112
}
114113
// Although the Python implementation drains the queue on closing,
@@ -137,17 +136,17 @@ public void enqueueEvent(Event event) {
137136

138137
@Override
139138
public void awaitQueuePollerStart() throws InterruptedException {
140-
log.debug("Waiting for queue poller to start on {}", this);
139+
LOGGER.debug("Waiting for queue poller to start on {}", this);
141140
pollingStartedLatch.await(10, TimeUnit.SECONDS);
142-
log.debug("Queue poller started on {}", this);
141+
LOGGER.debug("Queue poller started on {}", this);
143142
}
144143

145144
@Override
146145
void signalQueuePollerStarted() {
147146
if (pollingStarted.get()) {
148147
return;
149148
}
150-
log.debug("Signalling that queue polling started {}", this);
149+
LOGGER.debug("Signalling that queue polling started {}", this);
151150
pollingStartedLatch.countDown();
152151
pollingStarted.set(true);
153152
}

sdk-server-common/src/main/java/io/a2a/server/requesthandlers/DefaultRequestHandler.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
@ApplicationScoped
5353
public class DefaultRequestHandler implements RequestHandler {
5454

55-
private static final Logger log = LoggerFactory.getLogger(DefaultRequestHandler.class);
55+
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultRequestHandler.class);
5656

5757
private final AgentExecutor agentExecutor;
5858
private final TaskStore taskStore;
@@ -81,10 +81,10 @@ public DefaultRequestHandler(AgentExecutor agentExecutor, TaskStore taskStore,
8181

8282
@Override
8383
public Task onGetTask(TaskQueryParams params) throws JSONRPCError {
84-
log.debug("onGetTask {}", params.id());
84+
LOGGER.debug("onGetTask {}", params.id());
8585
Task task = taskStore.get(params.id());
8686
if (task == null) {
87-
log.debug("No task found for {}. Throwing TaskNotFoundError", params.id());
87+
LOGGER.debug("No task found for {}. Throwing TaskNotFoundError", params.id());
8888
throw new TaskNotFoundError();
8989
}
9090
if (params.historyLength() != null && task.getHistory() != null && params.historyLength() < task.getHistory().size()) {
@@ -102,7 +102,7 @@ public Task onGetTask(TaskQueryParams params) throws JSONRPCError {
102102
.build();
103103
}
104104

105-
log.debug("Task found {}", task);
105+
LOGGER.debug("Task found {}", task);
106106
return task;
107107
}
108108

@@ -146,11 +146,11 @@ public Task onCancelTask(TaskIdParams params) throws JSONRPCError {
146146

147147
@Override
148148
public EventKind onMessageSend(MessageSendParams params) throws JSONRPCError {
149-
log.debug("onMessageSend - task: {}; context {}", params.message().getTaskId(), params.message().getContextId());
149+
LOGGER.debug("onMessageSend - task: {}; context {}", params.message().getTaskId(), params.message().getContextId());
150150
MessageSendSetup mss = initMessageSend(params);
151151

152152
String taskId = mss.requestContext.getTaskId();
153-
log.debug("Request context taskId: {}", taskId);
153+
LOGGER.debug("Request context taskId: {}", taskId);
154154

155155
EventQueue queue = queueManager.createOrTap(taskId);
156156
ResultAggregator resultAggregator = new ResultAggregator(mss.taskManager, null);
@@ -168,11 +168,11 @@ public EventKind onMessageSend(MessageSendParams params) throws JSONRPCError {
168168
etai = resultAggregator.consumeAndBreakOnInterrupt(consumer);
169169

170170
if (etai == null) {
171-
log.debug("No result, throwing InternalError");
171+
LOGGER.debug("No result, throwing InternalError");
172172
throw new InternalError("No result");
173173
}
174174
interrupted = etai.interrupted();
175-
log.debug("Was interrupted: {}", interrupted);
175+
LOGGER.debug("Was interrupted: {}", interrupted);
176176

177177
EventKind kind = etai.eventType();
178178
if (kind instanceof Task taskResult && !taskId.equals(taskResult.getId())) {
@@ -188,13 +188,13 @@ public EventKind onMessageSend(MessageSendParams params) throws JSONRPCError {
188188
}
189189
}
190190

191-
log.debug("Returning: {}", etai.eventType());
191+
LOGGER.debug("Returning: {}", etai.eventType());
192192
return etai.eventType();
193193
}
194194

195195
@Override
196196
public Flow.Publisher<StreamingEventKind> onMessageSendStream(MessageSendParams params) throws JSONRPCError {
197-
log.debug("onMessageSendStream - task: {}; context {}", params.message().getTaskId(), params.message().getContextId());
197+
LOGGER.debug("onMessageSendStream - task: {}; context {}", params.message().getTaskId(), params.message().getContextId());
198198
MessageSendSetup mss = initMessageSend(params);
199199

200200
AtomicReference<String> taskId = new AtomicReference<>(mss.requestContext.getTaskId());
@@ -352,11 +352,11 @@ private MessageSendSetup initMessageSend(MessageSendParams params) {
352352

353353
Task task = taskManager.getTask();
354354
if (task != null) {
355-
log.debug("Found task updating with message {}", params.message());
355+
LOGGER.debug("Found task updating with message {}", params.message());
356356
task = taskManager.updateWithMessage(params.message(), task);
357357

358358
if (shouldAddPushInfo(params)) {
359-
log.debug("Adding push info");
359+
LOGGER.debug("Adding push info");
360360
pushNotifier.setInfo(task.getId(), params.configuration().pushNotification());
361361
}
362362
}

sdk-server-common/src/main/java/io/a2a/server/tasks/ResultAggregator.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,8 @@
1818
import io.a2a.spec.TaskState;
1919
import io.a2a.spec.TaskStatusUpdateEvent;
2020
import io.a2a.util.Utils;
21-
import org.slf4j.Logger;
22-
import org.slf4j.LoggerFactory;
2321

2422
public class ResultAggregator {
25-
private static final Logger log = LoggerFactory.getLogger(ResultAggregator.class);
26-
2723
private final TaskManager taskManager;
2824
private volatile Message message;
2925

sdk-server-common/src/test/java/io/a2a/server/requesthandlers/JSONRPCHandlerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,7 @@ public void onComplete() {
730730
// TODO - this is very strange. The results array is synchronized, and the latch is counted down
731731
// AFTER adding items to the list. Still, I am seeing intermittently, but frequently that
732732
// the results list only has two items.
733+
// Remove System.out.printlns in this test when done.
733734
long end = System.currentTimeMillis() + 5000;
734735
while (results.size() != 3 && System.currentTimeMillis() < end) {
735736
Thread.sleep(1000);
@@ -1105,7 +1106,6 @@ public void testOnMessageSendInternalError() {
11051106
SendMessageRequest request = new SendMessageRequest("1", new MessageSendParams(MESSAGE, null, null));
11061107
SendMessageResponse response = handler.onMessageSend(request);
11071108

1108-
System.out.println(response);
11091109
assertInstanceOf(InternalError.class, response.getError());
11101110
}
11111111

sdk-server-common/src/test/java/io/a2a/server/util/async/AsyncUtilsTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,6 @@ public void testAsyncUtilsErrorPropagation() {
591591
Flow.Publisher<String> processor = processor(createTubeConfig(), source, new BiFunction<Consumer<Throwable>, String, Boolean>() {
592592
@Override
593593
public Boolean apply(Consumer<Throwable> throwableConsumer, String item) {
594-
System.out.println("-> (1) " + item);
595594
if (item.equals("c")) {
596595
throw new IllegalStateException();
597596
}
@@ -688,7 +687,6 @@ public void onComplete() {
688687
}
689688
});
690689

691-
System.out.println("---hi");
692690
latch.await(2, TimeUnit.SECONDS);
693691
assertEquals(6, results.size());
694692
}

0 commit comments

Comments
 (0)