override suspend fun handleMessages()

in jetbrains-core/src/software/aws/toolkits/jetbrains/services/cloudwatch/logs/CloudWatchActor.kt [136:213]


    override suspend fun handleMessages() {
        for (message in channel) {
            when (message) {
                is Message.LoadForward -> if (!nextForwardToken.isNullOrEmpty()) {
                    withContext(edtContext) { table.setPaintBusy(true) }
                    val items = try {
                        loadMore(nextForwardToken, saveForwardToken = true)
                    } catch (e: Exception) {
                        LOG.warn(e) { "Exception thrown while trying to load forwards" }
                        notifyError(
                            project = project,
                            title = message("cloudwatch.logs.exception"),
                            content = message("cloudwatch.logs.failed_to_load_more")
                        )
                        listOf()
                    }
                    withContext(edtContext) {
                        if (items.isNotEmpty()) {
                            table.listTableModel.addRows(items)
                        }
                        table.setPaintBusy(false)
                    }
                }
                is Message.LoadBackward -> if (!nextBackwardToken.isNullOrEmpty()) {
                    withContext(edtContext) { table.setPaintBusy(true) }
                    val items = try {
                        loadMore(nextBackwardToken, saveBackwardToken = true)
                    } catch (e: Exception) {
                        LOG.warn(e) { "Exception thrown while trying to load backwards" }
                        notifyError(
                            project = project,
                            title = message("cloudwatch.logs.exception"),
                            content = message("cloudwatch.logs.failed_to_load_more")
                        )
                        listOf<T>()
                    }
                    if (items.isNotEmpty()) {
                        // Selected rows can be non contiguous so we have to save every row selected
                        val newSelection = table.selectedRows.map { it + items.size }
                        val viewRect = table.visibleRect
                        table.listTableModel.items = items + table.listTableModel.items
                        withContext(edtContext) {
                            table.tableViewModel.fireTableDataChanged()
                            val offset = table.getCellRect(items.size, 0, true)
                            // Move the view box down y - cell height amount to stay in the same place
                            viewRect.y = (viewRect.y + offset.y - offset.height)
                            table.scrollRectToVisible(viewRect)
                            // Re-add the selection
                            newSelection.forEach {
                                table.addRowSelectionInterval(it, it)
                            }
                        }
                    }
                    withContext(edtContext) { table.setPaintBusy(false) }
                }
                is Message.LoadInitial -> {
                    loadInitial()
                    // make sure the scroll pane is at the top after loading. Needed for Refresh!
                    val rect = table.getCellRect(0, 0, true)
                    withContext(edtContext) {
                        table.scrollRectToVisible(rect)
                    }
                }
                is Message.LoadInitialRange -> {
                    loadInitialRange(message.previousEvent.timestamp, message.duration)
                    val item = table.listTableModel.items.firstOrNull { it == message.previousEvent }
                    val index = table.listTableModel.indexOf(item).takeIf { it > 0 } ?: return
                    withContext(edtContext) {
                        table.setRowSelectionInterval(index, index)
                        TableUtil.scrollSelectionToVisible(table)
                    }
                }
                is Message.LoadInitialFilter -> {
                    loadInitialFilter(message.queryString)
                }
            }
        }
    }