All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.getstream.core.faye.subscription.ChannelSubscription Maven / Gradle / Ivy

There is a newer version: 3.15.0
Show newest version
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