summaryrefslogtreecommitdiff
path: root/same/src/main/java/com/orbekk/same/apps
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-05-01 12:15:32 +0200
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-05-01 12:15:32 +0200
commit0bc8c4ddc0ffe6febf8cf39c6144e0193957a96a (patch)
tree64307319bb1e23a90b082b3aafb1882e0726be6f /same/src/main/java/com/orbekk/same/apps
parent22f189a883e5e86860d7e831c12cd5851eee0677 (diff)
Add SystemService.
The SystemService is meant for debugging commands. It currently supports GetSystemStatus() which prints the state of all components.
Diffstat (limited to 'same/src/main/java/com/orbekk/same/apps')
-rw-r--r--same/src/main/java/com/orbekk/same/apps/GetSystemStatus.java60
1 files changed, 60 insertions, 0 deletions
diff --git a/same/src/main/java/com/orbekk/same/apps/GetSystemStatus.java b/same/src/main/java/com/orbekk/same/apps/GetSystemStatus.java
new file mode 100644
index 0000000..b37126c
--- /dev/null
+++ b/same/src/main/java/com/orbekk/same/apps/GetSystemStatus.java
@@ -0,0 +1,60 @@
+package com.orbekk.same.apps;
+
+import com.google.protobuf.RpcCallback;
+import com.orbekk.protobuf.Rpc;
+import com.orbekk.protobuf.RpcChannel;
+import com.orbekk.same.Services;
+
+public class GetSystemStatus {
+ final String location;
+
+ public GetSystemStatus(String location) {
+ this.location = location;
+ }
+
+ public class StatusPrinter implements RpcCallback<Services.SystemStatus> {
+ @Override public void run(Services.SystemStatus status) {
+ if (status == null) {
+ System.err.println("Could not retrieve status.");
+ return;
+ }
+ System.out.println("=================================================");
+ System.out.println("System status for " + location);
+ System.out.println(status);
+ System.out.println("=================================================");
+ }
+ }
+
+ public void run() throws Exception {
+ RpcChannel channel = null;
+ try {
+ String host = location.split(":")[0];
+ int port = Integer.valueOf(location.split(":")[1]);
+ channel = RpcChannel.create(host, port);
+ Services.SystemService system = Services.SystemService.newStub(channel);
+ Rpc rpc = new Rpc();
+ rpc.setTimeout(10000);
+ system.getSystemStatus(rpc, Services.Empty.getDefaultInstance(),
+ new StatusPrinter());
+ rpc.await();
+ } finally {
+ if (channel != null) {
+ channel.close();
+ }
+ }
+ }
+
+ public static void main(String[] args) {
+ if (args.length != 1) {
+ System.err.println("Usage: " + GetSystemStatus.class + " host:port");
+ System.exit(1);
+ }
+ String location = args[0];
+ try {
+ new GetSystemStatus(location).run();
+ } catch (Exception e) {
+ e.printStackTrace();
+ System.exit(1);
+ }
+ }
+}