summaryrefslogtreecommitdiff
path: root/same/src/main/java/com
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-03-06 14:50:23 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-03-06 14:50:23 +0100
commitb795cc1519d88a22d3d3a05d5a41e278b6ccf617 (patch)
treef4da4f3db8fa05dfa4c4bfb0d257a6f8329b26bb /same/src/main/java/com
parent64f187d46f8ac97e4cfb400f52562f8bb53275be (diff)
Add tools used with the Directory service.
Diffstat (limited to 'same/src/main/java/com')
-rw-r--r--same/src/main/java/com/orbekk/same/DirectoryApp.java41
-rw-r--r--same/src/main/java/com/orbekk/same/SameController.java15
2 files changed, 55 insertions, 1 deletions
diff --git a/same/src/main/java/com/orbekk/same/DirectoryApp.java b/same/src/main/java/com/orbekk/same/DirectoryApp.java
new file mode 100644
index 0000000..c484d0f
--- /dev/null
+++ b/same/src/main/java/com/orbekk/same/DirectoryApp.java
@@ -0,0 +1,41 @@
+package com.orbekk.same;
+
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.orbekk.same.discovery.DirectoryService;
+
+public class DirectoryApp {
+ private static final Logger logger =
+ LoggerFactory.getLogger(DirectoryApp.class);
+ public static final int CONNECTION_TIMEOUT = 2 * 1000;
+ public static final int READ_TIMEOUT = 2 * 1000;
+ private String[] args;
+
+ public DirectoryApp(String[] args) {
+ this.args = args;
+ }
+
+ public void run() {
+ ConnectionManager connections = new ConnectionManagerImpl(
+ CONNECTION_TIMEOUT, READ_TIMEOUT);
+ DirectoryService directory = connections.getDirectory(args[0]);
+ try {
+ List<String> networks = directory.getNetworks();
+ System.out.println("Available networks:");
+ System.out.println(networks);
+ System.out.println("Registering network.");
+ directory.registerNetwork("InvalidNetwork", "InvalidUrl");
+ System.out.println("Available networks:");
+ System.out.println(directory.getNetworks());
+ } catch (Exception e) {
+ logger.error("Unable to contact directory service.", e);
+ }
+ }
+
+ public static void main(String[] args) {
+ new DirectoryApp(args).run();
+ }
+}
diff --git a/same/src/main/java/com/orbekk/same/SameController.java b/same/src/main/java/com/orbekk/same/SameController.java
index 6f32bf6..7f45592 100644
--- a/same/src/main/java/com/orbekk/same/SameController.java
+++ b/same/src/main/java/com/orbekk/same/SameController.java
@@ -10,6 +10,7 @@ import com.orbekk.net.DefaultBroadcasterFactory;
import com.orbekk.paxos.PaxosService;
import com.orbekk.paxos.PaxosServiceImpl;
import com.orbekk.same.config.Configuration;
+import com.orbekk.same.discovery.DirectoryService;
import com.orbekk.same.discovery.DiscoveryService;
import com.orbekk.same.http.ServerContainer;
import com.orbekk.same.http.StateServlet;
@@ -25,6 +26,7 @@ public class SameController {
private DiscoveryService discoveryService;
private BroadcasterFactory broadcasterFactory;
private Configuration configuration;
+ private ConnectionManager connections;
/**
* Timeout for remote operations in milliseconds.
@@ -70,7 +72,7 @@ public class SameController {
.build();
SameController controller = new SameController(
- configuration, server, master, client,
+ configuration, connections, server, master, client,
paxos, discoveryService, broadcasterFactory);
return controller;
}
@@ -81,6 +83,7 @@ public class SameController {
public SameController(
Configuration configuration,
+ ConnectionManager connections,
ServerContainer server,
Master master,
Client client,
@@ -88,6 +91,7 @@ public class SameController {
DiscoveryService discoveryService,
BroadcasterFactory broadcasterFactory) {
this.configuration = configuration;
+ this.connections = connections;
this.server = server;
this.master = master;
this.client = client;
@@ -153,6 +157,15 @@ public class SameController {
public Master getMaster() {
return master;
}
+
+ public DirectoryService getDirectory() {
+ String directoryUrl = configuration.get("directoryUrl");
+ DirectoryService directory = null;
+ if (directoryUrl != null) {
+ directory = connections.getDirectory(directoryUrl);
+ }
+ return directory;
+ }
public VariableFactory createVariableFactory() {
return new VariableFactory(client.getInterface());