-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use standard design patterns for fluxes
- Loading branch information
Showing
15 changed files
with
137 additions
and
211 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/main/java/com/trickl/flux/consumers/SimpMessageSender.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,30 @@ | ||
package com.trickl.flux.consumers; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.logging.Level; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.java.Log; | ||
|
||
import org.springframework.messaging.simp.SimpMessagingTemplate; | ||
|
||
@Log | ||
@RequiredArgsConstructor | ||
public class SimpMessageSender<T> implements | ||
Consumer<T> { | ||
|
||
private final SimpMessagingTemplate messagingTemplate; | ||
private final String destination; | ||
|
||
@Override | ||
public void accept(T t) { | ||
sendMessage(t); | ||
} | ||
|
||
void sendMessage(T value) { | ||
log.log( | ||
Level.FINE, "\u001B[32mSENDING ↑ {0}\u001B[0m on {1}", | ||
new Object[] {value, destination}); | ||
messagingTemplate.convertAndSend(destination, value); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/trickl/flux/mappers/DifferentialMapper.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,31 @@ | ||
package com.trickl.flux.mappers; | ||
|
||
import java.util.Optional; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import java.util.function.BiFunction; | ||
import java.util.function.Function; | ||
import lombok.AllArgsConstructor; | ||
import lombok.RequiredArgsConstructor; | ||
import org.reactivestreams.Publisher; | ||
|
||
@RequiredArgsConstructor | ||
@AllArgsConstructor | ||
public class DifferentialMapper<T, S> | ||
implements Function<T, Publisher<? extends S>> { | ||
|
||
private final BiFunction<T, T, Publisher<S>> transform; | ||
|
||
private final T emptyValue; | ||
|
||
private AtomicReference<Optional<T>> lastValue = | ||
new AtomicReference<>(Optional.empty()); | ||
|
||
@Override | ||
public Publisher<S> apply(T t) { | ||
return transform.apply( | ||
lastValue.getAndSet(Optional.of(t)) | ||
.orElse(emptyValue), | ||
t | ||
); | ||
} | ||
} |
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
28 changes: 0 additions & 28 deletions
28
src/main/java/com/trickl/flux/publishers/DifferentialPollPublisher.java
This file was deleted.
Oops, something went wrong.
49 changes: 0 additions & 49 deletions
49
src/main/java/com/trickl/flux/publishers/SimpMessagingPublisher.java
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
src/main/java/com/trickl/flux/transformers/DifferentialTransformer.java
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
src/main/java/com/trickl/flux/transformers/SingletonFluxTransfomer.java
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
src/main/java/com/trickl/flux/websocket/BinaryWebSocketFluxClient.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
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
1 change: 0 additions & 1 deletion
1
src/main/java/com/trickl/flux/websocket/TextWebSocketFluxClient.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
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
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
Oops, something went wrong.