- 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 is convenience publisher for one or multiple channels, publishing is as easy as callingsend(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
Nested Classes Modifier and Type Class Description static class
Emitter.Builder<PAYLOAD>
Builder forEmitter
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <PAYLOAD> Emitter.Builder<PAYLOAD>
builder()
Prepare new builder for Emitter construction.void
complete()
Send onComplete signal to all subscribers.static <PAYLOAD> Emitter<PAYLOAD>
create(Channel<PAYLOAD> channel)
Create new Emitter to serve as a publisher for supplied channel.static <PAYLOAD> Emitter<PAYLOAD>
create(Channel<PAYLOAD> channel, Channel<PAYLOAD>... channels)
Create new Emitter to serve as a broadcast publisher for supplied channels.void
error(Exception e)
Send onError signal to all subscribers.int
send(Message<PAYLOAD> msg)
SendMessage
to downstream when demand is higher than 0.CompletionStage<Void>
send(PAYLOAD msg)
Send raw payload to downstream, wrapped toMessage
when demand is higher than 0.void
subscribe(Subscriber<? super Message<PAYLOAD>> s)
-
-
-
Method Detail
-
send
public CompletionStage<Void> send(PAYLOAD msg)
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.- Parameters:
msg
- payload to be wrapped and sent(or buffered if there is no demand)- Returns:
- callback being invoked when message is acked
-
send
public int send(Message<PAYLOAD> msg)
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
public void error(Exception e)
Send onError signal to all subscribers.- Parameters:
e
- error to send in onError signal downstream
-
subscribe
public void subscribe(Subscriber<? super Message<PAYLOAD>> s)
-
create
public static <PAYLOAD> Emitter<PAYLOAD> create(Channel<PAYLOAD> channel)
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
public static <PAYLOAD> Emitter.Builder<PAYLOAD> builder()
Prepare new builder for Emitter construction.- Type Parameters:
PAYLOAD
- message payload type- Returns:
- new emitter builder
-
-