Handle errors on send() due to closed socket.

Also, more logging of the various close conditions,
and handle SocketException specifically on read()
to avoid printing a stack trace for it.

We ignore errors on send (don't throw them up),
except that we force-close the socket as a double
check that we'll get rid of the client.
Merge pull request #162 from sbt/wip/handle-socket-fail

Handle errors on send() due to closed socket.
Merge pull request #161 from sbt/wip/havocp-log-earlier

Send log events earlier, so we get events during sbt boot
To send an event, require Writes not Format

Format is invariant, so it can impose extra
restrictions on how we can pass the Format around
while Writes is more flexible.
Add "ImpliedState" object tracking state implied by events
Sync new clients to current execution state

This involves moving eventListeners to an eventSink object
because we need to synchronize adding listeners and sending
current state, to avoid sending events twice or missing events.

A small bugfix in here is that we did not send ExecutionWaiting
for synthetic execution requests previously. This bug was revealed
because the event state tracker throws an exception if events are
incorrect, so had to fix the bug to make the tests pass.
SbtEventSink: change to JsonSink[T], always use Writes instances

This patch has several changes which were somewhat tricky to separate.

 * SbtEventSink changed to have a type parameter for what can be
   sent; now an event sink is JsonSink[Event] and a message sink
   JsonSink[Message] and so on.
 * SbtClientHandler has to be a JsonSink[Any] because UIContext
   allows sending a JsValue which will not be a Message
 * EventLogger can use a JsonSink[LogEvent]
 * for now we only have one sink but pass it around as the most
   specific type we can in various places.
 * We were not using the provided Writes instances we were passing
   around; instead ipc.Peer was hardcoded to always use a global
   universal Message serializer.
   * Changed ipc.Peer to accept a JSON filter when constructed,
     which avoids importing sbt.protocol down into the IPC module
   * set a filter when constructing ipc.Client and ipc.Server
     which calls the provided writes and then inserts a "type"
     field, instead of ignoring provided writes entirely
 * We were also ignoring provided Writes instances in some cases
   where we matched on message type and then re-sent the message;
     send[T:Writes](msg: T) = msg match {
       case x: LogEvent => client.send(x)
     }
   This is wrong, we need to always keep the Writes with the
   message.
 * We pass separate jsonSink, eventSink, and logSink to
   ServerEngine, though for now they are all really the
   same object. They may always have to be to provide
   proper ordering guarantees.
 * UIContext updated to use Writes rather than Format for sending
 * some minor reformatting in here that Eclipse is dying to
   do that I'm tired of reverting every time...
Change Format to Writes in SimpleClient

We only need Writes to send things.