java.lang.Object
io.helidon.messaging.Emitter<PAYLOAD>
- Type Parameters:
PAYLOAD
- message payload type
public final class Emitter<PAYLOAD>
extends Object
implements Publisher<Message<PAYLOAD>>, Emitter<PAYLOAD>
Emitter is convenience publisher for one or multiple channels,
publishing is as easy as calling
send(Object)
method.
Channel<String> simpleChannel = Channel.create();
Emitter<String> emitter = Emitter.create(simpleChannel);
Messaging messaging = Messaging.builder()
.emitter(emitter)
.listener(simpleChannel, System.out::println)
.build();
messaging.start();
emitter.send(Message.of("Hello world!"));
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <PAYLOAD> Emitter.Builder<PAYLOAD>
builder()
Prepare new builder for Emitter construction.void
complete()
Send onComplete signal to all subscribers.static <PAYLOAD> Emitter<PAYLOAD>
Create new Emitter to serve as a publisher for supplied channel.static <PAYLOAD> Emitter<PAYLOAD>
Create new Emitter to serve as a broadcast publisher for supplied channels.int
Deprecated, for removal: This API element is subject to removal in a future version.void
Send onError signal to all subscribers.boolean
boolean
send
(M msg) Send raw payload to downstream, wrapped toMessage
when demand is higher than 0.void
subscribe
(Subscriber<? super Message<PAYLOAD>> s)
-
Method Details
-
send
Send raw payload to downstream, wrapped toMessage
when demand is higher than 0. Publishes the given item to each current subscriber by asynchronously invoking its onNext method, blocking uninterruptibly while resources for any subscriber are unavailable. -
send
-
emit
Deprecated, for removal: This API element is subject to removal in a future version.SendMessage
to downstream when demand is higher than 0. Publishes the given item to each current subscriber by asynchronously invoking its onNext method, blocking uninterruptibly while resources for any subscriber are unavailable.- Parameters:
msg
- message wrapper with payload- Returns:
- estimate of the maximum lag (number of items submitted but not yet consumed) among all current subscribers. This value is at least one (accounting for this submitted item) if there are any subscribers, else zero.
- Throws:
IllegalStateException
- if emitter has been already completedNullPointerException
- if message is nullRejectedExecutionException
- if thrown by Executor
-
complete
public void complete()Send onComplete signal to all subscribers. -
error
Send onError signal to all subscribers. -
isCancelled
public boolean isCancelled()- Specified by:
isCancelled
in interfaceEmitter<PAYLOAD>
-
hasRequests
public boolean hasRequests()- Specified by:
hasRequests
in interfaceEmitter<PAYLOAD>
-
subscribe
-
create
Create new Emitter to serve as a publisher for supplied channel.- Type Parameters:
PAYLOAD
- message payload type- Parameters:
channel
- to serve as publisher in- Returns:
- new emitter
-
create
public static <PAYLOAD> Emitter<PAYLOAD> create(Channel<PAYLOAD> channel, Channel<PAYLOAD>... channels) Create new Emitter to serve as a broadcast publisher for supplied channels.- Type Parameters:
PAYLOAD
- message payload type- Parameters:
channel
- to serve as publisher inchannels
- to serve as publisher for- Returns:
- new emitter
-
builder
Prepare new builder for Emitter construction.- Type Parameters:
PAYLOAD
- message payload type- Returns:
- new emitter builder
-