-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from scc-digitalhub/websocket
Websocket for run states
- Loading branch information
Showing
8 changed files
with
507 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...cation/src/main/java/it/smartcommunitylabdhub/core/components/cloud/RunCloudListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package it.smartcommunitylabdhub.core.components.cloud; | ||
|
||
import it.smartcommunitylabdhub.commons.models.entities.run.Run; | ||
import it.smartcommunitylabdhub.core.websocket.UserNotificationService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@Slf4j | ||
public class RunCloudListener { | ||
|
||
private UserNotificationService notificationService; | ||
|
||
@Autowired(required = false) | ||
public void setNotificationService(UserNotificationService notificationService) { | ||
this.notificationService = notificationService; | ||
} | ||
|
||
@Async | ||
@EventListener | ||
public void broadcast(CloudEntityEvent<Run> event) { | ||
Run run = event.getDto(); | ||
|
||
if (run != null) { | ||
log.debug("receive event for {}: {}", run.getId(), event.getAction()); | ||
|
||
if (notificationService != null) { | ||
//forward all events to users via notification | ||
//TODO support filtering/config | ||
notificationService.notifyOwner(run); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.