File tree Expand file tree Collapse file tree 3 files changed +84
-0
lines changed Expand file tree Collapse file tree 3 files changed +84
-0
lines changed Original file line number Diff line number Diff line change @@ -29,6 +29,14 @@ hmda {
29
29
}
30
30
isDemo = false
31
31
isDemo = ${?HMDA_IS_DEMO}
32
+ panel {
33
+ tcp {
34
+ host = "127.0.0.1"
35
+ host = ${?HMDA_PANEL_LOADER_HOST}
36
+ port = "8888"
37
+ port = ${?HMDA_PANEL_LOADER_PORT}
38
+ }
39
+ }
32
40
}
33
41
34
42
api-dispatcher {
Original file line number Diff line number Diff line change
1
+ package hmda .api .tcp
2
+
3
+ import java .net .InetSocketAddress
4
+
5
+ import akka .actor .{Actor , ActorSystem , Status }
6
+ import akka .stream .ActorMaterializer
7
+ import akka .stream .scaladsl .Tcp
8
+ import akka .stream .scaladsl .Tcp .ServerBinding
9
+ import hmda .persistence .model .HmdaActor
10
+
11
+ import scala .concurrent .{ExecutionContext , Future }
12
+
13
+ abstract class TcpApi extends HmdaActor {
14
+
15
+ val name : String
16
+ val host : String
17
+ val port : Int
18
+
19
+ implicit val system : ActorSystem
20
+ implicit val materializer : ActorMaterializer
21
+ implicit val ec : ExecutionContext
22
+
23
+ val tcp : Future [ServerBinding ]
24
+
25
+ override def receive = {
26
+ case Tcp .ServerBinding (s) => handleServerBinding(s)
27
+ case Status .Failure (e) => handleBindFailure(e)
28
+ }
29
+
30
+ private def handleServerBinding (address : InetSocketAddress ): Unit = {
31
+ log.info(s " $name started on {} " , address)
32
+ context.become(Actor .emptyBehavior)
33
+ }
34
+
35
+ private def handleBindFailure (error : Throwable ): Unit = {
36
+ log.error(error, s " Failed to bind to $host: $port" )
37
+ context stop self
38
+ }
39
+ }
Original file line number Diff line number Diff line change
1
+ package hmda .api .tcp .admin
2
+
3
+ import akka .NotUsed
4
+ import akka .pattern .pipe
5
+ import akka .actor .{ActorRef , ActorSystem }
6
+ import akka .stream .ActorMaterializer
7
+ import akka .stream .scaladsl .{Flow , Tcp }
8
+ import akka .util .ByteString
9
+ import hmda .api .tcp .TcpApi
10
+ import hmda .api .util .FlowUtils
11
+
12
+ import scala .concurrent .{ExecutionContext , Future }
13
+
14
+ class InstitutionAdminTcpApi (supervisor : ActorRef ) extends TcpApi with FlowUtils {
15
+ override val name : String = " hmda-institutions-tcp-api"
16
+
17
+ override implicit val system : ActorSystem = context.system
18
+ override implicit val materializer : ActorMaterializer = ActorMaterializer ()
19
+ override implicit val ec : ExecutionContext = context.dispatcher
20
+
21
+ override val host : String = config.getString(" hmda.panel.tcp.host" )
22
+ override val port : Int = config.getInt(" hmda.panel.tcp.port" )
23
+
24
+
25
+ val tcpHandler : Flow [ByteString , ByteString , NotUsed ] =
26
+ Flow [ByteString ]
27
+ .map{ e => println(e); e}
28
+
29
+
30
+ override val tcp : Future [Tcp .ServerBinding ] = Tcp ().bindAndHandle(
31
+ tcpHandler,
32
+ host,
33
+ port
34
+ )
35
+
36
+ tcp pipeTo self
37
+ }
You can’t perform that action at this time.
0 commit comments