io.getstream.core.faye.subscription.ChannelSubscription Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stream-java Show documentation
Show all versions of stream-java Show documentation
Stream Feeds Java Client for backend and android integrations
package io.getstream.core.faye.subscription;
import io.getstream.core.faye.Message;
import io.getstream.core.faye.client.FayeClient;
public class ChannelSubscription {
private final FayeClient client;
private final String channel;
private final ChannelDataCallback channelDataCallback;
private final SubscriptionCancelledCallback onCancelledCallback;
private WithChannelDataCallback withChannel;
private boolean cancelled = false;
public ChannelSubscription(FayeClient client, String channel) {
this.client = client;
this.channel = channel;
this.channelDataCallback = null;
this.onCancelledCallback = null;
}
public ChannelSubscription(
FayeClient client,
String channel,
ChannelDataCallback channelDataCallback,
SubscriptionCancelledCallback onCancelledCallback) {
this.client = client;
this.channel = channel;
this.channelDataCallback = channelDataCallback;
this.onCancelledCallback = onCancelledCallback;
}
public ChannelSubscription setWithChannel(WithChannelDataCallback withChannel) {
this.withChannel = withChannel;
return this;
}
public void call(Message message) {
if (channelDataCallback != null) channelDataCallback.onData(message.getData());
if (withChannel != null) withChannel.onData(message.getChannel(), message.getData());
}
public void cancel() {
if (cancelled) return;
client.unsubscribe(channel, this);
if (onCancelledCallback != null) onCancelledCallback.onCancelled();
cancelled = true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy