70 |
70 |
71 class Invoke_Scala extends Session.Protocol_Handler |
71 class Invoke_Scala extends Session.Protocol_Handler |
72 { |
72 { |
73 private var futures = Map.empty[String, java.util.concurrent.Future[Unit]] |
73 private var futures = Map.empty[String, java.util.concurrent.Future[Unit]] |
74 |
74 |
75 private def fulfill(prover: Session.Prover, |
75 private def fulfill(prover: Prover, id: String, tag: Invoke_Scala.Tag.Value, res: String): Unit = |
76 id: String, tag: Invoke_Scala.Tag.Value, res: String): Unit = synchronized |
76 synchronized |
77 { |
77 { |
78 if (futures.isDefinedAt(id)) { |
78 if (futures.isDefinedAt(id)) { |
79 prover.protocol_command("Invoke_Scala.fulfill", id, tag.toString, res) |
79 prover.protocol_command("Invoke_Scala.fulfill", id, tag.toString, res) |
80 futures -= id |
80 futures -= id |
|
81 } |
81 } |
82 } |
82 } |
|
83 |
83 |
84 private def cancel(prover: Session.Prover, |
84 private def cancel(prover: Prover, id: String, future: java.util.concurrent.Future[Unit]) |
85 id: String, future: java.util.concurrent.Future[Unit]) |
|
86 { |
85 { |
87 future.cancel(true) |
86 future.cancel(true) |
88 fulfill(prover, id, Invoke_Scala.Tag.INTERRUPT, "") |
87 fulfill(prover, id, Invoke_Scala.Tag.INTERRUPT, "") |
89 } |
88 } |
90 |
89 |
91 private def invoke_scala( |
90 private def invoke_scala(prover: Prover, msg: Prover.Protocol_Output): Boolean = synchronized |
92 prover: Session.Prover, msg: Prover.Protocol_Output): Boolean = synchronized |
|
93 { |
91 { |
94 msg.properties match { |
92 msg.properties match { |
95 case Markup.Invoke_Scala(name, id) => |
93 case Markup.Invoke_Scala(name, id) => |
96 futures += (id -> |
94 futures += (id -> |
97 default_thread_pool.submit(() => |
95 default_thread_pool.submit(() => |
102 true |
100 true |
103 case _ => false |
101 case _ => false |
104 } |
102 } |
105 } |
103 } |
106 |
104 |
107 private def cancel_scala( |
105 private def cancel_scala(prover: Prover, msg: Prover.Protocol_Output): Boolean = synchronized |
108 prover: Session.Prover, msg: Prover.Protocol_Output): Boolean = synchronized |
|
109 { |
106 { |
110 msg.properties match { |
107 msg.properties match { |
111 case Markup.Cancel_Scala(id) => |
108 case Markup.Cancel_Scala(id) => |
112 futures.get(id) match { |
109 futures.get(id) match { |
113 case Some(future) => cancel(prover, id, future) |
110 case Some(future) => cancel(prover, id, future) |