Android Open Source - RealtimeMessaging-Android Channel Subscription






From Project

Back to project page RealtimeMessaging-Android.

License

The source code is released under:

MIT License

If you think the Android project RealtimeMessaging-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * @fileoverview This file contains the class to create ortc factories
 * @author ORTC team members (ortc@ibt.pt) 
 *//*w w  w .ja  v a 2 s. c  o  m*/
package ibt.ortc.extensibility;

import java.util.HashMap;
import java.util.Map;

/**
 * Class that represents a channel subscription
 *  
 * How to use:
 * <pre>
 * subscribedChannel = new ChannelSubscription(subscribeOnReconnect, onMessageEventHandler);
 * </pre>
 * @version 2.1.0 27 Mar 2013
 * @author IBT
 * 
 */
public class ChannelSubscription {
  private boolean isSubscribing;
  private boolean isSubscribed;
  private boolean subscribeOnReconnected;
  private OnMessage onMessage;
  private OnMessageWithPayload onMessageWithPayload;
  private boolean isWithPayload;
  private boolean withNotification;
  
  /**
   * Creates an instance of a channel subscription
   * @param subscribeOnReconnected Indicates if the channel should be subscribe if a reconnect happens
   * @param onMessageT Event handler that is fired when a message is received in the channel
   * @param withNotification If true, GCM will be used
   */
  public <T> ChannelSubscription(boolean subscribeOnReconnected,T onMessageT, boolean withNotification){
    this.subscribeOnReconnected = subscribeOnReconnected;

    
    this.onMessageWithPayload = null;
    if(onMessageT instanceof OnMessage){
      this.onMessage = (OnMessage) onMessageT;
      this.isWithPayload = false;
    } else {
      this.onMessageWithPayload = (OnMessageWithPayload) onMessageT;
      this.isWithPayload = true;
    }
    this.isSubscribed = false;
    this.isSubscribing = false;
    this.withNotification = withNotification;
  }
  
  /**
   * Indicates whether the channel is being subscribed or not
   * @return boolean True if is subscribing the channel otherwise false
   */
  public boolean isSubscribing() {
    return isSubscribing;
  }

  /**
   * Changes the channel subscribing status
   * @param isSubscribing True indicates the channel is being subscribed
   */
  public void setSubscribing(boolean isSubscribing) {
    this.isSubscribing = isSubscribing;
  }

  /**
   * Indicates whether the channel is subscribed or not
   * @return boolean True if the channel is subscribed otherwise false
   */
  public boolean isSubscribed() {
    return isSubscribed;
  }

  /**
   * Changes the channel subscribed status
   * @param isSubscribed True indicates the channel is being subscribed
   */
  public void setSubscribed(boolean isSubscribed) {
    this.isSubscribed = isSubscribed;
  }

  /**
   * Fires the event handler that is associated the subscribed channel
   * @param channel 
   * @param sender
   * @param message 
   */
  public void runHandler(OrtcClient sender, String channel, String message){
    this.runHandler(sender, channel, message, null);
  }
  /**
   * Fires the event handler that is associated the subscribed channel (with payload)
   * @param channel 
   * @param sender
   * @param message 
   * @param payload
   */
  public void runHandler(OrtcClient sender, String channel, String message, Map<String, Object> payload){
    if(this.isWithPayload){
      this.onMessageWithPayload.run(sender, channel, message, payload);
    } else {
      this.onMessage.run(sender, channel, message);    
    }
  }
  
  /**
   * Indicates where the channel should be subscribed if a reconnect happens
   * @return boolean True if should be subscribed otherwise false
   */
  public boolean subscribeOnReconnected() {
    return subscribeOnReconnected;
  }
  
  /**
   * Indicates where the channel should be subscribed if a reconnect happens
   */
  public void setSubscribeOnReconnected(boolean value) {
    subscribeOnReconnected = value;
  }
  
  public boolean isWithNotification(){
    return this.withNotification;
  }
}




