-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/helper_subscribeToFeed' into develop
- Loading branch information
Showing
2 changed files
with
38 additions
and
2 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
runtime/src/main/java/com/fluxtion/runtime/output/AbstractMessageSink.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,25 @@ | ||
/* | ||
* SPDX-FileCopyrightText: © 2024 Gregory Higgins <[email protected]> | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
package com.fluxtion.runtime.output; | ||
|
||
import java.util.function.Function; | ||
|
||
public abstract class AbstractMessageSink<T> implements MessageSink<T> { | ||
|
||
private Function<? super T, ?> valueMapper = Function.identity(); | ||
|
||
@Override | ||
public final void accept(T t) { | ||
sendToSink(valueMapper.apply(t)); | ||
} | ||
|
||
@Override | ||
public void setValueMapper(Function<? super T, ?> valueMapper) { | ||
this.valueMapper = valueMapper; | ||
} | ||
|
||
abstract protected void sendToSink(Object value); | ||
} |
15 changes: 13 additions & 2 deletions
15
runtime/src/main/java/com/fluxtion/runtime/output/MessageSink.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 |
---|---|---|
@@ -1,12 +1,23 @@ | ||
/* | ||
* SPDX-FileCopyrightText: © 2024 Gregory Higgins <[email protected]> | ||
* SPDX-License-Identifier: AGPL-3.0-only | ||
*/ | ||
|
||
package com.fluxtion.runtime.output; | ||
|
||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* A sink for an EventProcessor. Implement this interface and register with : | ||
* | ||
* <p> | ||
* {@link com.fluxtion.runtime.EventProcessor#registerService(Object, Class, String)} | ||
* | ||
* @param <T> the type of message published to the Sink | ||
*/ | ||
public interface MessageSink<T> extends Consumer<T> { | ||
} | ||
|
||
default void setValueMapper(Function<? super T, ?> valueMapper) { | ||
throw new UnsupportedOperationException("setValueMapper not implemented"); | ||
} | ||
} |