src/Pure/PIDE/session.scala
author wenzelm
Tue, 29 Apr 2014 21:11:24 +0200
changeset 56793 d5ab6a8799ce
parent 56782 433cf57550fa
child 56799 00b13fb87b3a
permissions -rw-r--r--
more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
56210
c7c85cdb725d clarified module arrangement;
wenzelm
parents: 56208
diff changeset
     1
/*  Title:      Pure/PIDE/session.scala
36676
ac7961d42ac3 some rearrangement of Scala sources;
wenzelm
parents: 35013
diff changeset
     2
    Author:     Makarius
38221
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
     3
    Options:    :folding=explicit:collapseFolds=1:
36676
ac7961d42ac3 some rearrangement of Scala sources;
wenzelm
parents: 35013
diff changeset
     4
56210
c7c85cdb725d clarified module arrangement;
wenzelm
parents: 56208
diff changeset
     5
PIDE editor session, potentially with running prover process.
36676
ac7961d42ac3 some rearrangement of Scala sources;
wenzelm
parents: 35013
diff changeset
     6
*/
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
     7
34871
e596a0b71f3c incorporate "proofdocument" part into main Isabelle/Pure.jar -- except for html_panel.scala, which depends on external library (Lobo/Cobra browser);
wenzelm
parents: 34859
diff changeset
     8
package isabelle
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
     9
44733
329320fc88df buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents: 44732
diff changeset
    10
329320fc88df buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents: 44732
diff changeset
    11
import scala.collection.mutable
46771
06a9b24c4a36 explicit syslog_limit reduces danger of low-level message flooding;
wenzelm
parents: 46739
diff changeset
    12
import scala.collection.immutable.Queue
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
    13
34815
6bae73cd8e33 unified Command and Command_State, eliminated separate Accumulator;
wenzelm
parents: 34813
diff changeset
    14
34791
b97d5b38dea4 explicit object Session.Global_Settings;
wenzelm
parents: 34780
diff changeset
    15
