diff --git a/Client-server-discovery-lifecycle.md b/Client-server-discovery-lifecycle.md index 749efcd..66a9ca3 100644 --- a/Client-server-discovery-lifecycle.md +++ b/Client-server-discovery-lifecycle.md @@ -79,8 +79,16 @@ The sbt launcher provides a locking facility. Here's a more concrete proposal of how launching a server would work. However, first, let's make some assumptions that are potentially contentious that lead to the following proposal: 1. the sbt launcher's locking mechanism is sufficient for us to find a means to avoid double-server-startup. -2. We want clients to have *one* means of attempting to fork the sbt server process. -*TODO - more here* +2. We want clients to have *one* means of attempting to fork the sbt server process. This is assumed to + be the sbt launcher. +3. Upon network failure, or inability to communicate to the server, clients will attempt to spawn another + server. This will only succeed if the server is actually down. Clients are also responsible for + restoring any state they need on the server upon reconnect. +4. The sbt server needs to outlive the original client that requested it, and only shut down when it has + no more clients. + + +*TODO - more assumptions?* We create a new interface for the sbt launcher, called `xsbt.ServerMain`: @@ -88,7 +96,7 @@ We create a new interface for the sbt launcher, called `xsbt.ServerMain`: package xsbti; public interface ServerMain { - public ServerPort[] start(AppConfiguration configuration); + public ServerPort[] start(AppConfiguration configuration, ShutdownService shutdown); public boolean isAlive(ServerPort[] ports); } ``` @@ -100,7 +108,6 @@ The interface has two methods. One responsible for starting the Server, and ano 3. Checking to see if the old server is alive. If so, report these ports to the client (TODO - how?) 4. If the old server was not alive, start up a new server (fork + detach?). Write the new server bindings to the lock file. - Port bindings come in triples of `Address`, `Port` and `Protocol` mappings: ```java @@ -116,3 +123,15 @@ interface ServerPort { Clients should be able to be notified of all open ServerPort bindings created by a server. + +The shutdown service, passed to a server is designed so that the server itself can determine when it needs to go away. For example, sbt may want to shutdown its own server when there are no remaining connected clients, or after a timeout. The shutdown service has a single method, which tells the sbt-launcher to obtain the lock file and remove any active port bindings from the current server in the lock file: + +```java +package xsbti; + +interface ShutdownService { + void shutdownServer(ServerPort[] activePorts); +} +``` + +The server should not actually release ports until the ShutdownService call returns, this way ensuring that new services that may be starting up don't grab the same port and have our shutdown blow away their configuration. \ No newline at end of file