Skip to content

Commit de11456

Browse files
nficanoclaude
andcommitted
style: spotless-apply on examples and recipes
These modules used Gradle's `application` plugin, which was outside the java-library scope where spotless was applied — so their sources never got auto-formatted. Maven now applies spotless reactor-wide, surfacing the drift. Reformat in bulk to align with googleJavaFormat. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 2a7b4be commit de11456

26 files changed

Lines changed: 1260 additions & 1262 deletions

File tree

  • examples
    • ack-backpressure/src/main/java/dev/arcp/examples/ackbackpressure
    • agent-versions/src/main/java/dev/arcp/examples/agentversions
    • cancel/src/main/java/dev/arcp/examples/cancel
    • cost-budget/src/main/java/dev/arcp/examples/costbudget
    • custom-auth/src/main/java/dev/arcp/examples/customauth
    • delegate/src/main/java/dev/arcp/examples/delegate
    • heartbeat/src/main/java/dev/arcp/examples/heartbeat
    • idempotent-retry/src/main/java/dev/arcp/examples/idempotentretry
    • jakarta/src/main/java/dev/arcp/examples/jakarta
    • lease-expires-at/src/main/java/dev/arcp/examples/leaseexpiresat
    • lease-violation/src/main/java/dev/arcp/examples/leaseviolation
    • list-jobs/src/main/java/dev/arcp/examples/listjobs
    • progress/src/main/java/dev/arcp/examples/progress
    • provisioned-credentials/src/main/java/dev/arcp/examples/provisionedcredentials
    • result-chunk/src/main/java/dev/arcp/examples/resultchunk
    • resume/src/main/java/dev/arcp/examples/resume
    • spring-boot/src/main/java/dev/arcp/examples/springboot
    • stdio/src/main/java/dev/arcp/examples/stdio
    • submit-and-stream/src/main/java/dev/arcp/examples/submitandstream
    • subscribe/src/main/java/dev/arcp/examples/subscribe
    • tracing/src/main/java/dev/arcp/examples/tracing
    • vendor-extensions/src/main/java/dev/arcp/examples/vendorextensions
  • recipes
    • email-vendor-leases/src/main/java/dev/arcp/recipes/emailvendorleases
    • mcp-skill/src/main/java/dev/arcp/recipes/mcpskill
    • multi-agent-budget/src/main/java/dev/arcp/recipes/multiagentbudget
    • stream-resume/src/main/java/dev/arcp/recipes/streamresume

examples/ack-backpressure/src/main/java/dev/arcp/examples/ackbackpressure/Main.java

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,62 +16,71 @@
1616
import java.util.concurrent.atomic.AtomicInteger;
1717

