|
@ -6,39 +6,46 @@ import monix.execution.Scheduler |
|
|
import monix.eval.Task |
|
|
import monix.eval.Task |
|
|
import nova.monadic_sfx.screens.LoginScreen |
|
|
import nova.monadic_sfx.screens.LoginScreen |
|
|
import nova.monadic_sfx.AppTypes |
|
|
import nova.monadic_sfx.AppTypes |
|
|
import scalafx.application.Platform |
|
|
|
|
|
import scala.concurrent.duration._ |
|
|
import scala.concurrent.duration._ |
|
|
import io.odin.Logger |
|
|
import io.odin.Logger |
|
|
import monix.execution.Callback |
|
|
import monix.execution.Callback |
|
|
import com.softwaremill.macwire._ |
|
|
import com.softwaremill.macwire._ |
|
|
import nova.monadic_sfx.http.Requesters |
|
|
import nova.monadic_sfx.http.Requesters |
|
|
|
|
|
|
|
|
import akka.actor._ |
|
|
|
|
|
import akka.actor.typed.Behavior |
|
|
|
|
|
import akka.actor.typed.scaladsl.adapter._ |
|
|
|
|
|
import akka.actor.typed.scaladsl.Behaviors |
|
|
|
|
|
|
|
|
import akka.actor.typed._ |
|
|
import nova.monadic_sfx.actors.Counter |
|
|
import nova.monadic_sfx.actors.Counter |
|
|
import akka.actor.typed.DispatcherSelector |
|
|
|
|
|
|
|
|
import akka.util.Timeout |
|
|
|
|
|
|
|
|
class MyFxApp( |
|
|
class MyFxApp( |
|
|
logger: Logger[Task], |
|
|
logger: Logger[Task], |
|
|
backend: AppTypes.HttpBackend, |
|
|
backend: AppTypes.HttpBackend, |
|
|
actorSystem: akka.actor.ActorSystem, |
|
|
|
|
|
|
|
|
actorSystem: ActorSystem[SpawnProtocol.Command], |
|
|
requesters: Requesters, |
|
|
requesters: Requesters, |
|
|
schedulers: Schedulers |
|
|
schedulers: Schedulers |
|
|
) extends JFXApp { |
|
|
) extends JFXApp { |
|
|
|
|
|
|
|
|
implicit lazy val defaultScheduler: Scheduler = schedulers.fx |
|
|
implicit lazy val defaultScheduler: Scheduler = schedulers.fx |
|
|
|
|
|
|
|
|
|
|
|
lazy val fxActor: Task[ActorRef[Counter.Command]] = wireWith( |
|
|
|
|
|
MyFxApp.makeCounterActor _ |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
lazy val application = |
|
|
lazy val application = |
|
|
for { |
|
|
for { |
|
|
appStage <- Task( |
|
|
|
|
|
UiModule.makePrimaryStage(backend, actorSystem) |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
appStage <- Task(wireWith(UiModule.makePrimaryStage _)) |
|
|
|
|
|
|
|
|
// _ <- Task { |
|
|
// _ <- Task { |
|
|
// val counterActor = testActor(actorSystem) |
|
|
// val counterActor = testActor(actorSystem) |
|
|
// counterActor ! (Counter.Increment) |
|
|
// counterActor ! (Counter.Increment) |
|
|
// } |
|
|
// } |
|
|
|
|
|
// ta <- testActor2(actorSystem) |
|
|
|
|
|
// actor <- |
|
|
|
|
|
// actorTask.bracket(actor => Task(actor ! (Counter.Increment)))(actor => |
|
|
|
|
|
// Task(actor ! (Counter.Stop)) |
|
|
|
|
|
// ) |
|
|
|
|
|
// actor <- actorTask |
|
|
|
|
|
actor <- fxActor |
|
|
|
|
|
_ <- Task(actor ! (Counter.Increment)) |
|
|
_ <- Task { stage = appStage } |
|
|
_ <- Task { stage = appStage } |
|
|
_ <- Task.sleep(2.seconds) |
|
|
_ <- Task.sleep(2.seconds) |
|
|
loginScene <- wire[LoginScreen].render |
|
|
loginScene <- wire[LoginScreen].render |
|
@ -54,17 +61,17 @@ class MyFxApp( |
|
|
} |
|
|
} |
|
|
} yield () |
|
|
} yield () |
|
|
|
|
|
|
|
|
def testActor( |
|
|
|
|
|
system: ActorSystem |
|
|
|
|
|
): akka.actor.typed.ActorRef[Counter.Command] = { |
|
|
|
|
|
val behaviour: Behavior[Counter.Command] = |
|
|
|
|
|
Behaviors.setup(context => wire[Counter]) |
|
|
|
|
|
system.spawn( |
|
|
|
|
|
behaviour, |
|
|
|
|
|
"CounterActor", |
|
|
|
|
|
DispatcherSelector.fromConfig("javafx-dispatcher") |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// def testActor( |
|
|
|
|
|
// system: ActorSystem |
|
|
|
|
|
// ): akka.actor.typed.ActorRef[Counter.Command] = { |
|
|
|
|
|
// val behaviour: Behavior[Counter.Command] = |
|
|
|
|
|
// Behaviors.setup(context => wire[Counter]) |
|
|
|
|
|
// system.spawn( |
|
|
|
|
|
// behaviour, |
|
|
|
|
|
// "CounterActor", |
|
|
|
|
|
// DispatcherSelector.fromConfig("javafx-dispatcher") |
|
|
|
|
|
// ) |
|
|
|
|
|
// } |
|
|
|
|
|
|
|
|
application.timed.runAsync( |
|
|
application.timed.runAsync( |
|
|
new Callback[Throwable, (FiniteDuration, Unit)] { |
|
|
new Callback[Throwable, (FiniteDuration, Unit)] { |
|
@ -85,6 +92,38 @@ class MyFxApp( |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
override def stopApp() = { |
|
|
override def stopApp() = { |
|
|
Platform.exit() |
|
|
|
|
|
|
|
|
val stop = for { |
|
|
|
|
|
actor <- fxActor |
|
|
|
|
|
_ <- logger.info("Stopping actor counter") |
|
|
|
|
|
// _ <- Task.fromFuture { actor.ask[Counter.Value](Counter.GetValue) } |
|
|
|
|
|
t <- Task(actor ! Counter.Stop) |
|
|
|
|
|
// _ <- Task.sleep(1.second) |
|
|
|
|
|
_ <- logger.info("Counter actor stopped") |
|
|
|
|
|
} yield () |
|
|
|
|
|
stop.runAsyncAndForget |
|
|
|
|
|
// Platform.exit() |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
object MyFxApp { |
|
|
|
|
|
def makeCounterActor( |
|
|
|
|
|
system: ActorSystem[SpawnProtocol.Command] |
|
|
|
|
|
): Task[ActorRef[Counter.Command]] = { |
|
|
|
|
|
import akka.actor.typed.scaladsl.AskPattern._ |
|
|
|
|
|
import scala.concurrent.ExecutionContext |
|
|
|
|
|
|
|
|
|
|
|
implicit val timeout: Timeout = Timeout(3.seconds) |
|
|
|
|
|
implicit val ec: ExecutionContext = system.executionContext |
|
|
|
|
|
implicit val scheduler = system.scheduler |
|
|
|
|
|
Task.fromFuture { |
|
|
|
|
|
system.ask( |
|
|
|
|
|
SpawnProtocol.Spawn( |
|
|
|
|
|
behavior = wireWith(Counter.apply _), |
|
|
|
|
|
name = "counterActor", |
|
|
|
|
|
DispatcherSelector.fromConfig("javafx-dispatcher"), |
|
|
|
|
|
_ |
|
|
|
|
|
) |
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |