-
Notifications
You must be signed in to change notification settings - Fork 215
/
Subscribe.java
107 lines (95 loc) · 3.52 KB
/
Subscribe.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
* Copyright (c) 2020 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.api;
import java.util.Collection;
import java.util.Optional;
import java.util.function.Predicate;
import javax.annotation.Nullable;
import akka.actor.ActorRef;
import akka.cluster.ddata.Replicator;
/**
* Request to subscribe to topics.
*/
public final class Subscribe extends AbstractRequest {
@Nullable private final Predicate<Collection<String>> filter;
@Nullable private final String group;
private final boolean resubscribe;
private Subscribe(final Collection<String> topics,
final ActorRef subscriber,
final Replicator.WriteConsistency writeConsistency,
final boolean acknowledge,
@Nullable final Predicate<Collection<String>> filter,
@Nullable final String group,
final boolean resubscribe) {
super(topics, subscriber, writeConsistency, acknowledge);
this.filter = filter;
this.group = group;
this.resubscribe = resubscribe;
}
/**
* Create a "subscribe" request.
*
* @param topics the topics to subscribe to.
* @param subscriber who is subscribing.
* @param writeConsistency with which write consistency should this subscription be updated.
* @param acknowledge whether acknowledgement is desired.
* @param group any group the subscriber belongs to, or null.
* @return the request.
*/
public static Subscribe of(final Collection<String> topics,
final ActorRef subscriber,
final Replicator.WriteConsistency writeConsistency,
final boolean acknowledge,
@Nullable final String group) {
return new Subscribe(topics, subscriber, writeConsistency, acknowledge, null, group, false);
}
/**
* Create a "subscribe" request.
*
* @param topics the topics to subscribe to.
* @param subscriber who is subscribing.
* @param writeConsistency with which write consistency should this subscription be updated.
* @param acknowledge whether acknowledgement is desired.
* @param filter local filter for incoming messages.
* @param group any group the subscriber belongs to, or null.
* @return the request.
*/
public static Subscribe of(final Collection<String> topics,
final ActorRef subscriber,
final Replicator.WriteConsistency writeConsistency,
final boolean acknowledge,
@Nullable final Predicate<Collection<String>> filter,
@Nullable final String group,
final boolean resubscribe) {
return new Subscribe(topics, subscriber, writeConsistency, acknowledge, filter, group, resubscribe);
}
/**
* @return Filter for incoming messages.
*/
@Nullable
public Predicate<Collection<String>> getFilter() {
return filter;
}
/**
* @return the group the subscriber belongs to, or an empty optional.
*/
public Optional<String> getGroup() {
return Optional.ofNullable(group);
}
/**
* @return Whether this is a resubscribe request.
*/
public boolean isResubscribe() {
return resubscribe;
}
}