forked from ez0000001000000/Halt.rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHaltExample.java
More file actions
120 lines (97 loc) · 4.44 KB
/
HaltExample.java
File metadata and controls
120 lines (97 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Halt.rs Java Example
// Demonstrates using Halt.rs from Java applications
public class HaltExample {
public static void main(String[] args) {
System.out.println("Halt.rs Java Example");
// Initialize Halt proxy
HaltProxy proxy = new HaltProxy();
try {
// Health check
System.out.println("\n=== Health Check ===");
String health = proxy.getVersion();
System.out.println("Halt version: " + health);
String status = proxy.getStatus();
System.out.println("System status: " + status);
// Circuit Breaker Example
System.out.println("\n=== Circuit Breaker Example ===");
// Check breaker status
String breakerStatus = proxy.checkBreaker("AgentA", "AgentB");
System.out.println("Breaker status: " + breakerStatus);
// Register calls
for (int i = 0; i < 3; i++) {
boolean isTerminal = (i == 2); // Last call is terminal
String result = proxy.registerCall("AgentA", "AgentB", isTerminal);
System.out.println("Call " + (i + 1) + ": " + result);
}
// Reset breaker
String resetResult = proxy.resetBreaker("AgentA", "AgentB");
System.out.println("Reset breaker: " + resetResult);
// Backpressure Queue Example
System.out.println("\n=== Backpressure Queue Example ===");
// Push high priority task
String taskId1 = java.util.UUID.randomUUID().toString();
String pushResult1 = proxy.pushTask(
taskId1,
"High Priority Reasoning",
2, // Priority.HIGH
"{\"type\": \"reasoning\", \"model\": \"gpt-4\", \"prompt\": \"Analyze this Java code\"}"
);
System.out.println("Push high priority task: " + pushResult1);
// Push low priority task
String taskId2 = java.util.UUID.randomUUID().toString();
String pushResult2 = proxy.pushTask(
taskId2,
"Low Priority Logging",
0, // Priority.LOW
"{\"type\": \"logging\", \"message\": \"Background task completed\"}"
);
System.out.println("Push low priority task: " + pushResult2);
// Check queue size
int queueSize = proxy.getQueueSize();
System.out.println("Queue size: " + queueSize);
// Pop tasks
System.out.println("Popping tasks:");
for (int i = 0; i < Math.min(queueSize, 2); i++) {
String taskJson = proxy.popTask();
if (!"null".equals(taskJson)) {
System.out.println("Task " + (i + 1) + ": " + taskJson);
} else {
System.out.println("No more tasks");
}
}
// Audit Logging Example
System.out.println("\n=== Audit Logging Example ===");
// Log interactions
String logResult1 = proxy.logInteraction(
"AgentA",
"AgentB",
"[\"token_abc\", \"token_def\"]"
);
System.out.println("Log interaction 1: " + logResult1);
String logResult2 = proxy.logInteraction(
"AgentB",
"AgentC",
"[\"token_ghi\"]"
);
System.out.println("Log interaction 2: " + logResult2);
// Get topology
String topology = proxy.getTopologyMap();
System.out.println("Current topology: " + topology);
// Clear audit log
String clearResult = proxy.clearAuditLog();
System.out.println("Clear audit log: " + clearResult);
// Configuration Example
System.out.println("\n=== Configuration Example ===");
// Configure breaker
String configBreaker = proxy.configureBreaker(10, 60); // 10 calls per 60 seconds
System.out.println("Configure breaker: " + configBreaker);
// Configure queue capacity
String configQueue = proxy.configureQueueCapacity(2000);
System.out.println("Configure queue capacity: " + configQueue);
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
e.printStackTrace();
}
System.out.println("\nHalt.rs Java example completed!");
}
}