Skip to content

Commit b40d16d

Browse files
feat: update dependencies and enhance configuration
Signed-off-by: Janos Sarusi-Kis <janossk@cisco.com>
1 parent 87d3ccf commit b40d16d

7 files changed

Lines changed: 170 additions & 35 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ target/
44
*.war
55
*.ear
66
*.class
7+
dependency-reduced-pom.xml
78

89
# IDE
910
.idea/

examples/echo-agent/pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,26 @@
5454
</systemProperties>
5555
</configuration>
5656
</plugin>
57+
<plugin>
58+
<groupId>org.apache.maven.plugins</groupId>
59+
<artifactId>maven-shade-plugin</artifactId>
60+
<version>3.5.3</version>
61+
<executions>
62+
<execution>
63+
<phase>package</phase>
64+
<goals>
65+
<goal>shade</goal>
66+
</goals>
67+
<configuration>
68+
<shadedArtifactAttached>true</shadedArtifactAttached>
69+
<shadedClassifierName>shaded</shadedClassifierName>
70+
<transformers>
71+
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
72+
</transformers>
73+
</configuration>
74+
</execution>
75+
</executions>
76+
</plugin>
5777
</plugins>
5878
</build>
5979
</project>

examples/echo-agent/src/main/java/io/agntcy/slim/a2a/examples/echo/ClientMain.java

Lines changed: 40 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
package io.agntcy.slim.a2a.examples.echo;
55

6+
import java.time.Duration;
67
import java.util.List;
78
import java.util.UUID;
89

@@ -25,49 +26,60 @@ public final class ClientMain {
2526

2627
public static void main(String[] args) throws Exception {
2728
String serverAddr = ServerMain.DEFAULT_SERVER_ADDR;
29+
String remoteInstance = "server";
2830
for (int i = 0; i < args.length; i++) {
2931
if ("--server".equals(args[i]) && i + 1 < args.length) {
3032
serverAddr = args[i + 1];
33+
} else if ("--secret".equals(args[i]) && i + 1 < args.length) {
34+
ServerMain.SHARED_SECRET = args[i + 1];
35+
} else if ("--org".equals(args[i]) && i + 1 < args.length) {
36+
ServerMain.ORG = args[i + 1];
37+
} else if ("--ns".equals(args[i]) && i + 1 < args.length) {
38+
ServerMain.NS = args[i + 1];
39+
} else if ("--remote-instance".equals(args[i]) && i + 1 < args.length) {
40+
remoteInstance = args[i + 1];
3141
}
3242
}
3343

3444
SlimHelper.initializeDefaults();
3545

3646
Channel channel = SlimHelper.createChannel(
3747
"client", ServerMain.ORG, ServerMain.NS,
38-
"server", ServerMain.SHARED_SECRET, serverAddr);
48+
remoteInstance, ServerMain.SHARED_SECRET, serverAddr);
3949

40-
var client = new SlimA2AClient(channel);
50+
try {
51+
var client = new SlimA2AClient(channel);
4152

42-
String contextId = UUID.randomUUID().toString();
43-
Message message = Message.builder()
44-
.role(Message.Role.ROLE_USER)
45-
.messageId(UUID.randomUUID().toString())
46-
.contextId(contextId)
47-
.parts(List.of(new TextPart("Hello from Java A2A client!", null)))
48-
.build();
53+
String contextId = UUID.randomUUID().toString();
54+
Message message = Message.builder()
55+
.role(Message.Role.ROLE_USER)
56+
.messageId(UUID.randomUUID().toString())
57+
.contextId(contextId)
58+
.parts(List.of(new TextPart("Hello from Java A2A client!", null)))
59+
.build();
4960

50-
MessageSendParams params = MessageSendParams.builder()
51-
.message(message)
52-
.build();
61+
MessageSendParams params = MessageSendParams.builder()
62+
.message(message)
63+
.build();
5364

54-
System.out.println("Sending message to echo agent...");
55-
EventKind result = client.sendMessage(params);
65+
System.out.println("Sending message to echo agent...");
66+
EventKind result = client.sendMessage(params);
5667

57-
if (result instanceof Task task) {
58-
System.out.println("Got Task: id=" + task.id()
59-
+ " state=" + task.status().state());
60-
} else if (result instanceof Message msg) {
61-
System.out.println("Got Message: " + msg.parts());
62-
} else {
63-
System.out.println("Got: " + result);
64-
}
65-
66-
System.out.println("Fetching agent card...");
67-
var agentCard = client.getExtendedAgentCard();
68-
System.out.println("Agent: " + agentCard.name()
69-
+ " - " + agentCard.description());
68+
if (result instanceof Task task) {
69+
System.out.println("Got Task: id=" + task.id()
70+
+ " state=" + task.status().state());
71+
} else if (result instanceof Message msg) {
72+
System.out.println("Got Message: " + msg.parts());
73+
} else {
74+
System.out.println("Got: " + result);
75+
}
7076

71-
System.out.println("SLIM_A2A_CLIENT_DONE");
77+
// getExtendedAgentCard() is intentionally not called here: it hangs and, worse,
78+
// leaves the server's session/participant capacity stuck for every other client
79+
// until restarted. Re-enable once that server-side bug is fixed.
80+
System.out.println("SLIM_A2A_CLIENT_DONE");
81+
} finally {
82+
channel.close(Duration.ofSeconds(5));
83+
}
7284
}
7385
}

examples/echo-agent/src/main/java/io/agntcy/slim/a2a/examples/echo/ServerMain.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,15 @@
3030
*/
3131
public final class ServerMain {
3232

33-
static final String ORG = "agntcy";
34-
static final String NS = "slim-a2a";
35-
static final String SHARED_SECRET = "demo-shared-secret-min-32-chars!!";
36-
static final String DEFAULT_SERVER_ADDR = "http://localhost:46357";
33+
static String ORG = envOr("SLIM_ORG", "agntcy");
34+
static String NS = envOr("SLIM_NS", "slim-a2a");
35+
static String SHARED_SECRET = envOr("SLIM_SHARED_SECRET", "demo-shared-secret-min-32-chars!!");
36+
static final String DEFAULT_SERVER_ADDR = envOr("SLIM_SERVER", "http://localhost:46357");
37+
38+
private static String envOr(String name, String fallback) {
39+
String value = System.getenv(name);
40+
return (value == null || value.isEmpty()) ? fallback : value;
41+
}
3742

3843
public static void main(String[] args) throws Exception {
3944
String serverAddr = DEFAULT_SERVER_ADDR;
@@ -43,6 +48,12 @@ public static void main(String[] args) throws Exception {
4348
serverAddr = args[i + 1];
4449
} else if ("--instance".equals(args[i]) && i + 1 < args.length) {
4550
instance = args[i + 1];
51+
} else if ("--secret".equals(args[i]) && i + 1 < args.length) {
52+
SHARED_SECRET = args[i + 1];
53+
} else if ("--org".equals(args[i]) && i + 1 < args.length) {
54+
ORG = args[i + 1];
55+
} else if ("--ns".equals(args[i]) && i + 1 < args.length) {
56+
NS = args[i + 1];
4657
}
4758
}
4859

@@ -74,7 +85,7 @@ public static void main(String[] args) throws Exception {
7485
var queueManager = new InMemoryQueueManager(taskStore, eventBus);
7586
var pushConfigStore = new InMemoryPushNotificationConfigStore();
7687

77-
PushNotificationSender noOpPush = event -> {};
88+
PushNotificationSender noOpPush = (event, task) -> {};
7889

7990
var eventProcessor = new MainEventBusProcessor(eventBus, taskStore, noOpPush, queueManager);
8091
var processorThread = new Thread(eventProcessor, "event-bus-processor");

pom.xml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
<maven.compiler.source>21</maven.compiler.source>
3131
<maven.compiler.target>21</maven.compiler.target>
3232

33-
<slim.bindings.version>1.3.0</slim.bindings.version>
34-
<a2a.java.sdk.version>1.0.0.Beta1</a2a.java.sdk.version>
33+
<slim.bindings.version>1.4.1</slim.bindings.version>
34+
<a2a.java.sdk.version>1.1.0.Final</a2a.java.sdk.version>
3535
<protobuf.version>4.33.1</protobuf.version>
3636
<jna.version>5.14.0</jna.version>
3737
</properties>
@@ -86,6 +86,9 @@
8686
<configuration>
8787
<source>${maven.compiler.source}</source>
8888
<target>${maven.compiler.target}</target>
89+
<compilerArgs>
90+
<arg>--enable-preview</arg>
91+
</compilerArgs>
8992
</configuration>
9093
</plugin>
9194
<plugin>
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// Copyright AGNTCY Contributors (https://github.com/agntcy)
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package io.agntcy.slim.a2a;
5+
6+
import java.io.IOException;
7+
import java.io.InputStream;
8+
import java.io.UncheckedIOException;
9+
import java.nio.file.Files;
10+
import java.nio.file.Path;
11+
import java.nio.file.StandardCopyOption;
12+
13+
/**
14+
* slim-bindings-java 1.4.x resolves its native library through the Java Foreign
15+
* Function &amp; Memory API instead of JNA, so it no longer self-extracts the
16+
* platform-specific binary bundled inside its jar. This extracts the matching
17+
* binary to a temp file and points
18+
* {@code uniffi.component.slim_bindings.libraryOverride} at it, restoring the
19+
* "just works" behavior the JNA-based 1.3.x loader used to provide.
20+
*/
21+
final class NativeLibraryLoader {
22+
23+
private static final String OVERRIDE_PROPERTY = "uniffi.component.slim_bindings.libraryOverride";
24+
25+
private NativeLibraryLoader() {}
26+
27+
static synchronized void ensureExtracted() {
28+
if (System.getProperty(OVERRIDE_PROPERTY) != null) {
29+
return;
30+
}
31+
String resourcePath = platformDir() + "/" + libraryFileName();
32+
try (InputStream in = NativeLibraryLoader.class.getClassLoader().getResourceAsStream(resourcePath)) {
33+
if (in == null) {
34+
throw new IllegalStateException(
35+
"slim-bindings-java native library not found on classpath: " + resourcePath);
36+
}
37+
Path tempFile = Files.createTempFile("slim_bindings-", suffix());
38+
tempFile.toFile().deleteOnExit();
39+
Files.copy(in, tempFile, StandardCopyOption.REPLACE_EXISTING);
40+
System.setProperty(OVERRIDE_PROPERTY, tempFile.toAbsolutePath().toString());
41+
} catch (IOException e) {
42+
throw new UncheckedIOException("Failed to extract slim-bindings-java native library", e);
43+
}
44+
}
45+
46+
private static String platformDir() {
47+
return osFamily() + "-" + archName();
48+
}
49+
50+
private static String libraryFileName() {
51+
return switch (osFamily()) {
52+
case "win32" -> "slim_bindings.dll";
53+
case "darwin" -> "libslim_bindings.dylib";
54+
default -> "libslim_bindings.so";
55+
};
56+
}
57+
58+
private static String suffix() {
59+
return switch (osFamily()) {
60+
case "win32" -> ".dll";
61+
case "darwin" -> ".dylib";
62+
default -> ".so";
63+
};
64+
}
65+
66+
private static String osFamily() {
67+
String name = System.getProperty("os.name", "").toLowerCase();
68+
if (name.contains("mac") || name.contains("darwin")) {
69+
return "darwin";
70+
}
71+
if (name.contains("win")) {
72+
return "win32";
73+
}
74+
return "linux";
75+
}
76+
77+
private static String archName() {
78+
String arch = System.getProperty("os.arch", "").toLowerCase();
79+
if (arch.equals("aarch64") || arch.equals("arm64")) {
80+
return "aarch64";
81+
}
82+
return "x86-64";
83+
}
84+
}

slim-a2a/src/main/java/io/agntcy/slim/a2a/SlimHelper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
*/
1717
public final class SlimHelper {
1818

19+
static {
20+
NativeLibraryLoader.ensureExtracted();
21+
}
22+
1923
private SlimHelper() {}
2024

2125
/**

0 commit comments

Comments
 (0)