File: t4515.scala

package info (click to toggle)
scala 2.11.12-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 62,924 kB
  • sloc: javascript: 28,808; java: 13,415; xml: 3,135; sh: 1,620; python: 756; makefile: 38; awk: 36; ansic: 6
file content (41 lines) | stat: -rw-r--r-- 1,209 bytes parent folder | download | duplicates (4)
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
import scala.collection.mutable.HashMap

object Main {
  trait Target { }

  trait PushEventContext[EventType] {
    def getEvent: EventType
  }
  trait PushNode[EventType] { }
  trait DerivedPushNode[EventType] extends PushNode[EventType] { }

  trait HandlerBase[EventType] {
    def onEvent(target: Target,
                event: EventType,
                node: PushNode[EventType],
                ctx: PushEventContext[EventType]): Unit
                                            }
  val handlers = new HashMap[DerivedPushNode[_], HandlerBase[_]]

  object TimerPushService {
    private val INSTANCE: TimerPushService = new TimerPushService
    def get: TimerPushService = INSTANCE
  }

  class TimerPushService {
    def add[EventType](node: DerivedPushNode[EventType],
                       context: PushEventContext[EventType]): Unit = {}

    def pollEvents[EventType](node: DerivedPushNode[EventType]): List[PushEventContext[EventType]] =
      Nil
  }

  def onTimer(target: Target) {
    val pushService = TimerPushService.get
    for ((node, handler) <- handlers) {
      for (ctx <- pushService.pollEvents(node)) {
        handler.onEvent(target, ctx.getEvent, node, ctx)
      }
    }
  }
}