Skip to content

Commit

Permalink
Minor refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
K1li4nL committed May 2, 2023
1 parent 800becd commit 6fe67df
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 5 additions & 3 deletions be2-scala/src/main/scala/ch/epfl/pop/pubsub/ClientActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ final case class ClientActor(mediator: ActorRef, connectionMediatorRef: ActorRef
private val mediatorAskable: AskableActorRef = mediator

// Tell connectionMediator we are online
if (isServer)
if (isServer) {
connectionMediatorRef ! ConnectionMediator.NewServerConnected(self)
}

private def messageWsHandle(event: ClientActorMessage): Unit = event match {
case ClientAnswer(graphMessage) => wsHandle.fold(())(_ ! graphMessage)
Expand All @@ -36,9 +37,10 @@ final case class ClientActor(mediator: ActorRef, connectionMediatorRef: ActorRef
wsHandle = Some(wsClient)

case DisconnectWsHandle =>
if (isServer)
connectionMediatorRef ! ConnectionMediator.ServerLeft(self)
subscribedChannels.foreach(channel => mediator ! PubSubMediator.UnsubscribeFrom(channel, this.self))
if (isServer) {
connectionMediatorRef ! ConnectionMediator.ServerLeft(self)
}

case ClientActor.SubscribeTo(channel) =>
val ask: Future[PubSubMediatorMessage] = (mediatorAskable ? PubSubMediator.SubscribeTo(channel, this.self)).map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ object PublishSubscribe {
val portResponseHandler = 4
val totalPorts = 5

val totalBroadcastPort = 2

/* building blocks */
// input message from the client
val input = builder.add(Flow[Message].collect { case TextMessage.Strict(s) => println(s">>> Incoming message : $s"); s })
Expand All @@ -66,7 +68,7 @@ object PublishSubscribe {
val responsePartition = builder.add(GetMessagesByIdResponseHandler.graph(dbActorRef.actorRef))

val merger = builder.add(Merge[GraphMessage](totalPorts))
val broadcast = builder.add(Broadcast[GraphMessage](2))
val broadcast = builder.add(Broadcast[GraphMessage](totalBroadcastPort))

val monitorSink = builder.add(Monitor.sink(monitorRef))
val jsonRpcAnswerGenerator = builder.add(AnswerGenerator.generator)
Expand Down

0 comments on commit 6fe67df

Please sign in to comment.