summaryrefslogtreecommitdiff
path: root/same
diff options
context:
space:
mode:
Diffstat (limited to 'same')
-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());