author | wenzelm |
Mon, 28 Apr 2014 15:20:59 +0200 | |
changeset 56772 | 725a192f8081 |
parent 56771 | 28d62a5b07e8 |
child 56775 | 59f70b89e5fd |
permissions | -rw-r--r-- |
56210 | 1 |
/* Title: Pure/PIDE/session.scala |
36676 | 2 |
Author: Makarius |
38221 | 3 |
Options: :folding=explicit:collapseFolds=1: |
36676 | 4 |
|
56210 | 5 |
PIDE editor session, potentially with running prover process. |
36676 | 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 | 15 |
object Session |
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 => |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56713
diff
changeset
|
40 |
System.err.println("Consumer failed: " + quote(c.name) + "\n" + Exn.message(exn)) |
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 | 47 |
/* change */ |
48 |
||
49 |
sealed case class Change( |
|
50 |
previous: Document.Version, |
|
51 |
doc_blobs: Document.Blobs, |
|
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 | 54 |
doc_edits: List[Document.Edit_Command], |
55 |
version: Document.Version) |
|
56 |
||
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 | 60 |
//{{{ |
50697
82e9178e6a98
improved Monitor_Dockable, based on ML_Statistics operations;
wenzelm
parents:
50566
diff
changeset
|
61 |
case class Statistics(props: Properties.T) |
50117 | 62 |
case class Global_Options(options: Options) |
44805 | 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 | 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 | 71 |
case object Startup extends Phase // transient |
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 | 74 |
case object Shutdown extends Phase // transient |
43716 | 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 |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
78 |
/* protocol handlers */ |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
79 |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
80 |
abstract class Protocol_Handler |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
81 |
{ |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
82 |
def stop(prover: Prover): Unit = {} |
56385 | 83 |
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
|
84 |
} |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
85 |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
86 |
class Protocol_Handlers( |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
87 |
handlers: Map[String, Session.Protocol_Handler] = Map.empty, |
56385 | 88 |
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
|
89 |
{ |
53054
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
90 |
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
|
91 |
|
52111
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
92 |
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
|
93 |
{ |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
94 |
val (handlers1, functions1) = |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
95 |
handlers.get(name) match { |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
96 |
case Some(old_handler) => |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
97 |
System.err.println("Redefining protocol handler: " + name) |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
98 |
old_handler.stop(prover) |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
99 |
(handlers - name, functions -- old_handler.functions.keys) |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
100 |
case None => (handlers, functions) |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
101 |
} |
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 |
val (handlers2, functions2) = |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
104 |
try { |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
105 |
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
|
106 |
val new_functions = |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
107 |
for ((a, f) <- new_handler.functions.toList) yield |
56385 | 108 |
(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
|
109 |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
110 |
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
|
111 |
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
|
112 |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
113 |
(handlers1 + (name -> new_handler), functions1 ++ new_functions) |
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 |
catch { |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
116 |
case exn: Throwable => |
56671
06853449cf0a
explicit Exn.error_message in accordance to Output.error_message in ML;
wenzelm
parents:
56412
diff
changeset
|
117 |
System.err.println(Exn.error_message( |
06853449cf0a
explicit Exn.error_message in accordance to Output.error_message in ML;
wenzelm
parents:
56412
diff
changeset
|
118 |
"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
|
119 |
(handlers1, functions1) |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
120 |
} |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
121 |
|
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
122 |
new Protocol_Handlers(handlers2, functions2) |
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 |
|
56385 | 125 |
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
|
126 |
msg.properties match { |
52111
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
127 |
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
|
128 |
try { functions(a)(msg) } |
52111
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
129 |
catch { |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
130 |
case exn: Throwable => |
56671
06853449cf0a
explicit Exn.error_message in accordance to Output.error_message in ML;
wenzelm
parents:
56412
diff
changeset
|
131 |
System.err.println(Exn.error_message( |
06853449cf0a
explicit Exn.error_message in accordance to Output.error_message in ML;
wenzelm
parents:
56412
diff
changeset
|
132 |
"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
|
133 |
false |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
134 |
} |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
135 |
case _ => false |
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
136 |
} |
52113 | 137 |
|
138 |
def stop(prover: Prover): Protocol_Handlers = |
|
139 |
{ |
|
140 |
for ((_, handler) <- handlers) handler.stop(prover) |
|
141 |
new Protocol_Handlers() |
|
142 |
} |
|
52111
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
143 |
} |
34791 | 144 |
} |
145 |
||
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
146 |
|
56208 | 147 |
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
|
148 |
{ |
47653 | 149 |
/* global flags */ |
150 |
||
151 |
@volatile var timing: Boolean = false |
|
152 |
@volatile var verbose: Boolean = false |
|
153 |
||
154 |
||
49288 | 155 |
/* tuning parameters */ |
156 |
||
157 |
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
|
158 |
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
|
159 |
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
|
160 |
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
|
161 |
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
|
162 |
def reparse_limit: Int = 0 |
37849 | 163 |
|
164 |
||
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56713
diff
changeset
|
165 |
/* outlets */ |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56713
diff
changeset
|
166 |
|
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56713
diff
changeset
|
167 |
private val dispatcher = |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56713
diff
changeset
|
168 |
Consumer_Thread.fork[() => Unit]("Session.dispatcher", daemon = true) { case e => e(); true } |
34809 | 169 |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56713
diff
changeset
|
170 |
val statistics = new Session.Outlet[Session.Statistics](dispatcher) |
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56713
diff
changeset
|
171 |
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
|
172 |
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
|
173 |
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
|
174 |
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
|
175 |
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
|
176 |
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
|
177 |
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
|
178 |
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
|
179 |
val trace_events = new Session.Outlet[Simplifier_Trace.Event.type](dispatcher) |
34809 | 180 |
|
181 |
||
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
|
182 |
|
45635
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
183 |
/** 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
|
184 |
|
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
185 |
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
|
186 |
previous: Future[Document.Version], |
54521
744ea0025e11
clarified Document.Blobs environment vs. actual edits of auxiliary files;
wenzelm
parents:
54519
diff
changeset
|
187 |
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
|
188 |
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
|
189 |
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
|
190 |
|
56704 | 191 |
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
|
192 |
{ |
56704 | 193 |
case Text_Edits(previous, doc_blobs, text_edits, version_result) => |
194 |
val prev = previous.get_finished |
|
195 |
val change = |
|
196 |
Timing.timeit("parse_change", timing) { |
|
197 |
resources.parse_change(reparse_limit, prev, doc_blobs, text_edits) |
|
198 |
} |
|
199 |
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
|
200 |
manager.send(change) |
56704 | 201 |
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
|
202 |
} |
d9cf3520083c
explicit change_parser thread, which avoids undirected Future.fork with its tendency towards hundreds of worker threads;
wenzelm
parents:
45633
diff
changeset
|
203 |
|
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
204 |
|
47653 | 205 |
|
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
|
206 |
/** main protocol manager **/ |
34809 | 207 |
|
43651
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
208 |
/* global state */ |
43644 | 209 |
|
56690 | 210 |
private val syslog = Synchronized(Queue.empty[XML.Elem]) |
56687 | 211 |
def current_syslog(): String = cat_lines(syslog.value.iterator.map(XML.content)) |
39626
a5d0bcfb95a3
manage persistent syslog via Session, not Isabelle_Process;
wenzelm
parents:
39625
diff
changeset
|
212 |
|
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
213 |
@volatile private var _phase: Session.Phase = Session.Inactive |
39633 | 214 |
private def phase_=(new_phase: Session.Phase) |
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
215 |
{ |
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
216 |
_phase = new_phase |
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56713
diff
changeset
|
217 |
phase_changed.post(new_phase) |
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
218 |
} |
43716 | 219 |
def phase = _phase |
43553 | 220 |
def is_ready: Boolean = phase == Session.Ready |
39630
44181423183a
explicit Session.Phase indication with associated event bus;
wenzelm
parents:
39629
diff
changeset
|
221 |
|
56690 | 222 |
private val global_state = Synchronized(Document.State.init) |
56687 | 223 |
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
|
224 |
|
56393
22f533e6a049
more abstract Prover.Syntax, as proposed by Carst Tankink;
wenzelm
parents:
56387
diff
changeset
|
225 |
def recent_syntax(): Prover.Syntax = |
46944
9fc22eb6408c
more recent recent_syntax, e.g. relevant for document rendering during startup;
wenzelm
parents:
46942
diff
changeset
|
226 |
{ |
9fc22eb6408c
more recent recent_syntax, e.g. relevant for document rendering during startup;
wenzelm
parents:
46942
diff
changeset
|
227 |
val version = current_state().recent_finished.version.get_finished |
56394
bbf4d512f395
clarified Version.syntax -- avoid guessing initial situation;
wenzelm
parents:
56393
diff
changeset
|
228 |
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
|
229 |
} |
34816
d33312514220
maintain generic session entities -- cover commands, states, etc. (but not yet documents);
wenzelm
parents:
34815
diff
changeset
|
230 |
|
44960 | 231 |
def snapshot(name: Document.Node.Name = Document.Node.Name.empty, |
232 |
pending_edits: List[Text.Edit] = Nil): Document.Snapshot = |
|
56687 | 233 |
global_state.value.snapshot(name, pending_edits) |
43716 | 234 |
|
43651
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
235 |
|
53054
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
236 |
/* protocol handlers */ |
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
237 |
|
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
238 |
@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
|
239 |
|
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
240 |
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
|
241 |
_protocol_handlers.get(name) |
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
242 |
|
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
243 |
|
43651
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
244 |
/* theory files */ |
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
245 |
|
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48422
diff
changeset
|
246 |
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
|
247 |
{ |
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48422
diff
changeset
|
248 |
val header1 = |
56208 | 249 |
if (resources.loaded_theories(name.theory)) |
54559 | 250 |
header.error("Cannot update finished theory " + quote(name.theory)) |
48707
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48422
diff
changeset
|
251 |
else header |
ba531af91148
simplified Document.Node.Header -- internalized errors;
wenzelm
parents:
48422
diff
changeset
|
252 |
(name, Document.Node.Deps(header1)) |
44442
cb18e4f09053
clarified norm_header/header_edit -- disallow update of loaded theories;
wenzelm
parents:
44436
diff
changeset
|
253 |
} |
cb18e4f09053
clarified norm_header/header_edit -- disallow update of loaded theories;
wenzelm
parents:
44436
diff
changeset
|
254 |
|
43651
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
255 |
|
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
|
256 |
/* internal messages */ |
43651
511df47bcadc
some support for theory files within Isabelle/Scala session;
wenzelm
parents:
43649
diff
changeset
|
257 |
|
56387 | 258 |
private case class Start(name: String, args: List[String]) |
56709 | 259 |
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
|
260 |
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
|
261 |
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
|
262 |
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
|
263 |
private case object Prune_History |
41534 | 264 |
|
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
|
265 |
|
56719
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents:
56715
diff
changeset
|
266 |
/* buffered changes */ |
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents:
56715
diff
changeset
|
267 |
|
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents:
56715
diff
changeset
|
268 |
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
|
269 |
{ |
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents:
56715
diff
changeset
|
270 |
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
|
271 |
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
|
272 |
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
|
273 |
|
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents:
56715
diff
changeset
|
274 |
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
|
275 |
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
|
276 |
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
|
277 |
assignment = false |
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents:
56715
diff
changeset
|
278 |
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
|
279 |
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
|
280 |
} |
56771
28d62a5b07e8
more systematic delay_first discipline for change_buffer and prune_history;
wenzelm
parents:
56735
diff
changeset
|
281 |
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
|
282 |
|
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents:
56715
diff
changeset
|
283 |
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
|
284 |
assignment |= assign |
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents:
56715
diff
changeset
|
285 |
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
|
286 |
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
|
287 |
commands += command |
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents:
56715
diff
changeset
|
288 |
} |
56771
28d62a5b07e8
more systematic delay_first discipline for change_buffer and prune_history;
wenzelm
parents:
56735
diff
changeset
|
289 |
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
|
290 |
} |
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents:
56715
diff
changeset
|
291 |
|
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents:
56715
diff
changeset
|
292 |
def shutdown() |
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents:
56715
diff
changeset
|
293 |
{ |
56771
28d62a5b07e8
more systematic delay_first discipline for change_buffer and prune_history;
wenzelm
parents:
56735
diff
changeset
|
294 |
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
|
295 |
flush() |
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents:
56715
diff
changeset
|
296 |
} |
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents:
56715
diff
changeset
|
297 |
} |
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents:
56715
diff
changeset
|
298 |
|
80eb2192516a
simplified change_buffer (again, see 937826d702d5): no thread, just timer, rely on asynchronous commands_changed.post;
wenzelm
parents:
56715
diff
changeset
|
299 |
|
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
|
300 |
/* 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
|
301 |
|
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
|
302 |
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
|
303 |
{ |
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
|
304 |
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
|
305 |
|
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
|
306 |
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
|
307 |
|
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
|
308 |
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
|
309 |
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
|
310 |
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
|
311 |
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
|
312 |
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
|
313 |
} |
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
|
314 |
} |
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
|
315 |
|
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
|
316 |
|
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
|
317 |
/* 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
|
318 |
|
56771
28d62a5b07e8
more systematic delay_first discipline for change_buffer and prune_history;
wenzelm
parents:
56735
diff
changeset
|
319 |
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
|
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 |
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
|
322 |
{ |
56387 | 323 |
var prover: Option[Prover] = None |
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
|
324 |
|
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
|
325 |
|
52649
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
326 |
/* raw edits */ |
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
327 |
|
54521
744ea0025e11
clarified Document.Blobs environment vs. actual edits of auxiliary files;
wenzelm
parents:
54519
diff
changeset
|
328 |
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
|
329 |
//{{{ |
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
330 |
{ |
56712 | 331 |
require(prover.isDefined) |
332 |
||
52649
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
333 |
prover.get.discontinue_execution() |
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
334 |
|
56687 | 335 |
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
|
336 |
val version = Future.promise[Document.Version] |
56711 | 337 |
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
|
338 |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56713
diff
changeset
|
339 |
raw_edits.post(Session.Raw_Edits(doc_blobs, edits)) |
56704 | 340 |
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
|
341 |
} |
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
342 |
//}}} |
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
343 |
|
f45ab3e8211b
update_options with full update, e.g. required for re-assignment of Command.prints;
wenzelm
parents:
52563
diff
changeset
|
344 |
|
43716 | 345 |
/* resulting changes */ |
34809 | 346 |
|
56315 | 347 |
def handle_change(change: Session.Change) |
38221 | 348 |
//{{{ |
34809 | 349 |
{ |
56712 | 350 |
require(prover.isDefined) |
351 |
||
44383 | 352 |
def id_command(command: Command) |
43720 | 353 |
{ |
54519
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54443
diff
changeset
|
354 |
for { |
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54443
diff
changeset
|
355 |
digest <- command.blobs_digests |
56687 | 356 |
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
|
357 |
} { |
56315 | 358 |
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
|
359 |
case Some(blob) => |
56687 | 360 |
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
|
361 |
prover.get.define_blob(digest, blob.bytes) |
55783 | 362 |
case None => |
363 |
System.err.println("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
|
364 |
} |
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54443
diff
changeset
|
365 |
} |
5fed81762406
maintain blobs within document state: digest + text in ML, digest-only in Scala;
wenzelm
parents:
54443
diff
changeset
|
366 |
|
56687 | 367 |
if (!global_state.value.defined_command(command.id)) { |
368 |
global_state.change(_.define_command(command)) |
|
44644
317e4962dd0f
clarified define_command: store name as structural information;
wenzelm
parents:
44616
diff
changeset
|
369 |
prover.get.define_command(command) |
43720 | 370 |
} |
371 |
} |
|
56315 | 372 |
change.doc_edits foreach { |
44383 | 373 |
case (_, edit) => |
374 |
edit foreach { case (c1, c2) => c1 foreach id_command; c2 foreach id_command } |
|
375 |
} |
|
43722 | 376 |
|
56687 | 377 |
val assignment = global_state.value.the_assignment(change.previous).check_finished |
378 |
global_state.change(_.define_version(change.version, assignment)) |
|
56315 | 379 |
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
|
380 |
resources.commit(change) |
34809 | 381 |
} |
38221 | 382 |
//}}} |
34809 | 383 |
|
384 |
||
46772
be21f050eda4
tuned signature -- emphasize Isabelle_Process Input vs. Output;
wenzelm
parents:
46771
diff
changeset
|
385 |
/* prover output */ |
34809 | 386 |
|
56385 | 387 |
def handle_output(output: Prover.Output) |
38221 | 388 |
//{{{ |
34809 | 389 |
{ |
51662
3391a493f39a
just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents:
51083
diff
changeset
|
390 |
def bad_output() |
43716 | 391 |
{ |
392 |
if (verbose) |
|
56713 | 393 |
System.err.println("Ignoring bad prover output: " + output.message.toString) |
43716 | 394 |
} |
395 |
||
52531 | 396 |
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
|
397 |
{ |
3391a493f39a
just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents:
51083
diff
changeset
|
398 |
try { |
56687 | 399 |
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
|
400 |
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
|
401 |
} |
3391a493f39a
just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents:
51083
diff
changeset
|
402 |
catch { |
3391a493f39a
just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents:
51083
diff
changeset
|
403 |
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
|
404 |
} |
3391a493f39a
just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents:
51083
diff
changeset
|
405 |
} |
3391a493f39a
just one timing protocol function, with 3 implementations: TTY/PG, PIDE/document, build;
wenzelm
parents:
51083
diff
changeset
|
406 |
|
54442
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
407 |
output match { |
56385 | 408 |
case msg: Prover.Protocol_Output => |
54442
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
409 |
val handled = _protocol_handlers.invoke(msg) |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
410 |
if (!handled) { |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
411 |
msg.properties match { |
56712 | 412 |
case Markup.Protocol_Handler(name) if prover.isDefined => |
54442
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
413 |
_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
|
414 |
|
56712 | 415 |
case Protocol.Command_Timing(state_id, timing) if prover.isDefined => |
54442
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
416 |
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
|
417 |
accumulate(state_id, prover.get.xml_cache.elem(message)) |
46122 | 418 |
|
54442
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
419 |
case Markup.Assign_Update => |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
420 |
msg.text match { |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
421 |
case Protocol.Assign_Update(id, update) => |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
422 |
try { |
56687 | 423 |
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
|
424 |
change_buffer.invoke(true, cmds) |
54442
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
425 |
} |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
426 |
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
|
427 |
postponed_changes.flush() |
54442
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
428 |
case _ => bad_output() |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
429 |
} |
56771
28d62a5b07e8
more systematic delay_first discipline for change_buffer and prune_history;
wenzelm
parents:
56735
diff
changeset
|
430 |
delay_prune.invoke() |
46122 | 431 |
|
54442
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
432 |
case Markup.Removed_Versions => |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
433 |
msg.text match { |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
434 |
case Protocol.Removed(removed) => |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
435 |
try { |
56687 | 436 |
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
|
437 |
} |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
438 |
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
|
439 |
case _ => bad_output() |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
440 |
} |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
441 |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
442 |
case Markup.ML_Statistics(props) => |
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56713
diff
changeset
|
443 |
statistics.post(Session.Statistics(props)) |
54442
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
444 |
|
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
445 |
case Markup.Task_Statistics(props) => |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
446 |
// FIXME |
52111
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
447 |
|
54442
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
448 |
case _ => bad_output() |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
449 |
} |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
450 |
} |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
451 |
case _ => |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
452 |
output.properties match { |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
453 |
case Position.Id(state_id) => |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
454 |
accumulate(state_id, output.message) |
56210 | 455 |
|
54442
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
456 |
case _ if output.is_init => |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
457 |
phase = Session.Ready |
56210 | 458 |
|
54442
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
459 |
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
|
460 |
if (rc == 0) phase = Session.Inactive |
c39972ddd672
more specific Protocol_Output: empty message.body, main content via bytes/text;
wenzelm
parents:
53054
diff
changeset
|
461 |
else phase = Session.Failed |
56735 | 462 |
prover = None |
56210 | 463 |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56713
diff
changeset
|
464 |
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
|
465 |
} |
52111
1fd184eaa310
explicit management of Session.Protocol_Handlers, with protocol state and functions;
wenzelm
parents:
52084
diff
changeset
|
466 |
} |
34809 | 467 |
} |
38221 | 468 |
//}}} |
34809 | 469 |
|
34820
a8ba6cde13e9
basic setup for synchronous / modal (!) prover startup;
wenzelm
parents:
34819
diff
changeset
|
470 |
|
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
|
471 |
/* 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
|
472 |
|
56710
8f102c18eab7
more uniform warning/error handling, potentially with propagation to send_wait caller;
wenzelm
parents:
56709
diff
changeset
|
473 |
Consumer_Thread.fork[Any]("Session.manager", daemon = true) |
56709 | 474 |
{ |
475 |
case arg: Any => |
|
476 |
//{{{ |
|
477 |
arg match { |
|
56733
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents:
56719
diff
changeset
|
478 |
case output: Prover.Output => |
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents:
56719
diff
changeset
|
479 |
if (output.is_stdout || output.is_stderr) raw_output_messages.post(output) |
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents:
56719
diff
changeset
|
480 |
else handle_output(output) |
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents:
56719
diff
changeset
|
481 |
if (output.is_syslog) { |
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents:
56719
diff
changeset
|
482 |
syslog.change(queue => |
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents:
56719
diff
changeset
|
483 |
{ |
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents:
56719
diff
changeset
|
484 |
val queue1 = queue.enqueue(output.message) |
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents:
56719
diff
changeset
|
485 |
if (queue1.length > syslog_limit) queue1.dequeue._2 else queue1 |
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents:
56719
diff
changeset
|
486 |
}) |
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents:
56719
diff
changeset
|
487 |
syslog_messages.post(output) |
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents:
56719
diff
changeset
|
488 |
} |
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents:
56719
diff
changeset
|
489 |
all_messages.post(output) |
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents:
56719
diff
changeset
|
490 |
|
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents:
56719
diff
changeset
|
491 |
case input: Prover.Input => |
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents:
56719
diff
changeset
|
492 |
all_messages.post(input) |
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents:
56719
diff
changeset
|
493 |
|
56709 | 494 |
case Start(name, args) if prover.isEmpty => |
495 |
if (phase == Session.Inactive || phase == Session.Failed) { |
|
496 |
phase = Session.Startup |
|
56733
f7700146678d
manager is direct receiver of prover output -- discontinued old performance tuning (329320fc88df, 1baa5d19ac44);
wenzelm
parents:
56719
diff
changeset
|
497 |
prover = Some(resources.start_prover(manager.send(_), name, args)) |
56709 | 498 |
} |
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
|
499 |
|
56709 | 500 |
case Stop => |
56712 | 501 |
if (prover.isDefined && is_ready) { |
56709 | 502 |
_protocol_handlers = _protocol_handlers.stop(prover.get) |
56772 | 503 |
global_state.change(_ => Document.State.init) |
56709 | 504 |
phase = Session.Shutdown |
505 |
prover.get.terminate |
|
506 |
} |
|
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
|
507 |
|
56771
28d62a5b07e8
more systematic delay_first discipline for change_buffer and prune_history;
wenzelm
parents:
56735
diff
changeset
|
508 |
case Prune_History => |
28d62a5b07e8
more systematic delay_first discipline for change_buffer and prune_history;
wenzelm
parents:
56735
diff
changeset
|
509 |
if (prover.isDefined) { |
28d62a5b07e8
more systematic delay_first discipline for change_buffer and prune_history;
wenzelm
parents:
56735
diff
changeset
|
510 |
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
|
511 |
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
|
512 |
} |
28d62a5b07e8
more systematic delay_first discipline for change_buffer and prune_history;
wenzelm
parents:
56735
diff
changeset
|
513 |
|
56709 | 514 |
case Update_Options(options) => |
515 |
if (prover.isDefined && is_ready) { |
|
516 |
prover.get.options(options) |
|
517 |
handle_raw_edits(Document.Blobs.empty, Nil) |
|
518 |
} |
|
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56713
diff
changeset
|
519 |
global_options.post(Session.Global_Options(options)) |
34809 | 520 |
|
56709 | 521 |
case Cancel_Exec(exec_id) if prover.isDefined => |
522 |
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
|
523 |
|
56709 | 524 |
case Session.Raw_Edits(doc_blobs, edits) if prover.isDefined => |
525 |
handle_raw_edits(doc_blobs, edits) |
|
526 |
||
527 |
case Session.Dialog_Result(id, serial, result) if prover.isDefined => |
|
528 |
prover.get.dialog_result(serial, result) |
|
529 |
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
|
530 |
|
56709 | 531 |
case Protocol_Command(name, args) if prover.isDefined => |
532 |
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
|
533 |
|
56709 | 534 |
case change: Session.Change if prover.isDefined => |
535 |
if (global_state.value.is_assigned(change.previous)) |
|
536 |
handle_change(change) |
|
537 |
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
|
538 |
} |
56709 | 539 |
true |
540 |
//}}} |
|
541 |
} |
|
34777
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
542 |
} |
91d6089cef88
class Session models full session, with or without prover process (cf. heaps, browser_info);
wenzelm
parents:
diff
changeset
|
543 |
|
34809 | 544 |
|
43716 | 545 |
/* actions */ |
34809 | 546 |
|
56387 | 547 |
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
|
548 |
{ manager.send(Start(name, args)) } |
45076 | 549 |
|
50117 | 550 |
def stop() |
551 |
{ |
|
56709 | 552 |
manager.send_wait(Stop) |
56704 | 553 |
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
|
554 |
change_buffer.shutdown() |
56771
28d62a5b07e8
more systematic delay_first discipline for change_buffer and prune_history;
wenzelm
parents:
56735
diff
changeset
|
555 |
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
|
556 |
manager.shutdown() |
56715
52125652e82a
clarified Session.Consumer, with Session.Outlet managed by dispatcher thread;
wenzelm
parents:
56713
diff
changeset
|
557 |
dispatcher.shutdown() |
50117 | 558 |
} |
38841
4df7b76249a0
include Document.History in Document.State -- just one universal session state maintained by main actor;
wenzelm
parents:
38722
diff
changeset
|
559 |
|
53054
8365d7fca3de
public access for protocol handlers and protocol commands -- to be used within reason;
wenzelm
parents:
52931
diff
changeset
|
560 |
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
|
561 |
{ 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
|
562 |
|
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
|
563 |
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
|
564 |
{ 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
|
565 |
|
54521
744ea0025e11
clarified Document.Blobs environment vs. actual edits of auxiliary files;
wenzelm
parents:
54519
diff
changeset
|
566 |
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
|
567 |
{ if (!edits.isEmpty) manager.send_wait(Session.Raw_Edits(doc_blobs, edits)) } |
50498 | 568 |
|
52084
573e80625c78
more explicit Session.update_options as source of Global_Options event;
wenzelm
parents:
51818
diff
changeset
|
569 |
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
|
570 |
{ manager.send_wait(Update_Options(options)) } |
52084
573e80625c78
more explicit Session.update_options as source of Global_Options event;
wenzelm
parents:
51818
diff
changeset
|
571 |
|
52531 | 572 |
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
|
573 |
{ 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
|
574 |
} |