1818
/**
19-
* Demonstrates manual ack/back-pressure: client opts out of auto-ack,
20-
* counts events itself, then sends a single explicit ack at the end.
19+
* Demonstrates manual ack/back-pressure: client opts out of auto-ack, counts events itself, then
20+
* sends a single explicit ack at the end.
2121
*/
2222
public final class Main {
23-
public static void main(String[] args) throws Exception {
24-
MemoryTransport.Pair pair = MemoryTransport.pair();
25-
ArcpRuntime runtime = ArcpRuntime.builder()
26-
.agent("ticker", "1.0.0", (input, ctx) -> {
27-
for (int i = 1; i <= 20; i++) {
28-
ctx.emit(new StatusEvent("tick-" + i, null));
29-
}
30-
return JobOutcome.Success.inline(input.payload());
23+
public static void main(String[] args) throws Exception {
24+
MemoryTransport.Pair pair = MemoryTransport.pair();
25+
ArcpRuntime runtime =
26+
ArcpRuntime.builder()
27+
.agent(
28+
"ticker",
29+
"1.0.0",
30+
(input, ctx) -> {
31+
for (int i = 1; i <= 20; i++) {
32+
ctx.emit(new StatusEvent("tick-" + i, null));
33+
}
34+
return JobOutcome.Success.inline(input.payload());
3135
})
32-
.build();
33-
runtime.accept(pair.runtime());
36+
.build();
37+
runtime.accept(pair.runtime());
3438

35-
AtomicInteger received = new AtomicInteger();
39+
AtomicInteger received = new AtomicInteger();
3640

37-
try (ArcpClient client = ArcpClient.builder(pair.client())
38-
.autoAck(false)
39-
.features(EnumSet.allOf(Feature.class))
40-
.build()) {
41-
client.connect(Duration.ofSeconds(5));
41+
try (ArcpClient client =
42+
ArcpClient.builder(pair.client())
43+
.autoAck(false)
44+
.features(EnumSet.allOf(Feature.class))
45+
.build()) {
46+
client.connect(Duration.ofSeconds(5));
4247

43-
JobHandle handle = client.submit(
44-
ArcpClient.jobSubmit("ticker@1.0.0", JsonNodeFactory.instance.objectNode()));
48+
JobHandle handle =
49+
client.submit(
50+
ArcpClient.jobSubmit("ticker@1.0.0", JsonNodeFactory.instance.objectNode()));
4551

46-
handle.events().subscribe(new Flow.Subscriber<>() {
52+
handle
53+
.events()
54+
.subscribe(
55+
new Flow.Subscriber<>() {
4756
@Override
4857
public void onSubscribe(Flow.Subscription s) {
49-
s.request(Long.MAX_VALUE);
58+
s.request(Long.MAX_VALUE);
5059
}
5160

5261
@Override
5362
public void onNext(EventBody body) {
54-
received.incrementAndGet();
63+
received.incrementAndGet();
5564
}
5665

5766
@Override
5867
public void onError(Throwable throwable) {}
5968

6069
@Override
6170
public void onComplete() {}
62-
});
71+
});
6372

64-
handle.result().get(5, TimeUnit.SECONDS);
73+
handle.result().get(5, TimeUnit.SECONDS);
6574

66-
// Allow event delivery to finish.
67-
Thread.sleep(200);
75+
// Allow event delivery to finish.
76+
Thread.sleep(200);
6877

69-
assert received.get() == 20 : "expected 20 events, got " + received.get();
78+
assert received.get() == 20 : "expected 20 events, got " + received.get();
7079

71-
// Explicit ack after processing all events.
72-
client.ack(client.lastSeenSeq());
73-
System.out.println("OK ack-backpressure");
74-
}
75-
runtime.close();
80+
// Explicit ack after processing all events.
81+
client.ack(client.lastSeenSeq());
82+
System.out.println("OK ack-backpressure");
7683
}
84+
runtime.close();
85+
}
7786
}

examples/agent-versions/src/main/java/dev/arcp/examples/agentversions/Main.java

Lines changed: 47 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,57 @@
1313

1414
/** Two registered versions; bare-name resolves to default; unknown version errors. */
1515
public final class Main {
16-
public static void main(String[] args) throws Exception {
17-
MemoryTransport.Pair pair = MemoryTransport.pair();
18-
ArcpRuntime runtime = ArcpRuntime.builder()
19-
.agent("code-refactor", "1.0.0",
20-
(input, ctx) -> JobOutcome.Success.inline(
21-
JsonNodeFactory.instance.objectNode().put("v", "1.0.0")))
22-
.agent("code-refactor", "2.0.0",
23-
(input, ctx) -> JobOutcome.Success.inline(
24-
JsonNodeFactory.instance.objectNode().put("v", "2.0.0")))
25-
.build();
26-
runtime.agents().setDefault("code-refactor", "2.0.0");
27-
runtime.accept(pair.runtime());
16+
public static void main(String[] args) throws Exception {
17+
MemoryTransport.Pair pair = MemoryTransport.pair();
18+
ArcpRuntime runtime =
19+
ArcpRuntime.builder()
20+
.agent(
21+
"code-refactor",
22+
"1.0.0",
23+
(input, ctx) ->
24+
JobOutcome.Success.inline(
25+
JsonNodeFactory.instance.objectNode().put("v", "1.0.0")))
26+
.agent(
27+
"code-refactor",
28+
"2.0.0",
29+
(input, ctx) ->
30+
JobOutcome.Success.inline(
31+
JsonNodeFactory.instance.objectNode().put("v", "2.0.0")))
32+
.build();
33+
runtime.agents().setDefault("code-refactor", "2.0.0");
34+
runtime.accept(pair.runtime());
2835

29-
try (ArcpClient client = ArcpClient.builder(pair.client()).build()) {
30-
client.connect(Duration.ofSeconds(5));
36+
try (ArcpClient client = ArcpClient.builder(pair.client()).build()) {
37+
client.connect(Duration.ofSeconds(5));
3138

32-
JobHandle pinned = client.submit(ArcpClient.jobSubmit(
33-
"code-refactor@1.0.0", JsonNodeFactory.instance.objectNode()));
34-
JobResult pinnedResult = pinned.result().get(5, TimeUnit.SECONDS);
35-
assert "1.0.0".equals(pinnedResult.result().get("v").asText());
36-
assert "code-refactor@1.0.0".equals(pinned.resolvedAgent());
39+
JobHandle pinned =
40+
client.submit(
41+
ArcpClient.jobSubmit("code-refactor@1.0.0", JsonNodeFactory.instance.objectNode()));
42+
JobResult pinnedResult = pinned.result().get(5, TimeUnit.SECONDS);
43+
assert "1.0.0".equals(pinnedResult.result().get("v").asText());
44+
assert "code-refactor@1.0.0".equals(pinned.resolvedAgent());
3745

38-
JobHandle bare = client.submit(ArcpClient.jobSubmit(
39-
"code-refactor", JsonNodeFactory.instance.objectNode()));
40-
JobResult bareResult = bare.result().get(5, TimeUnit.SECONDS);
41-
assert "2.0.0".equals(bareResult.result().get("v").asText());
42-
assert "code-refactor@2.0.0".equals(bare.resolvedAgent());
46+
JobHandle bare =
47+
client.submit(
48+
ArcpClient.jobSubmit("code-refactor", JsonNodeFactory.instance.objectNode()));
49+
JobResult bareResult = bare.result().get(5, TimeUnit.SECONDS);
50+
assert "2.0.0".equals(bareResult.result().get("v").asText());
51+
assert "code-refactor@2.0.0".equals(bare.resolvedAgent());
4352

44-
try {
45-
client.submit(ArcpClient.jobSubmit(
46-
"code-refactor@9.9.9", JsonNodeFactory.instance.objectNode()));
47-
throw new AssertionError("expected AgentVersionNotAvailableException");
48-
} catch (RuntimeException e) {
49-
Throwable root = e;
50-
while (root.getCause() != null) {
51-
root = root.getCause();
52-
}
53-
assert root instanceof AgentVersionNotAvailableException
54-
: "got " + root;
55-
}
56-
57-
System.out.println("OK agent-versions");
53+
try {
54+
client.submit(
55+
ArcpClient.jobSubmit("code-refactor@9.9.9", JsonNodeFactory.instance.objectNode()));
56+
throw new AssertionError("expected AgentVersionNotAvailableException");
57+
} catch (RuntimeException e) {
58+
Throwable root = e;
59+
while (root.getCause() != null) {
60+
root = root.getCause();
5861
}
59-
runtime.close();
62+
assert root instanceof AgentVersionNotAvailableException : "got " + root;
63+
}
64+
65+
System.out.println("OK agent-versions");
6066
}
67+
runtime.close();
68+
}
6169
}

examples/cancel/src/main/java/dev/arcp/examples/cancel/Main.java

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
44
import dev.arcp.client.ArcpClient;
55
import dev.arcp.client.JobHandle;
6-
import dev.arcp.core.error.ArcpException;
76
import dev.arcp.core.error.CancelledException;
87
import dev.arcp.core.events.LogEvent;
98
import dev.arcp.core.transport.MemoryTransport;
@@ -13,38 +12,45 @@
1312
import java.util.concurrent.ExecutionException;
1413
import java.util.concurrent.TimeUnit;
1514

16-
/** Submits a long-running job, then cancels it; the resulting future fails with CancelledException. */
15+
/**
16+
* Submits a long-running job, then cancels it; the resulting future fails with CancelledException.
17+
*/
1718
public final class Main {
18-
public static void main(String[] args) throws Exception {
19-
MemoryTransport.Pair pair = MemoryTransport.pair();
20-
ArcpRuntime runtime = ArcpRuntime.builder()
21-
.agent("sleeper", "1.0.0", (input, ctx) -> {
22-
ctx.emit(new LogEvent("info", "sleeping"));
23-
while (!ctx.cancelled()) {
24-
Thread.sleep(50);
25-
}
26-
return new JobOutcome.Failure(
27-
dev.arcp.core.error.ErrorCode.CANCELLED, "cooperative");
19+
public static void main(String[] args) throws Exception {
20+
MemoryTransport.Pair pair = MemoryTransport.pair();
21+
ArcpRuntime runtime =
22+
ArcpRuntime.builder()
23+
.agent(
24+
"sleeper",
25+
"1.0.0",
26+
(input, ctx) -> {
27+
ctx.emit(new LogEvent("info", "sleeping"));
28+
while (!ctx.cancelled()) {
29+
Thread.sleep(50);
30+
}
31+
return new JobOutcome.Failure(
32+
dev.arcp.core.error.ErrorCode.CANCELLED, "cooperative");
2833
})
29-
.build();
30-
runtime.accept(pair.runtime());
34+
.build();
35+
runtime.accept(pair.runtime());
3136

32-
try (ArcpClient client = ArcpClient.builder(pair.client()).build()) {
33-
client.connect(Duration.ofSeconds(5));
34-
JobHandle handle = client.submit(
35-
ArcpClient.jobSubmit("sleeper@1.0.0", JsonNodeFactory.instance.objectNode()));
36-
Thread.sleep(100);
37-
handle.cancel();
37+
try (ArcpClient client = ArcpClient.builder(pair.client()).build()) {
38+
client.connect(Duration.ofSeconds(5));
39+
JobHandle handle =
40+
client.submit(
41+
ArcpClient.jobSubmit("sleeper@1.0.0", JsonNodeFactory.instance.objectNode()));
42+
Thread.sleep(100);
43+
handle.cancel();
3844

39-
try {
40-
handle.result().get(5, TimeUnit.SECONDS);
41-
throw new AssertionError("expected cancellation");
42-
} catch (ExecutionException e) {
43-
assert e.getCause() instanceof CancelledException
44-
: "expected CancelledException, got " + e.getCause();
45-
System.out.println("OK cancel");
46-
}
47-
}
48-
runtime.close();
45+
try {
46+
handle.result().get(5, TimeUnit.SECONDS);
47+
throw new AssertionError("expected cancellation");
48+
} catch (ExecutionException e) {
49+
assert e.getCause() instanceof CancelledException
50+
: "expected CancelledException, got " + e.getCause();
51+
System.out.println("OK cancel");
52+
}
4953
}
54+
runtime.close();
55+
}
5056
}

examples/cost-budget/src/main/java/dev/arcp/examples/costbudget/Main.java

Lines changed: 34 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,41 @@
1616

1717
/** Tracks a USD budget; agent over-spends and surfaces BUDGET_EXHAUSTED. */
1818
public final class Main {
19-
public static void main(String[] args) throws Exception {
20-
MemoryTransport.Pair pair = MemoryTransport.pair();
21-
ArcpRuntime runtime = ArcpRuntime.builder()
22-
.agent("spender", "1.0.0", (input, ctx) -> {
23-
// Spend over budget by accumulating cost.inference metrics.
24-
for (int i = 0; i < 10; i++) {
25-
ctx.emit(new MetricEvent(
26-
"cost.inference", new BigDecimal("0.75"),
27-
"USD", null));
28-
ctx.authorize("tool.call", "*");
29-
}
30-
return JobOutcome.Success.inline(input.payload());
19+
public static void main(String[] args) throws Exception {
20+
MemoryTransport.Pair pair = MemoryTransport.pair();
21+
ArcpRuntime runtime =
22+
ArcpRuntime.builder()
23+
.agent(
24+
"spender",
25+
"1.0.0",
26+
(input, ctx) -> {
27+
// Spend over budget by accumulating cost.inference metrics.
28+
for (int i = 0; i < 10; i++) {
29+
ctx.emit(
30+
new MetricEvent("cost.inference", new BigDecimal("0.75"), "USD", null));
31+
ctx.authorize("tool.call", "*");
32+
}
33+
return JobOutcome.Success.inline(input.payload());
3134
})
32-
.build();
33-
runtime.accept(pair.runtime());
35+
.build();
36+
runtime.accept(pair.runtime());
3437

35-
try (ArcpClient client = ArcpClient.builder(pair.client()).build()) {
36-
client.connect(Duration.ofSeconds(5));
37-
Lease lease = Lease.builder()
38-
.allow("tool.call", "*")
39-
.allow("cost.budget", "USD:5.00")
40-
.build();
41-
JobHandle handle = client.submit(ArcpClient.jobSubmit(
42-
"spender@1.0.0",
43-
JsonNodeFactory.instance.objectNode(),
44-
lease,
45-
null,
46-
null,
47-
null));
48-
try {
49-
handle.result().get(5, TimeUnit.SECONDS);
50-
throw new AssertionError("expected BudgetExhaustedException");
51-
} catch (ExecutionException e) {
52-
assert e.getCause() instanceof BudgetExhaustedException
53-
: "got " + e.getCause();
54-
System.out.println("OK cost-budget");
55-
}
56-
}
57-
runtime.close();
38+
try (ArcpClient client = ArcpClient.builder(pair.client()).build()) {
39+
client.connect(Duration.ofSeconds(5));
40+
Lease lease =
41+
Lease.builder().allow("tool.call", "*").allow("cost.budget", "USD:5.00").build();
42+
JobHandle handle =
43+
client.submit(
44+
ArcpClient.jobSubmit(
45+
"spender@1.0.0", JsonNodeFactory.instance.objectNode(), lease, null, null, null));
46+
try {
47+
handle.result().get(5, TimeUnit.SECONDS);
48+
throw new AssertionError("expected BudgetExhaustedException");
49+
} catch (ExecutionException e) {
50+
assert e.getCause() instanceof BudgetExhaustedException : "got " + e.getCause();
51+
System.out.println("OK cost-budget");
52+
}
5853
}
54+
runtime.close();
55+
}
5956
}

0 commit comments

Comments
 (0)