java.lang.Object
io.helidon.messaging.Emitter<PAYLOAD>
- Type Parameters:
PAYLOAD- message payload type
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
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic <PAYLOAD> Emitter.Builder<PAYLOAD>builder()Prepare new builder for Emitter construction.voidcomplete()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.voidSend onError signal to all subscribers.intSendMessageto downstream when demand is higher than 0.Send raw payload to downstream, wrapped toMessagewhen demand is higher than 0.voidsubscribe(Subscriber<? super Message<PAYLOAD>> s)
-
Method Details
-
send
Send raw payload to downstream, wrapped toMessagewhen 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
SendMessageto 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.- Parameters:
e- error to send in onError signal downstream
-
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
-