36 lines
1.0 KiB
Kotlin
36 lines
1.0 KiB
Kotlin
package com.android.trisolarisserver.component
|
|
|
|
import com.android.trisolarisserver.controller.BookingSnapshotBuilder
|
|
import com.android.trisolarisserver.controller.dto.BookingDetailResponse
|
|
import org.springframework.scheduling.annotation.Scheduled
|
|
import org.springframework.stereotype.Component
|
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter
|
|
import java.util.UUID
|
|
|
|
@Component
|
|
class BookingEvents(
|
|
private val bookingSnapshotBuilder: BookingSnapshotBuilder
|
|
) {
|
|
private val hub = SseHub<BookingKey>("booking") { key ->
|
|
bookingSnapshotBuilder.build(key.propertyId, key.bookingId)
|
|
}
|
|
|
|
fun subscribe(propertyId: UUID, bookingId: UUID): SseEmitter {
|
|
return hub.subscribe(BookingKey(propertyId, bookingId))
|
|
}
|
|
|
|
fun emit(propertyId: UUID, bookingId: UUID) {
|
|
hub.emit(BookingKey(propertyId, bookingId))
|
|
}
|
|
|
|
@Scheduled(fixedDelayString = "25000")
|
|
fun heartbeat() {
|
|
hub.heartbeat()
|
|
}
|
|
}
|
|
|
|
private data class BookingKey(
|
|
val propertyId: UUID,
|
|
val bookingId: UUID
|
|
)
|