Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • delight delight
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Merge requests 0
    • Merge requests 0
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • Repository
  • Wiki
    • Wiki
  • Activity
  • Graph
  • Commits
Collapse sidebar
  • delight
  • delightdelight
  • Wiki
  • ServerSentEventsFeature

ServerSentEventsFeature · Changes

Page history
updated code-snippet authored May 24, 2019 by Andreas Lauer's avatar Andreas Lauer
Hide whitespace changes
Inline Side-by-side
ServerSentEventsFeature.md
View page @ c610841f
......@@ -6,7 +6,7 @@ to have Java clients to receive those events.
Interface:
public interface SseInterface {
@SSE(autoReconnect=20)
@SSE
EventStream<TestPojo> status(String jobName);
}
......@@ -21,9 +21,15 @@ Implementation:
@Override
public EventStream<TestPojo> status(String jobName) {
return (EventStream<TestPojo> stream) -> {
//compute values, loop or wait
try {
//compute values, loop or wait
//don't forget to check Thread.interrupted() when looping
//the stream may have been closed by the client
if (stream.isClosed()) {
return;
}
TestPojo event = new TestPojo(...);
stream.pushEvent(event);
......@@ -37,9 +43,10 @@ Implementation:
* The implementation returns a `Consumer<EventStream<Payload>>`. This will automatically converted by Java into an `EventStream<Payload>` using FunctionalInterface mechanics.
* The provided stream is the transport for the generated events. _Just push your events into the stream_.
* The consumer may be a long running task. It should check for the interrupted flag, tough
* The consumer may be a long running task. It should check for the `Thread.interrupted()` and `stream.isClosed()` flags, tough.
* When the consumer finishes the connection from the EvenSource is being closed and (possibly) will be re-established after some time.
Client:
Client (asynchronous):
...
DelightConfig cfg = DelightConfigFinder.getDefaultConfigBuilder()
......@@ -53,7 +60,7 @@ Client:
.usingApi(SseInterface.class);
try (EventStream<TestPojo> events = sseService.status("send me events ...")) {
events.register(eventPayload -> {
events.register(eventPayload -> { //elements of type TestPojo
System.out.printf("(SseClient)Received: '%s'\n", eventPayload);
},
ex -> { //error handler
......
Clone repository
  • DocuFeature
  • ExampleServer
  • ExampleWebApp
  • Home
  • ServerSentEventsFeature
  • StatsFeature
  • people
  • xmlrpc
    • Documentation
    • ExampleUsingConverterRegistry
    • ExampleUsingOwnConceteTypes
    • ExampleUsingOwnInterfaceTypes
    • ExampleUsingThirdPartyTypes
    • ExampleUsingXmlRpcBeans
    • ExampleUsingXmlRpcCompliantTypes

Legal Notice, Imprint, Privacy Policy