Java Source Code List

ibt.ortc.api.ApplicationTest.java
ibt.ortc.api.Authentication.java
ibt.ortc.api.Balancer.java
ibt.ortc.api.ChannelPermissions.java
ibt.ortc.api.InvalidBalancerServerException.java
ibt.ortc.api.OnDisablePresence.java
ibt.ortc.api.OnEnablePresence.java
ibt.ortc.api.OnPresence.java
ibt.ortc.api.OnRestWebserviceResponse.java
ibt.ortc.api.OrtcAuthenticationNotAuthorizedException.java
ibt.ortc.api.Ortc.java
ibt.ortc.api.Pair.java
ibt.ortc.api.Presence.java
ibt.ortc.api.RestWebservice.java
ibt.ortc.api.SecureWebConnections.java
ibt.ortc.api.Strings.java
ibt.ortc.extensibility.ChannelSubscription.java
ibt.ortc.extensibility.CharEscaper.java
ibt.ortc.extensibility.ConnectionProtocol.java
ibt.ortc.extensibility.DispatchedMessages.java
ibt.ortc.extensibility.EventEnum.java
ibt.ortc.extensibility.GcmOrtcBroadcastReceiver.java
ibt.ortc.extensibility.GcmOrtcIntentService.java
ibt.ortc.extensibility.GcmRegistration.java
ibt.ortc.extensibility.HeartbeatSender.java
ibt.ortc.extensibility.OnConnected.java
ibt.ortc.extensibility.OnDisconnected.java
ibt.ortc.extensibility.OnException.java
ibt.ortc.extensibility.OnMessageWithPayload.java
ibt.ortc.extensibility.OnMessage.java
ibt.ortc.extensibility.OnReconnected.java
ibt.ortc.extensibility.OnReconnecting.java
ibt.ortc.extensibility.OnSubscribed.java
ibt.ortc.extensibility.OnUnsubscribed.java
ibt.ortc.extensibility.OrtcClient.java
ibt.ortc.extensibility.OrtcFactory.java
ibt.ortc.extensibility.exception.OrtcAlreadyConnectedException.java
ibt.ortc.extensibility.exception.OrtcDoesNotHavePermissionException.java
ibt.ortc.extensibility.exception.OrtcEmptyFieldException.java
ibt.ortc.extensibility.exception.OrtcGcmException.java
ibt.ortc.extensibility.exception.OrtcInvalidCharactersException.java
ibt.ortc.extensibility.exception.OrtcMaxLengthException.java
ibt.ortc.extensibility.exception.OrtcNotConnectedException.java
ibt.ortc.extensibility.exception.OrtcNotSubscribedException.java
ibt.ortc.extensibility.exception.OrtcSubscribedException.java
ibt.ortc.ortclib.ApplicationTest.java
ibt.ortc.ortclib.MainActivity.java
ibt.ortc.ortclib.SettingsActivity.java
ibt.ortc.plugins.IbtRealtimeSJ.IbtRealtimeSJClient.java
ibt.ortc.plugins.IbtRealtimeSJ.IbtRealtimeSJFactory.java
ibt.ortc.plugins.IbtRealtimeSJ.OrtcMessage.java
ibt.ortc.plugins.IbtRealtimeSJ.OrtcOperation.java
ibt.ortc.plugins.IbtRealtimeSJ.OrtcServerErrorException.java
ibt.ortc.plugins.websocket.WebSocketConnection.java
ibt.ortc.plugins.websocket.WebSocketEventHandler.java
ibt.ortc.plugins.websocket.WebSocketException.java
ibt.ortc.plugins.websocket.WebSocketHandshake.java
ibt.ortc.plugins.websocket.WebSocketMessage.java
ibt.ortc.plugins.websocket.WebSocketReceiver.java
ibt.ortc.plugins.websocket.WebSocketSender.java
ibt.ortc.plugins.websocket.WebSocket.java