mirror of https://github.com/sbt/sbt.git
Use 'FastTrack' instead of 'Maintenance'
FastTrack may better convey the intent.
This commit is contained in:
parent
5238c78dfd
commit
ba0d97c9ac
|
|
@ -26,10 +26,10 @@ import scala.collection.JavaConverters._
|
||||||
abstract class CommandChannel {
|
abstract class CommandChannel {
|
||||||
private val commandQueue: ConcurrentLinkedQueue[Exec] = new ConcurrentLinkedQueue()
|
private val commandQueue: ConcurrentLinkedQueue[Exec] = new ConcurrentLinkedQueue()
|
||||||
private val registered: java.util.Set[java.util.Queue[Exec]] = new java.util.HashSet
|
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(
|
private[sbt] final def register(
|
||||||
queue: java.util.Queue[Exec],
|
queue: java.util.Queue[Exec],
|
||||||
maintenanceQueue: java.util.Queue[MaintenanceTask]
|
fastTrackQueue: java.util.Queue[FastTrackTask]
|
||||||
): Unit =
|
): Unit =
|
||||||
registered.synchronized {
|
registered.synchronized {
|
||||||
registered.add(queue)
|
registered.add(queue)
|
||||||
|
|
@ -37,20 +37,20 @@ abstract class CommandChannel {
|
||||||
queue.addAll(commandQueue)
|
queue.addAll(commandQueue)
|
||||||
commandQueue.clear()
|
commandQueue.clear()
|
||||||
}
|
}
|
||||||
maintenance.add(maintenanceQueue)
|
fastTrack.add(fastTrackQueue)
|
||||||
()
|
()
|
||||||
}
|
}
|
||||||
private[sbt] final def unregister(
|
private[sbt] final def unregister(
|
||||||
queue: java.util.Queue[CommandChannel],
|
queue: java.util.Queue[CommandChannel],
|
||||||
maintenanceQueue: java.util.Queue[MaintenanceTask]
|
fastTrackQueue: java.util.Queue[FastTrackTask]
|
||||||
): Unit =
|
): Unit =
|
||||||
registered.synchronized {
|
registered.synchronized {
|
||||||
registered.remove(queue)
|
registered.remove(queue)
|
||||||
maintenance.remove(maintenanceQueue)
|
fastTrack.remove(fastTrackQueue)
|
||||||
()
|
()
|
||||||
}
|
}
|
||||||
private[sbt] final def initiateMaintenance(task: String): Unit = {
|
private[sbt] final def addFastTrackTask(task: String): Unit = {
|
||||||
maintenance.forEach(q => q.synchronized { q.add(new MaintenanceTask(this, task)); () })
|
fastTrack.forEach(q => q.synchronized { q.add(new FastTrackTask(this, task)); () })
|
||||||
}
|
}
|
||||||
private[sbt] def mkUIThread: (State, CommandChannel) => UITask
|
private[sbt] def mkUIThread: (State, CommandChannel) => UITask
|
||||||
private[sbt] def makeUIThread(state: State): UITask = mkUIThread(state, this)
|
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))))
|
if (cmd.nonEmpty) append(Exec(cmd, Some(Exec.newExecId), Some(CommandSource(name))))
|
||||||
else false
|
else false
|
||||||
}
|
}
|
||||||
private[sbt] def onMaintenance: String => Boolean = { s: String =>
|
private[sbt] def onFastTrackTask: String => Boolean = { s: String =>
|
||||||
maintenance.synchronized(maintenance.forEach { q =>
|
fastTrack.synchronized(fastTrack.forEach { q =>
|
||||||
q.add(new MaintenanceTask(this, s))
|
q.add(new FastTrackTask(this, s))
|
||||||
()
|
()
|
||||||
})
|
})
|
||||||
true
|
true
|
||||||
|
|
@ -116,4 +116,4 @@ case class ConsolePromptEvent(state: State) extends EventMessage
|
||||||
*/
|
*/
|
||||||
case class ConsoleUnpromptEvent(lastSource: Option[CommandSource]) 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)
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ private[sbt] trait UITask extends Runnable with AutoCloseable {
|
||||||
private[sbt] def channel: CommandChannel
|
private[sbt] def channel: CommandChannel
|
||||||
private[sbt] def reader: UITask.Reader
|
private[sbt] def reader: UITask.Reader
|
||||||
private[this] final def handleInput(s: Either[String, String]): Boolean = s match {
|
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)
|
case Right(cmd) => channel.onCommand(cmd)
|
||||||
}
|
}
|
||||||
private[this] val isStopped = new AtomicBoolean(false)
|
private[this] val isStopped = new AtomicBoolean(false)
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ private[sbt] final class CommandExchange {
|
||||||
private val commandQueue: LinkedBlockingQueue[Exec] = new LinkedBlockingQueue[Exec]
|
private val commandQueue: LinkedBlockingQueue[Exec] = new LinkedBlockingQueue[Exec]
|
||||||
private val channelBuffer: ListBuffer[CommandChannel] = new ListBuffer()
|
private val channelBuffer: ListBuffer[CommandChannel] = new ListBuffer()
|
||||||
private val channelBufferLock = new AnyRef {}
|
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 val nextChannelId: AtomicInteger = new AtomicInteger(0)
|
||||||
private[this] val lastState = new AtomicReference[State]
|
private[this] val lastState = new AtomicReference[State]
|
||||||
private[this] val currentExecRef = new AtomicReference[Exec]
|
private[this] val currentExecRef = new AtomicReference[Exec]
|
||||||
|
|
@ -58,7 +58,7 @@ private[sbt] final class CommandExchange {
|
||||||
|
|
||||||
def subscribe(c: CommandChannel): Unit = channelBufferLock.synchronized {
|
def subscribe(c: CommandChannel): Unit = channelBufferLock.synchronized {
|
||||||
channelBuffer.append(c)
|
channelBuffer.append(c)
|
||||||
c.register(commandQueue, maintenanceChannelQueue)
|
c.register(commandQueue, fastTrackChannelQueue)
|
||||||
}
|
}
|
||||||
|
|
||||||
private[sbt] def withState[T](f: State => T): T = f(lastState.get)
|
private[sbt] def withState[T](f: State => T): T = f(lastState.get)
|
||||||
|
|
@ -253,7 +253,7 @@ private[sbt] final class CommandExchange {
|
||||||
}
|
}
|
||||||
|
|
||||||
def shutdown(): Unit = {
|
def shutdown(): Unit = {
|
||||||
maintenanceThread.close()
|
fastTrackThread.close()
|
||||||
channels foreach (_.shutdown(true))
|
channels foreach (_.shutdown(true))
|
||||||
// interrupt and kill the thread
|
// interrupt and kill the thread
|
||||||
server.foreach(_.shutdown())
|
server.foreach(_.shutdown())
|
||||||
|
|
@ -394,21 +394,21 @@ private[sbt] final class CommandExchange {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private[this] class MaintenanceThread
|
private[this] class FastTrackThread
|
||||||
extends Thread("sbt-command-exchange-maintenance")
|
extends Thread("sbt-command-exchange-fastTrack")
|
||||||
with AutoCloseable {
|
with AutoCloseable {
|
||||||
setDaemon(true)
|
setDaemon(true)
|
||||||
start()
|
start()
|
||||||
private[this] val isStopped = new AtomicBoolean(false)
|
private[this] val isStopped = new AtomicBoolean(false)
|
||||||
override def run(): Unit = {
|
override def run(): Unit = {
|
||||||
def exit(mt: MaintenanceTask): Unit = {
|
def exit(mt: FastTrackTask): Unit = {
|
||||||
mt.channel.shutdown(false)
|
mt.channel.shutdown(false)
|
||||||
if (mt.channel.name.contains("console")) shutdown(mt.channel.name)
|
if (mt.channel.name.contains("console")) shutdown(mt.channel.name)
|
||||||
}
|
}
|
||||||
@tailrec def impl(): Unit = {
|
@tailrec def impl(): Unit = {
|
||||||
maintenanceChannelQueue.take match {
|
fastTrackChannelQueue.take match {
|
||||||
case null =>
|
case null =>
|
||||||
case mt: MaintenanceTask =>
|
case mt: FastTrackTask =>
|
||||||
mt.task match {
|
mt.task match {
|
||||||
case `attach` => mt.channel.prompt(ConsolePromptEvent(lastState.get))
|
case `attach` => mt.channel.prompt(ConsolePromptEvent(lastState.get))
|
||||||
case "cancel" => Option(currentExecRef.get).foreach(cancel)
|
case "cancel" => Option(currentExecRef.get).foreach(cancel)
|
||||||
|
|
@ -435,5 +435,5 @@ private[sbt] final class CommandExchange {
|
||||||
}
|
}
|
||||||
private[sbt] def channelForName(channelName: String): Option[CommandChannel] =
|
private[sbt] def channelForName(channelName: String): Option[CommandChannel] =
|
||||||
channels.find(_.name == channelName)
|
channels.find(_.name == channelName)
|
||||||
private[this] val maintenanceThread = new MaintenanceThread
|
private[this] val fastTrackThread = new FastTrackThread
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ final class NetworkChannel(
|
||||||
attached.set(true)
|
attached.set(true)
|
||||||
pendingRequests.remove(id)
|
pendingRequests.remove(id)
|
||||||
jsonRpcRespond("", id)
|
jsonRpcRespond("", id)
|
||||||
initiateMaintenance(attach)
|
addFastTrackTask(attach)
|
||||||
}
|
}
|
||||||
private[sbt] def prompt(): Unit = {
|
private[sbt] def prompt(): Unit = {
|
||||||
terminal.setPrompt(Prompt.Running)
|
terminal.setPrompt(Prompt.Running)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue