-
Notifications
You must be signed in to change notification settings - Fork 214
/
DistributedPubImpl.java
63 lines (53 loc) · 2.27 KB
/
DistributedPubImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Copyright (c) 2019 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.internal.utils.pubsub;
import java.util.Set;
import org.eclipse.ditto.base.model.acks.AcknowledgementRequest;
import org.eclipse.ditto.base.model.signals.Signal;
import org.eclipse.ditto.internal.utils.pubsub.actors.Publisher;
import org.eclipse.ditto.internal.utils.pubsub.extractors.AckExtractor;
import org.eclipse.ditto.internal.utils.pubsub.extractors.PubSubTopicExtractor;
import org.apache.pekko.actor.ActorRef;
/**
* Package-private implementation of {@link DistributedPub} for publication access from an already-started
* pub-supervisor and topic extractor.
*
* @param <T> type of messages.
*/
final class DistributedPubImpl<T extends Signal<?>> implements DistributedPub<T> {
private final ActorRef pubSupervisor;
private final PubSubTopicExtractor<T> topicExtractor;
DistributedPubImpl(final ActorRef pubSupervisor, final PubSubTopicExtractor<T> topicExtractor) {
this.pubSupervisor = pubSupervisor;
this.topicExtractor = topicExtractor;
}
@Override
public ActorRef getPublisher() {
return pubSupervisor;
}
@Override
public Object wrapForPublication(final T message, final CharSequence groupIndexKey) {
return Publisher.publish(topicExtractor.getTopics(message), message, groupIndexKey);
}
@Override
public <S extends T> Object wrapForPublicationWithAcks(final S message, final CharSequence groupIndexKey,
final AckExtractor<S> ackExtractor) {
final Set<AcknowledgementRequest> ackRequests = ackExtractor.getAckRequests(message);
if (ackRequests.isEmpty()) {
return wrapForPublication(message, groupIndexKey);
} else {
return Publisher.publishWithAck(topicExtractor.getTopics(message), message, ackRequests,
ackExtractor.getEntityId(message), ackExtractor.getDittoHeaders(message));
}
}
}