diff options
Diffstat (limited to 'directory/src/main/java/com/orbekk')
-rw-r--r-- | directory/src/main/java/com/orbekk/same/directory/DirectoryApp.java | 13 | ||||
-rw-r--r-- | directory/src/main/java/com/orbekk/same/directory/DirectoryServiceImpl.java | 32 |
2 files changed, 36 insertions, 9 deletions
diff --git a/directory/src/main/java/com/orbekk/same/directory/DirectoryApp.java b/directory/src/main/java/com/orbekk/same/directory/DirectoryApp.java index 7a05894..667d4f0 100644 --- a/directory/src/main/java/com/orbekk/same/directory/DirectoryApp.java +++ b/directory/src/main/java/com/orbekk/same/directory/DirectoryApp.java @@ -3,6 +3,7 @@ package com.orbekk.same.directory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.orbekk.protobuf.SimpleProtobufServer; import com.orbekk.same.discovery.DirectoryService; import com.orbekk.same.http.JettyServerBuilder; import com.orbekk.same.http.ServerContainer; @@ -12,13 +13,9 @@ public class DirectoryApp { public static void main(String[] args) { Logger logger = LoggerFactory.getLogger(DirectoryApp.class); - ServerContainer server = new JettyServerBuilder(DISCOVERY_PORT) - .withService(new DirectoryServiceImpl(), DirectoryService.class) - .build(); - try { - server.start(); - } catch (Exception e) { - logger.error("Unable to start server.", e); - } + SimpleProtobufServer server = + SimpleProtobufServer.create(DISCOVERY_PORT); + server.registerService(new DirectoryServiceImpl()); + server.start(); } } diff --git a/directory/src/main/java/com/orbekk/same/directory/DirectoryServiceImpl.java b/directory/src/main/java/com/orbekk/same/directory/DirectoryServiceImpl.java index 307c0ca..9c38446 100644 --- a/directory/src/main/java/com/orbekk/same/directory/DirectoryServiceImpl.java +++ b/directory/src/main/java/com/orbekk/same/directory/DirectoryServiceImpl.java @@ -7,9 +7,15 @@ import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.protobuf.RpcCallback; +import com.google.protobuf.RpcController; import com.orbekk.same.discovery.DirectoryService; +import com.orbekk.same.Services; +import com.orbekk.same.Services.Empty; +import com.orbekk.same.Services.MasterState; +import com.orbekk.same.Services.NetworkDirectory; -public class DirectoryServiceImpl implements DirectoryService { +public class DirectoryServiceImpl extends Services.Directory implements DirectoryService { private Logger logger = LoggerFactory.getLogger(getClass()); public final static long EXPIRE_TIME = 15 * 60l * 1000; // 15 minutes List<NetworkEntry> networkList = new ArrayList<NetworkEntry>(); @@ -45,4 +51,28 @@ public class DirectoryServiceImpl implements DirectoryService { networkList.remove(entry); networkList.add(entry); } + + @Override + public void registerNetwork(RpcController controller, MasterState request, + RpcCallback<Empty> done) { + try { + registerNetwork(request.getNetworkName(), request.getMasterUrl()); + } catch (Exception e) { + // No RPC call here. + } + done.run(Empty.getDefaultInstance()); + } + + @Override + public void getNetworks(RpcController controller, Empty request, + RpcCallback<NetworkDirectory> done) { + NetworkDirectory.Builder directory = NetworkDirectory.newBuilder(); + for (NetworkEntry e : networkList) { + directory.addNetwork(MasterState.newBuilder() + .setMasterUrl(e.masterUrl) + .setNetworkName(e.networkName) + .build()); + } + done.run(directory.build()); + } } |