keys.scala, etc.: Make merging public keys have a progress bar.
[tripe-android] / admin.scala
index 52a2912..9796cd9 100644 (file)
@@ -30,7 +30,7 @@ package uk.org.distorted.tripe; package object admin {
 import java.io.{BufferedReader, InputStreamReader, OutputStreamWriter};
 import java.util.concurrent.locks.{Condition, ReentrantLock => Lock};
 
-import scala.collection.mutable.{HashMap, Publisher};
+import scala.collection.mutable.HashMap;
 import scala.concurrent.Channel;
 import scala.util.control.Breaks;
 
@@ -78,7 +78,7 @@ class CommandFailed(val msg: Seq[String]) extends Exception {
 
 class ConnectionLostException extends Exception;
 
-object Connection extends Publisher[AsyncMessage]
+object Connection extends Hook[AsyncMessage]
 {
   /* Synchronization.
    *
@@ -102,7 +102,7 @@ object Connection extends Publisher[AsyncMessage]
     private[this] var nextmsg: Option[JobMessage] = None;
 
     private[this] def fetchNext()
-      { if (nextmsg == None) nextmsg = Some(ch.read); }
+      { if (!nextmsg) nextmsg = Some(ch.read); }
     override def hasNext: Boolean = {
       fetchNext();
       nextmsg match {
@@ -113,10 +113,10 @@ object Connection extends Publisher[AsyncMessage]
     override def next(): Seq[String] = {
       fetchNext();
       nextmsg match {
-       case None => ???
-       case Some(JobOK) => throw new NoSuchElementException
-       case Some(JobFail(msg)) => throw new CommandFailed(msg)
-       case Some(JobLostConnection) => throw new ConnectionLostException
+       case None => unreachable;
+       case Some(JobOK) => throw new NoSuchElementException;
+       case Some(JobFail(msg)) => throw new CommandFailed(msg);
+       case Some(JobLostConnection) => throw new ConnectionLostException;
        case Some(JobInfo(msg)) => nextmsg = None; msg
       }
     }
@@ -248,7 +248,7 @@ println(s";; line: $line");
              j
            }
          case msg: AsyncMessage =>
-           publish(msg);
+           callHook(msg);
          case _: ServiceMessage =>
            ok;
        }
@@ -267,7 +267,7 @@ println(s";; line: $line");
          case None => ok;
        }
       }
-      publish(ConnectionLost);
+      callHook(ConnectionLost);
     }
   }
 }