Use 'FastTrack' instead of 'Maintenance'

FastTrack may better convey the intent.
This commit is contained in:
Ethan Atkins 2020-06-25 15:12:40 -07:00
parent 5238c78dfd
commit ba0d97c9ac
4 changed files with 22 additions and 22 deletions

View File

@ -26,10 +26,10 @@ import scala.collection.JavaConverters._
abstract class CommandChannel {
private val commandQueue: ConcurrentLinkedQueue[Exec] = new ConcurrentLinkedQueue()
private val registered: java.util.Set[java.util.Queue[Exec]] = new java.util.HashSet
private val maintenance: java.util.Set[java.util.Queue[MaintenanceTask]] = new java.util.HashSet
private val fastTrack: java.util.Set[java.util.Queue[FastTrackTask]] = new java.util.HashSet
private[sbt] final def register(
queue: java.util.Queue[Exec],
maintenanceQueue: java.util.Queue[MaintenanceTask]
fastTrackQueue: java.util.Queue[FastTrackTask]
): Unit =
registered.synchronized {
registered.add(queue)
@ -37,20 +37,20 @@ abstract class CommandChannel {
queue.addAll(commandQueue)
commandQueue.clear()
}
maintenance.add(maintenanceQueue)
fastTrack.add(fastTrackQueue)
()
}
private[sbt] final def unregister(
queue: java.util.Queue[CommandChannel],
maintenanceQueue: java.util.Queue[MaintenanceTask]
fastTrackQueue: java.util.Queue[FastTrackTask]
): Unit =
registered.synchronized {
registered.remove(queue)
maintenance.remove(maintenanceQueue)
fastTrack.remove(fastTrackQueue)
()
}
private[sbt] final def initiateMaintenance(task: String): Unit = {
maintenance.forEach(q => q.synchronized { q.add(new MaintenanceTask(this, task)); () })
private[sbt] final def addFastTrackTask(task: String): Unit = {
fastTrack.forEach(q => q.synchronized { q.add(new FastTrackTask(this, task)); () })
}
private[sbt] def mkUIThread: (State, CommandChannel) => UITask
private[sbt] def makeUIThread(state: State): UITask = mkUIThread(state, this)
@ -91,9 +91,9 @@ abstract class CommandChannel {
if (cmd.nonEmpty) append(Exec(cmd, Some(Exec.newExecId), Some(CommandSource(name))))
else false
}
private[sbt] def onMaintenance: String => Boolean = { s: String =>
maintenance.synchronized(maintenance.forEach { q =>
q.add(new MaintenanceTask(this, s))
private[sbt] def onFastTrackTask: String => Boolean = { s: String =>
fastTrack.synchronized(fastTrack.forEach { q =>
q.add(new FastTrackTask(this, s))
()
})
true
@ -116,4 +116,4 @@ case class ConsolePromptEvent(state: State) extends EventMessage
*/
case class ConsoleUnpromptEvent(lastSource: Option[CommandSource]) extends EventMessage
private[internal] class MaintenanceTask(val channel: CommandChannel, val task: String)
private[internal] class FastTrackTask(val channel: CommandChannel, val task: String)

View File

@ -25,7 +25,7 @@ private[sbt] trait UITask extends Runnable with AutoCloseable {
private[sbt] def channel: CommandChannel
private[sbt] def reader: UITask.Reader
private[this] final def handleInput(s: Either[String, String]): Boolean = s match {
case Left(m) => channel.onMaintenance(m)
case Left(m) => channel.onFastTrackTask(m)
case Right(cmd) => channel.onCommand(cmd)
}
private[this] val isStopped = new AtomicBoolean(false)

View File

@ -49,7 +49,7 @@ private[sbt] final class CommandExchange {
private val commandQueue: LinkedBlockingQueue[Exec] = new LinkedBlockingQueue[Exec]
private val channelBuffer: ListBuffer[CommandChannel] = new ListBuffer()
private val channelBufferLock = new AnyRef {}
private val maintenanceChannelQueue = new LinkedBlockingQueue[MaintenanceTask]
private val fastTrackChannelQueue = new LinkedBlockingQueue[FastTrackTask]
private val nextChannelId: AtomicInteger = new AtomicInteger(0)
private[this] val lastState = new AtomicReference[State]
private[this] val currentExecRef = new AtomicReference[Exec]
@ -58,7 +58,7 @@ private[sbt] final class CommandExchange {
def subscribe(c: CommandChannel): Unit = channelBufferLock.synchronized {
channelBuffer.append(c)
c.register(commandQueue, maintenanceChannelQueue)
c.register(commandQueue, fastTrackChannelQueue)
}
private[sbt] def withState[T](f: State => T): T = f(lastState.get)
@ -253,7 +253,7 @@ private[sbt] final class CommandExchange {
}
def shutdown(): Unit = {
maintenanceThread.close()
fastTrackThread.close()
channels foreach (_.shutdown(true))
// interrupt and kill the thread
server.foreach(_.shutdown())
@ -394,21 +394,21 @@ private[sbt] final class CommandExchange {
}
}
private[this] class MaintenanceThread
extends Thread("sbt-command-exchange-maintenance")
private[this] class FastTrackThread
extends Thread("sbt-command-exchange-fastTrack")
with AutoCloseable {
setDaemon(true)
start()
private[this] val isStopped = new AtomicBoolean(false)
override def run(): Unit = {
def exit(mt: MaintenanceTask): Unit = {
def exit(mt: FastTrackTask): Unit = {
mt.channel.shutdown(false)
if (mt.channel.name.contains("console")) shutdown(mt.channel.name)
}
@tailrec def impl(): Unit = {
maintenanceChannelQueue.take match {
fastTrackChannelQueue.take match {
case null =>
case mt: MaintenanceTask =>
case mt: FastTrackTask =>
mt.task match {
case `attach` => mt.channel.prompt(ConsolePromptEvent(lastState.get))
case "cancel" => Option(currentExecRef.get).foreach(cancel)
@ -435,5 +435,5 @@ private[sbt] final class CommandExchange {
}
private[sbt] def channelForName(channelName: String): Option[CommandChannel] =
channels.find(_.name == channelName)
private[this] val maintenanceThread = new MaintenanceThread
private[this] val fastTrackThread = new FastTrackThread
}

View File

@ -95,7 +95,7 @@ final class NetworkChannel(
attached.set(true)
pendingRequests.remove(id)
jsonRpcRespond("", id)
initiateMaintenance(attach)
addFastTrackTask(attach)
}
private[sbt] def prompt(): Unit = {
terminal.setPrompt(Prompt.Running)