I have a case where I need to re-use already open connections to a client and for this I'm storing the connections as soon as they are opened in a ConcurrentHashMap and when the server needs to send any message to the client, it checks if there is an open connection to the client and if yes, it uses it to send the message.
ActorFlow.actorRef { actorRef =>
val flow = Props(new OCPPActor(actorRef, chargingStationId, isPersistentConn))
WebSocketManager.addConnection(chargingStationId, flow)
flow
})
In the example above, as it can be seen that I'm adding the connection to a ConcurrentHashMap inside the WebSocketManager object. Now if the connection already exist, how should I handle this? Is my understanding correct that the actorRef in the code above is the out ActorRef? So that means, for my case where the connection already exist,
ActorFlow.actorRef { _ =>
WebSocketManager.getConnection(chargingStationId)
})
Is this correct?