001package com.pusher.client.channel;
002
003/**
004 * Client applications should implement this interface if they want to be
005 * notified when events are received on a public or private channel.
006 *
007 * <p>
008 * To bind your implementation of this interface to a channel, either:
009 * </p>
010 * <ul>
011 * <li>Call {@link com.pusher.client.Pusher#subscribe(String)} to subscribe and
012 * receive an instance of {@link Channel}.</li>
013 * <li>Call {@link Channel#bind(String, SubscriptionEventListener)} to bind your
014 * listener to a specified event.</li>
015 * </ul>
016 *
017 * <p>
018 * Or, call
019 * {@link com.pusher.client.Pusher#subscribe(String, ChannelEventListener, String...)}
020 * to subscribe to a channel and bind your listener to one or more events at the
021 * same time.
022 * </p>
023 */
024public interface SubscriptionEventListener {
025    /**
026     * Callback that is fired whenever an event that this
027     * {@linkplain SubscriptionEventListener} has been bound to is received.
028     *
029     * @param event A PusherEvent object which exposes the whole event.
030     *              See {@linkplain PusherEvent} for more.
031     */
032    void onEvent(final PusherEvent event);
033
034    /**
035     * Callback that is fired whenever an unexpected error occurs processing
036     * for this {@linkplain SubscriptionEventListener}.
037     *
038     * @param message A description of the problem.
039     * @param e       An associated exception, if available.
040     */
041    default void onError(String message, Exception e) {
042        // No-op
043        return;
044    }
045}