@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature
77import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
88import com.fasterxml.jackson.module.kotlin.readValue
99import com.intellij.openapi.Disposable
10+ import com.intellij.openapi.application.ApplicationManager
1011import com.intellij.openapi.application.PathManager
1112import com.intellij.openapi.components.Service
1213import com.intellij.util.Alarm
@@ -27,56 +28,30 @@ private const val NOTIFICATION_ENDPOINT = "https://idetoolkits-hostedfiles.amazo
2728private const val MAX_RETRIES = 3
2829private const val RETRY_DELAY_MS = 1000L
2930
30- @Service
31- class NotificationPollingService : Disposable {
32- /* *
33- * Data class representing the structure of notifications from the endpoint
34- */
35- data class NotificationFile (
36- val notifications : List <Notification >,
37- val version : String ,
38- )
39-
40- data class Notification (
41- val id : String ,
42- val message : String ,
43- val criteria : NotificationCriteria ,
44- )
45-
46- data class NotificationCriteria (
47- val minVersion : String? ,
48- val maxVersion : String? ,
49- val regions : List <String >? ,
50- val ideType : String? ,
51- val pluginVersion : String? ,
52- val os : String? ,
53- val authType : String? ,
54- val authRegion : String? ,
55- val authState : String? ,
56- val authScopes : List <String >? ,
57- val installedPlugins : List <String >? ,
58- val computeEnvironment : String? ,
59- val messageType : String? ,
60- )
31+
32+ interface NotificationPollingService {
33+ fun startPolling ()
34+ fun dispose ()
35+ }
36+
37+ @Service(Service .Level .APP )
38+ class NotificationPollingServiceImpl : NotificationPollingService , Disposable {
39+
6140 private val mapper = jacksonObjectMapper().configure(DeserializationFeature .FAIL_ON_UNKNOWN_PROPERTIES , false )
62- private val LOG = getLogger<NotificationPollingService >()
63- private var currentETag: String? = null
41+ private var currentETag: String? = null // todo Persistant state? add an init possibly
6442 private val alarm = AlarmFactory .getInstance().create(Alarm .ThreadToUse .POOLED_THREAD , this )
65-
66- init {
67- startPolling()
68- }
43+ private val pollingIntervalMs = Duration .ofMinutes(10 ).toMillis()
6944
7045 override fun dispose () {
7146 alarm.dispose()
7247 }
7348
74- private fun startPolling () {
49+ override fun startPolling () {
7550 pollForNotifications()
7651
7752 alarm.addRequest(
7853 { startPolling() },
79- Duration .ofMinutes( 10 ).toMillis()
54+ pollingIntervalMs
8055 )
8156 }
8257
@@ -99,7 +74,7 @@ class NotificationPollingService : Disposable {
9974 }
10075
10176 // Download and process new notifications
102- val notifications = downloadAndProcessNotifications(newETag )
77+ val notifications = downloadAndProcessNotifications()
10378 currentETag = newETag
10479 return notifications
10580 } catch (e: Exception ) {
@@ -125,7 +100,7 @@ class NotificationPollingService : Disposable {
125100 request.connection.headerFields[" ETag" ]?.firstOrNull() ? : " "
126101 }
127102
128- private fun downloadAndProcessNotifications (newETag : String ): NotificationFile {
103+ private fun downloadAndProcessNotifications (): NotificationFile {
129104 val content = HttpRequests .request(NOTIFICATION_ENDPOINT )
130105 .userAgent(" AWS Toolkit for JetBrains" )
131106 .readString()
@@ -214,5 +189,35 @@ class NotificationPollingService : Disposable {
214189
215190 companion object {
216191 private const val NOTIFICATIONS_RESOURCE_PATH = " /software/aws/toolkits/resources/notifications.json"
192+ private val LOG = getLogger<NotificationPollingServiceImpl >()
193+ fun getInstance (): NotificationPollingService =
194+ ApplicationManager .getApplication().getService(NotificationPollingService ::class .java)
217195 }
218196}
197+
198+ data class NotificationFile (
199+ val notifications : List <Notification >,
200+ val version : String ,
201+ )
202+
203+ data class Notification (
204+ val id : String ,
205+ val message : String ,
206+ val criteria : NotificationCriteria ,
207+ )
208+
209+ data class NotificationCriteria (
210+ val minVersion : String? ,
211+ val maxVersion : String? ,
212+ val regions : List <String >? ,
213+ val ideType : String? ,
214+ val pluginVersion : String? ,
215+ val os : String? ,
216+ val authType : String? ,
217+ val authRegion : String? ,
218+ val authState : String? ,
219+ val authScopes : List <String >? ,
220+ val installedPlugins : List <String >? ,
221+ val computeEnvironment : String? ,
222+ val messageType : String? ,
223+ )
0 commit comments