object Session
b97d5b38dea4 explicit object Session.Global_Settings;
wenzelm
parents: 34780
diff changeset
    16
{
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    17
  /* outlets */
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    18
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    19
  object Consumer
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    20
  {
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    21
    def apply[A](name: String)(consume: A => Unit): Consumer[A] =
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    22
      new Consumer[A](name, consume)
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    23
  }
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    24
  final class Consumer[-A] private(val name: String, val consume: A => Unit)
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    25
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    26
  class Outlet[A](dispatcher: Consumer_Thread[() => Unit])
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    27
  {
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    28
    private val consumers = Synchronized(List.empty[Consumer[A]])
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    29
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    30
    def += (c: Consumer[A]) { consumers.change(Library.update(c)) }
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    31
    def -= (c: Consumer[A]) { consumers.change(Library.remove(c)) }
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    32
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    33
    def post(a: A)
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    34
    {
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    35
      for (c <- consumers.value.iterator) {
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    36
        dispatcher.send(() =>
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    37
          try { c.consume(a) }
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    38
          catch {
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    39
            case exn: Throwable =>
56782
433cf57550fa more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents: 56775
diff changeset
    40
              Output.error_message("Consumer failed: " + quote(c.name) + "\n" + Exn.message(exn))
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    41
          })
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    42
      }
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    43
    }
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    44
  }
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    45
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
    46
56315
c20053f67093 tuned signature;
wenzelm
parents: 56210
diff changeset
    47
  /* change */
c20053f67093 tuned signature;
wenzelm
parents: 56210
diff changeset
    48
c20053f67093 tuned signature;
wenzelm
parents: 56210
diff changeset
    49
  sealed case class Change(
c20053f67093 tuned signature;
wenzelm
parents: 56210
diff changeset
    50
    previous: Document.Version,
c20053f67093 tuned signature;
wenzelm
parents: 56210
diff changeset
    51
    doc_blobs: Document.Blobs,
c20053f67093 tuned signature;
wenzelm
parents: 56210
diff changeset
    52
    syntax_changed: Boolean,
56316
b1cf8ddc2e04 propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
wenzelm
parents: 56315
diff changeset
    53
    deps_changed: Boolean,
56315
c20053f67093 tuned signature;
wenzelm
parents: 56210
diff changeset
    54
    doc_edits: List[Document.Edit_Command],
c20053f67093 tuned signature;
wenzelm
parents: 56210
diff changeset
    55
    version: Document.Version)
c20053f67093 tuned signature;
wenzelm
parents: 56210
diff changeset
    56
c20053f67093 tuned signature;
wenzelm
parents: 56210
diff changeset
    57
34813
f0107bc96961 more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents: 34810
diff changeset
    58
  /* events */
f0107bc96961 more explicit modeling of Command and Command_State as Session.Entity;
wenzelm
parents: 34810
diff changeset
    59
43716
1d64662c1bfd tuned source structure;
wenzelm
parents: 43697
diff changeset
    60
  //{{{
50697
82e9178e6a98 improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents: 50566
diff changeset
    61
  case class Statistics(props: Properties.T)
50117
32755e357a51 update options via protocol;
wenzelm
parents: 49524
diff changeset
    62
  case class Global_Options(options: Options)
44805
48a5c104d434 clarified terminology;
wenzelm
parents: 44775
diff changeset
    63
  case object Caret_Focus
54521
744ea0025e11 clarified Document.Blobs environment vs. actual edits of auxiliary files;
wenzelm
parents: 54519
diff changeset
    64
  case class Raw_Edits(doc_blobs: Document.Blobs, edits: List[Document.Edit_Text])
52531
21f8e0e151f5 tuned signature;
wenzelm
parents: 52530
diff changeset
    65
  case class Dialog_Result(id: Document_ID.Generic, serial: Long, result: String)
47027
fc3bb6c02a3c explicit propagation of assignment event, even if changed command set is empty;
wenzelm
parents: 46944
diff changeset
    66
  case class Commands_Changed(
fc3bb6c02a3c explicit propagation of assignment event, even if changed command set is empty;
wenzelm
parents: 46944
diff changeset
    67
    assignment: Boolean, nodes: Set[Document.Node.Name], commands: Set[Command])
39630
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
    68
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
    69
  sealed abstract class Phase
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
    70
  case object Inactive extends Phase
39701
7c351c1c0624 simplified / clarified Session.Phase;
wenzelm
parents: 39698
diff changeset
    71
  case object Startup extends Phase  // transient
7c351c1c0624 simplified / clarified Session.Phase;
wenzelm
parents: 39698
diff changeset
    72
  case object Failed extends Phase
39630
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
    73
  case object Ready extends Phase
39701
7c351c1c0624 simplified / clarified Session.Phase;
wenzelm
parents: 39698
diff changeset
    74
  case object Shutdown extends Phase  // transient
43716
1d64662c1bfd tuned source structure;
wenzelm
parents: 43697
diff changeset
    75
  //}}}
52111
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
    76
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
    77
56775
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
    78
  /* syslog */
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
    79
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
    80
  private[Session] class Syslog(limit: Int)
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
    81
  {
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
    82
    private var queue = Queue.empty[XML.Elem]
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
    83
    private var length = 0
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
    84
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
    85
    def += (msg: XML.Elem): Unit = synchronized {
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
    86
      queue = queue.enqueue(msg)
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
    87
      length += 1
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
    88
      if (length > limit) queue = queue.dequeue._2
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
    89
    }
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
    90
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
    91
    def content: String = synchronized {
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
    92
      cat_lines(queue.iterator.map(XML.content)) +
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
    93
      (if (length > limit) "\n(A total of " + length + " messages...)" else "")
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
    94
    }
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
    95
  }
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
    96
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
    97
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
    98
52111
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
    99
  /* protocol handlers */
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   100
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   101
  abstract class Protocol_Handler
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   102
  {
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   103
    def stop(prover: Prover): Unit = {}
56385
76acce58aeab more general prover operations;
wenzelm
parents: 56335
diff changeset
   104
    val functions: Map[String, (Prover, Prover.Protocol_Output) => Boolean]
52111
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   105
  }
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   106
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   107
  class Protocol_Handlers(
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   108
    handlers: Map[String, Session.Protocol_Handler] = Map.empty,
56385
76acce58aeab more general prover operations;
wenzelm
parents: 56335
diff changeset
   109
    functions: Map[String, Prover.Protocol_Output => Boolean] = Map.empty)
52111
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   110
  {
53054
8365d7fca3de public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents: 52931
diff changeset
   111
    def get(name: String): Option[Protocol_Handler] = handlers.get(name)
8365d7fca3de public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents: 52931
diff changeset
   112
52111
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   113
    def add(prover: Prover, name: String): Protocol_Handlers =
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   114
    {
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   115
      val (handlers1, functions1) =
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   116
        handlers.get(name) match {
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   117
          case Some(old_handler) =>
56782
433cf57550fa more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents: 56775
diff changeset
   118
            Output.warning("Redefining protocol handler: " + name)
52111
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   119
            old_handler.stop(prover)
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   120
            (handlers - name, functions -- old_handler.functions.keys)
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   121
          case None => (handlers, functions)
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   122
        }
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   123
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   124
      val (handlers2, functions2) =
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   125
        try {
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   126
          val new_handler = Class.forName(name).newInstance.asInstanceOf[Protocol_Handler]
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   127
          val new_functions =
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   128
            for ((a, f) <- new_handler.functions.toList) yield
56385
76acce58aeab more general prover operations;
wenzelm
parents: 56335
diff changeset
   129
              (a, (msg: Prover.Protocol_Output) => f(prover, msg))
52111
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   130
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   131
          val dups = for ((a, _) <- new_functions if functions1.isDefinedAt(a)) yield a
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   132
          if (!dups.isEmpty) error("Duplicate protocol functions: " + commas_quote(dups))
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   133
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   134
          (handlers1 + (name -> new_handler), functions1 ++ new_functions)
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   135
        }
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   136
        catch {
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   137
          case exn: Throwable =>
56782
433cf57550fa more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents: 56775
diff changeset
   138
            Output.error_message(
433cf57550fa more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents: 56775
diff changeset
   139
              "Failed to initialize protocol handler: " + quote(name) + "\n" + Exn.message(exn))
52111
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   140
            (handlers1, functions1)
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   141
        }
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   142
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   143
      new Protocol_Handlers(handlers2, functions2)
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   144
    }
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   145
56385
76acce58aeab more general prover operations;
wenzelm
parents: 56335
diff changeset
   146
    def invoke(msg: Prover.Protocol_Output): Boolean =
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   147
      msg.properties match {
52111
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   148
        case Markup.Function(a) if functions.isDefinedAt(a) =>
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   149
          try { functions(a)(msg) }
52111
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   150
          catch {
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   151
            case exn: Throwable =>
56782
433cf57550fa more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents: 56775
diff changeset
   152
              Output.error_message(
433cf57550fa more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents: 56775
diff changeset
   153
                "Failed invocation of protocol function: " + quote(a) + "\n" + Exn.message(exn))
52111
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   154
            false
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   155
          }
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   156
        case _ => false
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   157
      }
52113
2d2b049429f3 stop protocol handlers as well;
wenzelm
parents: 52111
diff changeset
   158
2d2b049429f3 stop protocol handlers as well;
wenzelm
parents: 52111
diff changeset
   159
    def stop(prover: Prover): Protocol_Handlers =
2d2b049429f3 stop protocol handlers as well;
wenzelm
parents: 52111
diff changeset
   160
    {
2d2b049429f3 stop protocol handlers as well;
wenzelm
parents: 52111
diff changeset
   161
      for ((_, handler) <- handlers) handler.stop(prover)
2d2b049429f3 stop protocol handlers as well;
wenzelm
parents: 52111
diff changeset
   162
      new Protocol_Handlers()
2d2b049429f3 stop protocol handlers as well;
wenzelm
parents: 52111
diff changeset
   163
    }
52111
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   164
  }
34791
b97d5b38dea4 explicit object Session.Global_Settings;
wenzelm
parents: 34780
diff changeset
   165
}
b97d5b38dea4 explicit object Session.Global_Settings;
wenzelm
parents: 34780
diff changeset
   166
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   167
56208
06cc31dff138 clarifed module name;
wenzelm
parents: 55801
diff changeset
   168
