com.pubnub.api.builder.SubscribeBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pubnub Show documentation
Show all versions of pubnub Show documentation
PubNub is a cross-platform client-to-client (1:1 and 1:many) push service in the cloud, capable of
broadcasting real-time messages to millions of web and mobile clients simultaneously, in less than a quarter
second!
package com.pubnub.api.builder;
import com.pubnub.api.builder.dto.SubscribeOperation;
import com.pubnub.api.managers.SubscriptionManager;
import lombok.AccessLevel;
import lombok.Setter;
import lombok.experimental.Accessors;
import java.util.List;
@Setter
@Accessors(chain = true, fluent = true)
public class SubscribeBuilder extends PubSubBuilder {
/**
* Allow users to specify if they would also like to include the presence channels for those subscriptions.
*/
@Setter(AccessLevel.NONE)
private boolean presenceEnabled;
/**
* Allow users to subscribe with a custom timetoken.
*/
@Setter(AccessLevel.NONE)
private Long timetoken;
public SubscribeBuilder(final SubscriptionManager subscriptionManager) {
super(subscriptionManager);
}
public SubscribeBuilder withPresence() {
this.presenceEnabled = true;
return this;
}
public SubscribeBuilder withTimetoken(Long timetokenInstance) {
this.timetoken = timetokenInstance;
return this;
}
public void execute() {
SubscribeOperation subscribeOperation = SubscribeOperation.builder()
.channels(this.getChannelSubscriptions())
.channelGroups(this.getChannelGroupSubscriptions())
.timetoken(timetoken)
.presenceEnabled(presenceEnabled)
.build();
this.getSubscriptionManager().adaptSubscribeBuilder(subscribeOperation);
}
public SubscribeBuilder channels(final List channels) {
return (SubscribeBuilder) super.channels(channels);
}
public SubscribeBuilder channelGroups(final List channelGroups) {
return (SubscribeBuilder) super.channelGroups(channelGroups);
}
}