-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEcho.java
More file actions
65 lines (54 loc) · 1.77 KB
/
Copy pathEcho.java
File metadata and controls
65 lines (54 loc) · 1.77 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
package io.aether.echo;
import io.aether.StandardUUIDs;
import io.aether.cloud.client.AetherCloudClient;
import io.aether.cloud.client.ClientState;
import io.aether.cloud.client.ClientStateInFile;
import io.aether.logger.Log;
import io.aether.logger.LogFilter;
import io.aether.utils.futures.AFuture;
import java.net.URI;
import java.util.List;
import java.util.UUID;
public class Echo {
private AetherCloudClient client;
public Echo() {
this(List.of(URI.create("tcp://registration.aethernet.io:9010")));
}
public Echo(List<URI> registrationUris) {
this(new ClientStateInFile(StandardUUIDs.ANONYMOUS_UID, registrationUris));
}
public Echo(ClientState state) {
client = AetherCloudClient.of(state);
client.startFuture.to(() -> {
Log.info("Echo service started", "uid", client.getUid());
});
client.onMessage((u, msg) -> {
Log.info("Echo received message", "from", u, "size", msg.length, "content", new String(msg));
client.sendMessage(u, msg).to(() -> {
Log.debug("Echoed message successfully", "to", u);
}).onError(e -> {
Log.error("Failed to echo message", e, "to", u);
});
});
}
public void runForever() {
try {
Thread.sleep(Long.MAX_VALUE);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
public AFuture start() {
return client.startFuture;
}
public UUID getUid() {
return client.getUid();
}
public AFuture destroy(boolean b) {
return client.destroy(b);
}
public static void main(String... aa) {
Log.printConsoleColored(new LogFilter());
new Echo().runForever();
}
}