class Session(val resources: Resources)
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   169
{
47653
4605d4341b8b some builtin session timing;
wenzelm
parents: 47629
diff changeset
   170
  /* global flags */
4605d4341b8b some builtin session timing;
wenzelm
parents: 47629
diff changeset
   171
4605d4341b8b some builtin session timing;
wenzelm
parents: 47629
diff changeset
   172
  @volatile var timing: Boolean = false
4605d4341b8b some builtin session timing;
wenzelm
parents: 47629
diff changeset
   173
  @volatile var verbose: Boolean = false
4605d4341b8b some builtin session timing;
wenzelm
parents: 47629
diff changeset
   174
4605d4341b8b some builtin session timing;
wenzelm
parents: 47629
diff changeset
   175
49288
2c9272cb4568 more options;
wenzelm
parents: 49250
diff changeset
   176
  /* tuning parameters */
2c9272cb4568 more options;
wenzelm
parents: 49250
diff changeset
   177
2c9272cb4568 more options;
wenzelm
parents: 49250
diff changeset
   178
  def output_delay: Time = Time.seconds(0.1)  // prover output (markup, common messages)
52800
1baa5d19ac44 less aggressive flushing: cope with massive amounts of protocol messages, e.g. from threads_trace;
wenzelm
parents: 52766
diff changeset
   179
  def message_delay: Time = Time.seconds(0.1)  // prover input/output messages
49293
afcccb9bfa3b prefer tuning parameters as public methods (again) -- to allow overriding in applications;
wenzelm
parents: 49288
diff changeset
   180
  def prune_delay: Time = Time.seconds(60.0)  // prune history -- delete old versions
afcccb9bfa3b prefer tuning parameters as public methods (again) -- to allow overriding in applications;
wenzelm
parents: 49288
diff changeset
   181
  def prune_size: Int = 0  // size of retained history
afcccb9bfa3b prefer tuning parameters as public methods (again) -- to allow overriding in applications;
wenzelm
parents: 49288
diff changeset
   182
  def syslog_limit: Int = 100
49524
68796a77c42b Thy_Syntax.consolidate_spans is subject to editor_reparse_limit, for improved experience of unbalanced comments etc.;
wenzelm
parents: 49523
diff changeset
   183
  def reparse_limit: Int = 0
37849
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
   184
4f9de312cc23 Session: predefined real time parameters;
wenzelm
parents: 37689
diff changeset
   185
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
   186
  /* outlets */
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
   187
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
   188
  private val dispatcher =
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
   189
    Consumer_Thread.fork[() => Unit]("Session.dispatcher", daemon = true) { case e => e(); true }
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   190
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
   191
  val statistics = new Session.Outlet[Session.Statistics](dispatcher)
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
   192
  val global_options = new Session.Outlet[Session.Global_Options](dispatcher)
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
   193
  val caret_focus = new Session.Outlet[Session.Caret_Focus.type](dispatcher)
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
   194
  val raw_edits = new Session.Outlet[Session.Raw_Edits](dispatcher)
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
   195
  val commands_changed = new Session.Outlet[Session.Commands_Changed](dispatcher)
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
   196
  val phase_changed = new Session.Outlet[Session.Phase](dispatcher)
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
   197
  val syslog_messages = new Session.Outlet[Prover.Output](dispatcher)
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
   198
  val raw_output_messages = new Session.Outlet[Prover.Output](dispatcher)
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
   199
  val all_messages = new Session.Outlet[Prover.Message](dispatcher)  // potential bottle-neck
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
   200
  val trace_events = new Session.Outlet[Simplifier_Trace.Event.type](dispatcher)
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   201
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   202
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   203
45635
d9cf3520083c explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents: 45633
diff changeset
   204
  /** pipelined change parsing **/
d9cf3520083c explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents: 45633
diff changeset
   205
d9cf3520083c explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents: 45633
diff changeset
   206
  private case class Text_Edits(
d9cf3520083c explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents: 45633
diff changeset
   207
    previous: Future[Document.Version],
54521
744ea0025e11 clarified Document.Blobs environment vs. actual edits of auxiliary files;
wenzelm
parents: 54519
diff changeset
   208
    doc_blobs: Document.Blobs,
45635
d9cf3520083c explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents: 45633
diff changeset
   209
    text_edits: List[Document.Edit_Text],
d9cf3520083c explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents: 45633
diff changeset
   210
    version_result: Promise[Document.Version])
d9cf3520083c explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents: 45633
diff changeset
   211
56704
c2f0ddd14747 simplified -- prefer Consumer_Thread over Actor;
wenzelm
parents: 56691
diff changeset
   212
  private val change_parser = Consumer_Thread.fork[Text_Edits]("change_parser", daemon = true)
45635
d9cf3520083c explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents: 45633
diff changeset
   213
  {
56704
c2f0ddd14747 simplified -- prefer Consumer_Thread over Actor;
wenzelm
parents: 56691
diff changeset
   214
    case Text_Edits(previous, doc_blobs, text_edits, version_result) =>
c2f0ddd14747 simplified -- prefer Consumer_Thread over Actor;
wenzelm
parents: 56691
diff changeset
   215
      val prev = previous.get_finished
c2f0ddd14747 simplified -- prefer Consumer_Thread over Actor;
wenzelm
parents: 56691
diff changeset
   216
      val change =
c2f0ddd14747 simplified -- prefer Consumer_Thread over Actor;
wenzelm
parents: 56691
diff changeset
   217
        Timing.timeit("parse_change", timing) {
c2f0ddd14747 simplified -- prefer Consumer_Thread over Actor;
wenzelm
parents: 56691
diff changeset
   218
          resources.parse_change(reparse_limit, prev, doc_blobs, text_edits)
c2f0ddd14747 simplified -- prefer Consumer_Thread over Actor;
wenzelm
parents: 56691
diff changeset
   219
        }
c2f0ddd14747 simplified -- prefer Consumer_Thread over Actor;
wenzelm
parents: 56691
diff changeset
   220
      version_result.fulfill(change.version)
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   221
      manager.send(change)
56704
c2f0ddd14747 simplified -- prefer Consumer_Thread over Actor;
wenzelm
parents: 56691
diff changeset
   222
      true
45635
d9cf3520083c explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents: 45633
diff changeset
   223
  }
d9cf3520083c explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents: 45633
diff changeset
   224
38841
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   225
47653
4605d4341b8b some builtin session timing;
wenzelm
parents: 47629
diff changeset
   226
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   227
  /** main protocol manager **/
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   228
43651
511df47bcadc some support for theory files within Isabelle/Scala session;
wenzelm
parents: 43649
diff changeset
   229
  /* global state */
43644
ea08ce1c314b tuned signature;
wenzelm
parents: 43553
diff changeset
   230
56775
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
   231
  private val syslog = new Session.Syslog(syslog_limit)
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
   232
  def syslog_content(): String = syslog.content
39626
a5d0bcfb95a3 manage persistent syslog via Session, not Isabelle_Process;
wenzelm
parents: 39625
diff changeset
   233
39630
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
   234
  @volatile private var _phase: Session.Phase = Session.Inactive
39633
26a28110ece5 simplified Session.Phase;
wenzelm
parents: 39630
diff changeset
   235
  private def phase_=(new_phase: Session.Phase)
39630
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
   236
  {
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
   237
    _phase = new_phase
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
   238
    phase_changed.post(new_phase)
39630
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
   239
  }
43716
1d64662c1bfd tuned source structure;
wenzelm
parents: 43697
diff changeset
   240
  def phase = _phase
43553
df80747342cb proper tokens only if session is ready;
wenzelm
parents: 43520
diff changeset
   241
  def is_ready: Boolean = phase == Session.Ready
39630
44181423183a explicit Session.Phase indication with associated event bus;
wenzelm
parents: 39629
diff changeset
   242
56690
69b31dc7256e eliminated redundant Volatile;
wenzelm
parents: 56687
diff changeset
   243
  private val global_state = Synchronized(Document.State.init)
56687
7fb98325722a tuned signature in accordance to ML version;
wenzelm
parents: 56671
diff changeset
   244
  def current_state(): Document.State = global_state.value
46944
9fc22eb6408c more recent recent_syntax, e.g. relevant for document rendering during startup;
wenzelm
parents: 46942
diff changeset
   245
56393
22f533e6a049 more abstract Prover.Syntax, as proposed by Carst Tankink;
wenzelm
parents: 56387
diff changeset
   246
  def recent_syntax(): Prover.Syntax =
46944
9fc22eb6408c more recent recent_syntax, e.g. relevant for document rendering during startup;
wenzelm
parents: 46942
diff changeset
   247
  {
9fc22eb6408c more recent recent_syntax, e.g. relevant for document rendering during startup;
wenzelm
parents: 46942
diff changeset
   248
    val version = current_state().recent_finished.version.get_finished
56394
bbf4d512f395 clarified Version.syntax -- avoid guessing initial situation;
wenzelm
parents: 56393
diff changeset
   249
    version.syntax getOrElse resources.base_syntax
46944
9fc22eb6408c more recent recent_syntax, e.g. relevant for document rendering during startup;
wenzelm
parents: 46942
diff changeset
   250
  }
34816
d33312514220 maintain generic session entities -- cover commands, states, etc. (but not yet documents);
wenzelm
parents: 34815
diff changeset
   251
44960
640c2b957f16 graph traversal in topological order;
wenzelm
parents: 44953
diff changeset
   252
  def snapshot(name: Document.Node.Name = Document.Node.Name.empty,
640c2b957f16 graph traversal in topological order;
wenzelm
parents: 44953
diff changeset
   253
      pending_edits: List[Text.Edit] = Nil): Document.Snapshot =
56687
7fb98325722a tuned signature in accordance to ML version;
wenzelm
parents: 56671
diff changeset
   254
    global_state.value.snapshot(name, pending_edits)
43716
1d64662c1bfd tuned source structure;
wenzelm
parents: 43697
diff changeset
   255
43651
511df47bcadc some support for theory files within Isabelle/Scala session;
wenzelm
parents: 43649
diff changeset
   256
53054
8365d7fca3de public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents: 52931
diff changeset
   257
  /* protocol handlers */
8365d7fca3de public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents: 52931
diff changeset
   258
8365d7fca3de public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents: 52931
diff changeset
   259
  @volatile private var _protocol_handlers = new Session.Protocol_Handlers()
8365d7fca3de public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents: 52931
diff changeset
   260
8365d7fca3de public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents: 52931
diff changeset
   261
  def protocol_handler(name: String): Option[Session.Protocol_Handler] =
8365d7fca3de public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents: 52931
diff changeset
   262
    _protocol_handlers.get(name)
8365d7fca3de public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents: 52931
diff changeset
   263
8365d7fca3de public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents: 52931
diff changeset
   264
43651
511df47bcadc some support for theory files within Isabelle/Scala session;
wenzelm
parents: 43649
diff changeset
   265
  /* theory files */
511df47bcadc some support for theory files within Isabelle/Scala session;
wenzelm
parents: 43649
diff changeset
   266
48707
ba531af91148 simplified Document.Node.Header -- internalized errors;
wenzelm
parents: 48422
diff changeset
   267
  def header_edit(name: Document.Node.Name, header: Document.Node.Header): Document.Edit_Text =
44442
cb18e4f09053 clarified norm_header/header_edit -- disallow update of loaded theories;
wenzelm
parents: 44436
diff changeset
   268
  {
48707
ba531af91148 simplified Document.Node.Header -- internalized errors;
wenzelm
parents: 48422
diff changeset
   269
    val header1 =
56208
06cc31dff138 clarifed module name;
wenzelm
parents: 55801
diff changeset
   270
      if (resources.loaded_theories(name.theory))
54559
39d91cac6e91 tuned messages;
wenzelm
parents: 54521
diff changeset
   271
        header.error("Cannot update finished theory " + quote(name.theory))
48707
ba531af91148 simplified Document.Node.Header -- internalized errors;
wenzelm
parents: 48422
diff changeset
   272
      else header
ba531af91148 simplified Document.Node.Header -- internalized errors;
wenzelm
parents: 48422
diff changeset
   273
    (name, Document.Node.Deps(header1))
44442
cb18e4f09053 clarified norm_header/header_edit -- disallow update of loaded theories;
wenzelm
parents: 44436
diff changeset
   274
  }
cb18e4f09053 clarified norm_header/header_edit -- disallow update of loaded theories;
wenzelm
parents: 44436
diff changeset
   275
43651
511df47bcadc some support for theory files within Isabelle/Scala session;
wenzelm
parents: 43649
diff changeset
   276
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   277
  /* internal messages */
43651
511df47bcadc some support for theory files within Isabelle/Scala session;
wenzelm
parents: 43649
diff changeset
   278
56387
d92eb5c3960d more general prover operations;
wenzelm
parents: 56385
diff changeset
   279
  private case class Start(name: String, args: List[String])
56709
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   280
  private case object Stop
52931
ac6648c0c0fb cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents: 52800
diff changeset
   281
  private case class Cancel_Exec(exec_id: Document_ID.Exec)
53054
8365d7fca3de public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents: 52931
diff changeset
   282
  private case class Protocol_Command(name: String, args: List[String])
52084
573e80625c78 more explicit Session.update_options as source of Global_Options event;
wenzelm
parents: 51818
diff changeset
   283
  private case class Update_Options(options: Options)
56771
28d62a5b07e8 more systematic delay_first discipline for change_buffer and prune_history;
wenzelm
parents: 56735
diff changeset
   284
  private case object Prune_History
41534
f36cb6f233bd less verbosity;
wenzelm
parents: 40848
diff changeset
   285
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   286
56719
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   287
  /* buffered changes */
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   288
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   289
  private object change_buffer
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   290
  {
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   291
    private var assignment: Boolean = false
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   292
    private var nodes: Set[Document.Node.Name] = Set.empty
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   293
    private var commands: Set[Command] = Set.empty
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   294
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   295
    def flush(): Unit = synchronized {
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   296
      if (assignment || !nodes.isEmpty || !commands.isEmpty)
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   297
        commands_changed.post(Session.Commands_Changed(assignment, nodes, commands))
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   298
      assignment = false
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   299
      nodes = Set.empty
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   300
      commands = Set.empty
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   301
    }
56771
28d62a5b07e8 more systematic delay_first discipline for change_buffer and prune_history;
wenzelm
parents: 56735
diff changeset
   302
    private val delay_flush = Simple_Thread.delay_first(output_delay) { flush() }
56719
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   303
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   304
    def invoke(assign: Boolean, cmds: List[Command]): Unit = synchronized {
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   305
      assignment |= assign
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   306
      for (command <- cmds) {
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   307
        nodes += command.node_name
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   308
        commands += command
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   309
      }
56771
28d62a5b07e8 more systematic delay_first discipline for change_buffer and prune_history;
wenzelm
parents: 56735
diff changeset
   310
      delay_flush.invoke()
56719
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   311
    }
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   312
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   313
    def shutdown()
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   314
    {
56771
28d62a5b07e8 more systematic delay_first discipline for change_buffer and prune_history;
wenzelm
parents: 56735
diff changeset
   315
      delay_flush.revoke()
56719
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   316
      flush()
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   317
    }
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   318
  }
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   319
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   320
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   321
  /* postponed changes */
44733
329320fc88df buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents: 44732
diff changeset
   322
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   323
  private object postponed_changes
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   324
  {
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   325
    private var postponed: List[Session.Change] = Nil
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   326
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   327
    def store(change: Session.Change): Unit = synchronized { postponed ::= change }
56705
937826d702d5 simplified commands_changed_buffer (in contrast to a8331fb5c959): rely on better performance of Consumer_Thread/Mailbox and more direct Timer (like session_actor.receiver);
wenzelm
parents: 56704
diff changeset
   328
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   329
    def flush(): Unit = synchronized {
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   330
      val state = global_state.value
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   331
      val (assigned, unassigned) = postponed.partition(change => state.is_assigned(change.previous))
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   332
      postponed = unassigned
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   333
      assigned.reverseIterator.foreach(change => manager.send(change))
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   334
    }
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   335
  }
44733
329320fc88df buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents: 44732
diff changeset
   336
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   337
56793
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   338
  /* prover process */
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   339
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   340
  private object prover
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   341
  {
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   342
    private val variable = Synchronized(None: Option[Prover])
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   343
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   344
    def defined: Boolean = variable.value.isDefined
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   345
    def get: Prover = variable.value.get
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   346
    def set(p: Prover) { variable.change(_ => Some(p)) }
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   347
    def reset { variable.change(_ => None) }
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   348
    def await_reset() { variable.guarded_access({ case None => Some((), None) case _ => None }) }
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   349
  }
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   350
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   351
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   352
  /* manager thread */
44733
329320fc88df buffer prover messages to prevent overloading of session_actor input channel -- which is critical due to synchronous messages wrt. GUI thread;
wenzelm
parents: 44732
diff changeset
   353
56771
28d62a5b07e8 more systematic delay_first discipline for change_buffer and prune_history;
wenzelm
parents: 56735
diff changeset
   354
  private val delay_prune = Simple_Thread.delay_first(prune_delay) { manager.send(Prune_History) }
28d62a5b07e8 more systematic delay_first discipline for change_buffer and prune_history;
wenzelm
parents: 56735
diff changeset
   355
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   356
  private val manager: Consumer_Thread[Any] =
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   357
  {
52649
f45ab3e8211b update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents: 52563
diff changeset
   358
    /* raw edits */
f45ab3e8211b update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents: 52563
diff changeset
   359
54521
744ea0025e11 clarified Document.Blobs environment vs. actual edits of auxiliary files;
wenzelm
parents: 54519
diff changeset
   360
    def handle_raw_edits(doc_blobs: Document.Blobs, edits: List[Document.Edit_Text])
52649
f45ab3e8211b update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents: 52563
diff changeset
   361
    //{{{
f45ab3e8211b update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents: 52563
diff changeset
   362
    {
56793
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   363
      require(prover.defined)
56712
c7cf653228ed more explicit checks;
wenzelm
parents: 56711
diff changeset
   364
52649
f45ab3e8211b update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents: 52563
diff changeset
   365
      prover.get.discontinue_execution()
f45ab3e8211b update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents: 52563
diff changeset
   366
56687
7fb98325722a tuned signature in accordance to ML version;
wenzelm
parents: 56671
diff changeset
   367
      val previous = global_state.value.history.tip.version
52649
f45ab3e8211b update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents: 52563
diff changeset
   368
      val version = Future.promise[Document.Version]
56711
ef3d00153e3b tuned signature;
wenzelm
parents: 56710
diff changeset
   369
      global_state.change(_.continue_history(previous, edits, version))
52649
f45ab3e8211b update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents: 52563
diff changeset
   370
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
   371
      raw_edits.post(Session.Raw_Edits(doc_blobs, edits))
56704
c2f0ddd14747 simplified -- prefer Consumer_Thread over Actor;
wenzelm
parents: 56691
diff changeset
   372
      change_parser.send(Text_Edits(previous, doc_blobs, edits, version))
52649
f45ab3e8211b update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents: 52563
diff changeset
   373
    }
f45ab3e8211b update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents: 52563
diff changeset
   374
    //}}}
f45ab3e8211b update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents: 52563
diff changeset
   375
f45ab3e8211b update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents: 52563
diff changeset
   376
43716
1d64662c1bfd tuned source structure;
wenzelm
parents: 43697
diff changeset
   377
    /* resulting changes */
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   378
56315
c20053f67093 tuned signature;
wenzelm
parents: 56210
diff changeset
   379
    def handle_change(change: Session.Change)
38221
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
   380
    //{{{
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   381
    {
56793
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   382
      require(prover.defined)
56712
c7cf653228ed more explicit checks;
wenzelm
parents: 56711
diff changeset
   383
44383
f99906c2a1d3 discontinued redundant Edit_Command_ID;
wenzelm
parents: 44298
diff changeset
   384
      def id_command(command: Command)
43720
wenzelm
parents: 43719
diff changeset
   385
      {
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54443
diff changeset
   386
        for {
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54443
diff changeset
   387
          digest <- command.blobs_digests
56687
7fb98325722a tuned signature in accordance to ML version;
wenzelm
parents: 56671
diff changeset
   388
          if !global_state.value.defined_blob(digest)
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54443
diff changeset
   389
        } {
56315
c20053f67093 tuned signature;
wenzelm
parents: 56210
diff changeset
   390
          change.doc_blobs.get(digest) match {
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54443
diff changeset
   391
            case Some(blob) =>
56687
7fb98325722a tuned signature in accordance to ML version;
wenzelm
parents: 56671
diff changeset
   392
              global_state.change(_.define_blob(digest))
56335
8953d4cc060a store blob content within document node: aux. files that were once open are made persistent;
wenzelm
parents: 56316
diff changeset
   393
              prover.get.define_blob(digest, blob.bytes)
55783
da0513d95155 more formal Document.Blobs;
wenzelm
parents: 55618
diff changeset
   394
            case None =>
56782
433cf57550fa more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents: 56775
diff changeset
   395
              Output.error_message("Missing blob for SHA1 digest " + digest)
54519
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54443
diff changeset
   396
          }
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54443
diff changeset
   397
        }
5fed81762406 maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents: 54443
diff changeset
   398
56687
7fb98325722a tuned signature in accordance to ML version;
wenzelm
parents: 56671
diff changeset
   399
        if (!global_state.value.defined_command(command.id)) {
7fb98325722a tuned signature in accordance to ML version;
wenzelm
parents: 56671
diff changeset
   400
          global_state.change(_.define_command(command))
44644
317e4962dd0f clarified define_command: store name as structural information;
wenzelm
parents: 44616
diff changeset
   401
          prover.get.define_command(command)
43720
wenzelm
parents: 43719
diff changeset
   402
        }
wenzelm
parents: 43719
diff changeset
   403
      }
56315
c20053f67093 tuned signature;
wenzelm
parents: 56210
diff changeset
   404
      change.doc_edits foreach {
44383
f99906c2a1d3 discontinued redundant Edit_Command_ID;
wenzelm
parents: 44298
diff changeset
   405
        case (_, edit) =>
f99906c2a1d3 discontinued redundant Edit_Command_ID;
wenzelm
parents: 44298
diff changeset
   406
          edit foreach { case (c1, c2) => c1 foreach id_command; c2 foreach id_command }
f99906c2a1d3 discontinued redundant Edit_Command_ID;
wenzelm
parents: 44298
diff changeset
   407
      }
43722
9b5dadb0c28d propagate header changes to prover process;
wenzelm
parents: 43721
diff changeset
   408
56687
7fb98325722a tuned signature in accordance to ML version;
wenzelm
parents: 56671
diff changeset
   409
      val assignment = global_state.value.the_assignment(change.previous).check_finished
7fb98325722a tuned signature in accordance to ML version;
wenzelm
parents: 56671
diff changeset
   410
      global_state.change(_.define_version(change.version, assignment))
56315
c20053f67093 tuned signature;
wenzelm
parents: 56210
diff changeset
   411
      prover.get.update(change.previous.id, change.version.id, change.doc_edits)
56316
b1cf8ddc2e04 propagate deps_changed, to resolve missing files without requiring jEdit events (e.g. buffer load/save);
wenzelm
parents: 56315
diff changeset
   412
      resources.commit(change)
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   413
    }
38221
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
   414
    //}}}
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   415
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   416
46772
be21f050eda4 tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents: 46771
diff changeset
   417
    /* prover output */
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   418
56385
76acce58aeab more general prover operations;
wenzelm
parents: 56335
diff changeset
   419
    def handle_output(output: Prover.Output)
38221
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
   420
    //{{{
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   421
    {
51662
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51083
diff changeset
   422
      def bad_output()
43716
1d64662c1bfd tuned source structure;
wenzelm
parents: 43697
diff changeset
   423
      {
1d64662c1bfd tuned source structure;
wenzelm
parents: 43697
diff changeset
   424
        if (verbose)
56782
433cf57550fa more systematic Isabelle output, like in classic Isabelle/ML (without markup);
wenzelm
parents: 56775
diff changeset
   425
          Output.warning("Ignoring bad prover output: " + output.message.toString)
43716
1d64662c1bfd tuned source structure;
wenzelm
parents: 43697
diff changeset
   426
      }
1d64662c1bfd tuned source structure;
wenzelm
parents: 43697
diff changeset
   427
52531
21f8e0e151f5 tuned signature;
wenzelm
parents: 52530
diff changeset
   428
      def accumulate(state_id: Document_ID.Generic, message: XML.Elem)
51662
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51083
diff changeset
   429
      {
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51083
diff changeset
   430
        try {
56687
7fb98325722a tuned signature in accordance to ML version;
wenzelm
parents: 56671
diff changeset
   431
          val st = global_state.change_result(_.accumulate(state_id, message))
56719
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   432
          change_buffer.invoke(false, List(st.command))
51662
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51083
diff changeset
   433
        }
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51083
diff changeset
   434
        catch {
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51083
diff changeset
   435
          case _: Document.State.Fail => bad_output()
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51083
diff changeset
   436
        }
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51083
diff changeset
   437
      }
3391a493f39a just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents: 51083
diff changeset
   438
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   439
      output match {
56385
76acce58aeab more general prover operations;
wenzelm
parents: 56335
diff changeset
   440
        case msg: Prover.Protocol_Output =>
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   441
          val handled = _protocol_handlers.invoke(msg)
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   442
          if (!handled) {
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   443
            msg.properties match {
56793
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   444
              case Markup.Protocol_Handler(name) if prover.defined =>
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   445
                _protocol_handlers = _protocol_handlers.add(prover.get, name)
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   446
56793
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   447
              case Protocol.Command_Timing(state_id, timing) if prover.defined =>
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   448
                val message = XML.elem(Markup.STATUS, List(XML.Elem(Markup.Timing(timing), Nil)))
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   449
                accumulate(state_id, prover.get.xml_cache.elem(message))
46122
1e9ec1a44dfc prefer raw_message for protocol implementation;
wenzelm
parents: 46121
diff changeset
   450
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   451
              case Markup.Assign_Update =>
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   452
                msg.text match {
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   453
                  case Protocol.Assign_Update(id, update) =>
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   454
                    try {
56687
7fb98325722a tuned signature in accordance to ML version;
wenzelm
parents: 56671
diff changeset
   455
                      val cmds = global_state.change_result(_.assign(id, update))
56719
80eb2192516a simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents: 56715
diff changeset
   456
                      change_buffer.invoke(true, cmds)
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   457
                    }
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   458
                    catch { case _: Document.State.Fail => bad_output() }
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   459
                    postponed_changes.flush()
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   460
                  case _ => bad_output()
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   461
                }
56771
28d62a5b07e8 more systematic delay_first discipline for change_buffer and prune_history;
wenzelm
parents: 56735
diff changeset
   462
                delay_prune.invoke()
46122
1e9ec1a44dfc prefer raw_message for protocol implementation;
wenzelm
parents: 46121
diff changeset
   463
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   464
              case Markup.Removed_Versions =>
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   465
                msg.text match {
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   466
                  case Protocol.Removed(removed) =>
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   467
                    try {
56687
7fb98325722a tuned signature in accordance to ML version;
wenzelm
parents: 56671
diff changeset
   468
                      global_state.change(_.removed_versions(removed))
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   469
                    }
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   470
                    catch { case _: Document.State.Fail => bad_output() }
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   471
                  case _ => bad_output()
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   472
                }
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   473
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   474
              case Markup.ML_Statistics(props) =>
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
   475
                statistics.post(Session.Statistics(props))
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   476
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   477
              case Markup.Task_Statistics(props) =>
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   478
                // FIXME
52111
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   479
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   480
              case _ => bad_output()
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   481
            }
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   482
          }
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   483
        case _ =>
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   484
          output.properties match {
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   485
            case Position.Id(state_id) =>
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   486
              accumulate(state_id, output.message)
56210
c7c85cdb725d clarified module arrangement;
wenzelm
parents: 56208
diff changeset
   487
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   488
            case _ if output.is_init =>
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   489
              phase = Session.Ready
56210
c7c85cdb725d clarified module arrangement;
wenzelm
parents: 56208
diff changeset
   490
54442
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   491
            case Markup.Return_Code(rc) if output.is_exit =>
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   492
              if (rc == 0) phase = Session.Inactive
c39972ddd672 more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents: 53054
diff changeset
   493
              else phase = Session.Failed
56793
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   494
              prover.reset
56210
c7c85cdb725d clarified module arrangement;
wenzelm
parents: 56208
diff changeset
   495
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
   496
            case _ => raw_output_messages.post(output)
44661
383c9d758a56 raw message function "assign_execs" avoids full overhead of decoding and caching message body;
wenzelm
parents: 44644
diff changeset
   497
          }
52111
1fd184eaa310 explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents: 52084
diff changeset
   498
        }
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   499
    }
38221
e0f00f0945b4 misc tuning and clarification;
wenzelm
parents: 38150
diff changeset
   500
    //}}}
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   501
34820
a8ba6cde13e9 basic setup for synchronous / modal (!) prover startup;
wenzelm
parents: 34819
diff changeset
   502
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   503
    /* main thread */
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   504
56710
8f102c18eab7 more uniform warning/error handling, potentially with propagation to send_wait caller;
wenzelm
parents: 56709
diff changeset
   505
    Consumer_Thread.fork[Any]("Session.manager", daemon = true)
56709
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   506
    {
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   507
      case arg: Any =>
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   508
        //{{{
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   509
        arg match {
56733
f7700146678d manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents: 56719
diff changeset
   510
          case output: Prover.Output =>
56775
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
   511
            if (output.is_stdout || output.is_stderr)
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
   512
              raw_output_messages.post(output)
56733
f7700146678d manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents: 56719
diff changeset
   513
            else handle_output(output)
56775
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
   514
56733
f7700146678d manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents: 56719
diff changeset
   515
            if (output.is_syslog) {
56775
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
   516
              syslog += output.message
56733
f7700146678d manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents: 56719
diff changeset
   517
              syslog_messages.post(output)
f7700146678d manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents: 56719
diff changeset
   518
            }
56775
59f70b89e5fd improved syslog performance -- avoid denial-of-service e.g. with threads_trace = 5 and active Syslog dockable;
wenzelm
parents: 56772
diff changeset
   519
56733
f7700146678d manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents: 56719
diff changeset
   520
            all_messages.post(output)
f7700146678d manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents: 56719
diff changeset
   521
f7700146678d manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents: 56719
diff changeset
   522
          case input: Prover.Input =>
f7700146678d manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents: 56719
diff changeset
   523
            all_messages.post(input)
f7700146678d manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents: 56719
diff changeset
   524
56793
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   525
          case Start(name, args) if !prover.defined =>
56709
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   526
            if (phase == Session.Inactive || phase == Session.Failed) {
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   527
              phase = Session.Startup
56793
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   528
              prover.set(resources.start_prover(manager.send(_), name, args))
56709
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   529
            }
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   530
56709
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   531
          case Stop =>
56793
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   532
            if (prover.defined && is_ready) {
56709
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   533
              _protocol_handlers = _protocol_handlers.stop(prover.get)
56772
725a192f8081 tuned comments;
wenzelm
parents: 56771
diff changeset
   534
              global_state.change(_ => Document.State.init)
56709
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   535
              phase = Session.Shutdown
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   536
              prover.get.terminate
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   537
            }
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   538
56771
28d62a5b07e8 more systematic delay_first discipline for change_buffer and prune_history;
wenzelm
parents: 56735
diff changeset
   539
          case Prune_History =>
56793
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   540
            if (prover.defined) {
56771
28d62a5b07e8 more systematic delay_first discipline for change_buffer and prune_history;
wenzelm
parents: 56735
diff changeset
   541
              val old_versions = global_state.change_result(_.prune_history(prune_size))
28d62a5b07e8 more systematic delay_first discipline for change_buffer and prune_history;
wenzelm
parents: 56735
diff changeset
   542
              if (!old_versions.isEmpty) prover.get.remove_versions(old_versions)
28d62a5b07e8 more systematic delay_first discipline for change_buffer and prune_history;
wenzelm
parents: 56735
diff changeset
   543
            }
28d62a5b07e8 more systematic delay_first discipline for change_buffer and prune_history;
wenzelm
parents: 56735
diff changeset
   544
56709
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   545
          case Update_Options(options) =>
56793
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   546
            if (prover.defined && is_ready) {
56709
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   547
              prover.get.options(options)
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   548
              handle_raw_edits(Document.Blobs.empty, Nil)
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   549
            }
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
   550
            global_options.post(Session.Global_Options(options))
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   551
56793
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   552
          case Cancel_Exec(exec_id) if prover.defined =>
56709
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   553
            prover.get.cancel_exec(exec_id)
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   554
56793
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   555
          case Session.Raw_Edits(doc_blobs, edits) if prover.defined =>
56709
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   556
            handle_raw_edits(doc_blobs, edits)
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   557
56793
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   558
          case Session.Dialog_Result(id, serial, result) if prover.defined =>
56709
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   559
            prover.get.dialog_result(serial, result)
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   560
            handle_output(new Prover.Output(Protocol.Dialog_Result(id, serial, result)))
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   561
56793
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   562
          case Protocol_Command(name, args) if prover.defined =>
56709
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   563
            prover.get.protocol_command(name, args:_*)
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   564
56793
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   565
          case change: Session.Change if prover.defined =>
56709
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   566
            if (global_state.value.is_assigned(change.previous))
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   567
              handle_change(change)
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   568
            else postponed_changes.store(change)
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   569
        }
56709
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   570
        true
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   571
        //}}}
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   572
    }
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   573
  }
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   574
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   575
43716
1d64662c1bfd tuned source structure;
wenzelm
parents: 43697
diff changeset
   576
  /* actions */
34809
0fed930f2992 misc tuning;
wenzelm
parents: 34808
diff changeset
   577
56387
d92eb5c3960d more general prover operations;
wenzelm
parents: 56385
diff changeset
   578
  def start(name: String, args: List[String])
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   579
  { manager.send(Start(name, args)) }
45076
dd803d319d5b tuned signature;
wenzelm
parents: 45075
diff changeset
   580
50117
32755e357a51 update options via protocol;
wenzelm
parents: 49524
diff changeset
   581
  def stop()
32755e357a51 update options via protocol;
wenzelm
parents: 49524
diff changeset
   582
  {
56709
e83356e94380 more careful shutdown (amending f2f53f7046f4);
wenzelm
parents: 56706
diff changeset
   583
    manager.send_wait(Stop)
56793
d5ab6a8799ce more synchronized treatment of prover process, which might emit more messages before shutdown and requires manager to accept them;
wenzelm
parents: 56782
diff changeset
   584
    prover.await_reset()
56704
c2f0ddd14747 simplified -- prefer Consumer_Thread over Actor;
wenzelm
parents: 56691
diff changeset
   585
    change_parser.shutdown()
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   586
    change_buffer.shutdown()
56771
28d62a5b07e8 more systematic delay_first discipline for change_buffer and prune_history;
wenzelm
parents: 56735
diff changeset
   587
    delay_prune.revoke()
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   588
    manager.shutdown()
56715
52125652e82a clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents: 56713
diff changeset
   589
    dispatcher.shutdown()
50117
32755e357a51 update options via protocol;
wenzelm
parents: 49524
diff changeset
   590
  }
38841
4df7b76249a0 include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents: 38722
diff changeset
   591
53054
8365d7fca3de public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents: 52931
diff changeset
   592
  def protocol_command(name: String, args: String*)
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   593
  { manager.send(Protocol_Command(name, args.toList)) }
53054
8365d7fca3de public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents: 52931
diff changeset
   594
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   595
  def cancel_exec(exec_id: Document_ID.Exec)
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   596
  { manager.send(Cancel_Exec(exec_id)) }
52931
ac6648c0c0fb cancel_query via direct access to the exec_id of the running query process;
wenzelm
parents: 52800
diff changeset
   597
54521
744ea0025e11 clarified Document.Blobs environment vs. actual edits of auxiliary files;
wenzelm
parents: 54519
diff changeset
   598
  def update(doc_blobs: Document.Blobs, edits: List[Document.Edit_Text])
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   599
  { if (!edits.isEmpty) manager.send_wait(Session.Raw_Edits(doc_blobs, edits)) }
50498
6647ba2775c1 support dialog via document content;
wenzelm
parents: 50433
diff changeset
   600
52084
573e80625c78 more explicit Session.update_options as source of Global_Options event;
wenzelm
parents: 51818
diff changeset
   601
  def update_options(options: Options)
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   602
  { manager.send_wait(Update_Options(options)) }
52084
573e80625c78 more explicit Session.update_options as source of Global_Options event;
wenzelm
parents: 51818
diff changeset
   603
52531
21f8e0e151f5 tuned signature;
wenzelm
parents: 52530
diff changeset
   604
  def dialog_result(id: Document_ID.Generic, serial: Long, result: String)
56706
f2f53f7046f4 converted main session manager to Consumer_Thread: messages need to be consumed immediately, postponed_changes replaces implicit actor mailbox scanning;
wenzelm
parents: 56705
diff changeset
   605
  { manager.send(Session.Dialog_Result(id, serial, result)) }
34777
91d6089cef88 class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff changeset
   606
}