
com.pusher.client.channel.impl.PrivateChannelImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pusher-java-client Show documentation
Show all versions of pusher-java-client Show documentation
This is a Java client library for Pusher, targeted at core Java and Android.
package com.pusher.client.channel.impl;
import java.util.LinkedHashMap;
import java.util.Map;
import com.google.gson.Gson;
import com.google.gson.JsonSyntaxException;
import com.pusher.client.AuthorizationFailureException;
import com.pusher.client.Authorizer;
import com.pusher.client.channel.ChannelState;
import com.pusher.client.channel.PrivateChannel;
import com.pusher.client.channel.PrivateChannelEventListener;
import com.pusher.client.channel.SubscriptionEventListener;
import com.pusher.client.connection.ConnectionState;
import com.pusher.client.connection.impl.InternalConnection;
import com.pusher.client.util.Factory;
public class PrivateChannelImpl extends ChannelImpl implements PrivateChannel {
private static final Gson GSON = new Gson();
private static final String CLIENT_EVENT_PREFIX = "client-";
private final InternalConnection connection;
private final Authorizer authorizer;
protected String channelData;
public PrivateChannelImpl(final InternalConnection connection, final String channelName,
final Authorizer authorizer, final Factory factory) {
super(channelName, factory);
this.connection = connection;
this.authorizer = authorizer;
}
/* PrivateChannel implementation */
@Override
@SuppressWarnings("rawtypes")
public void trigger(final String eventName, final String data) {
if (eventName == null || !eventName.startsWith(CLIENT_EVENT_PREFIX)) {
throw new IllegalArgumentException("Cannot trigger event " + eventName
+ ": client events must start with \"client-\"");
}
if (state != ChannelState.SUBSCRIBED) {
throw new IllegalStateException("Cannot trigger event " + eventName + " because channel " + name
+ " is in " + state.toString() + " state");
}
if (connection.getState() != ConnectionState.CONNECTED) {
throw new IllegalStateException("Cannot trigger event " + eventName + " because connection is in "
+ connection.getState().toString() + " state");
}
try {
final Map
© 2015 - 2025 Weber Informatics LLC | Privacy Policy