This repository was archived by the owner on Jun 28, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStreamController.scala
More file actions
59 lines (48 loc) · 1.54 KB
/
StreamController.scala
File metadata and controls
59 lines (48 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package controllers
import javax.inject.{Inject, Singleton}
import common.AppSettings
import play.api.mvc.{Action, Controller}
import services.{ValidationFailedException, ClusterClientService, ConnectionSetService, RoleMappingsService}
import templates.Page
import upickle.default._
import scala.async.Async._
import scala.concurrent.ExecutionContext
import scala.concurrent.duration.DurationLong
@Singleton
class StreamController @Inject()(
appSettings: AppSettings,
clusterClientService: ClusterClientService,
roleMappingsService: RoleMappingsService,
connectionSetService: ConnectionSetService
)(implicit ec: ExecutionContext) extends Controller {
def streams() = Action {
Ok(new Page("showcase").render)
}
def mappings() = Action {
Ok(write(roleMappingsService.onlineRoleMappings))
}
def hosts() = Action {
Ok(write(appSettings.hosts))
}
def connections() = Action.async {
async {
val connectionDataSet = await(connectionSetService.connectionSet)
Ok(write(connectionDataSet))
}
}
def throttle(serverName: String, delay: Long) = Action {
clusterClientService.throttle(serverName, delay.millis)
Accepted("ok")
}
def subscribe(serverName: String, topic: String) = Action {
clusterClientService.subscribe(serverName, topic)
.map(_ => Accepted("ok"))
.recover {
case ValidationFailedException(msg) => BadGateway(msg)
}.get
}
def unsubscribe(serverName: String, topic: String) = Action {
clusterClientService.unsubscribe(serverName, topic)
Accepted("ok")
}
}