Android Open Source - RealtimeStorage-Android Heartbeat






From Project

Back to project page RealtimeStorage-Android.

License

The source code is released under:

MIT License

If you think the Android project RealtimeStorage-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

package co.realtime.storage.entities;
/* w  w w.  ja v a  2s  .  c om*/
import co.realtime.storage.ext.StorageException;

/**
 * Heartbeat configuration. An heartbeat is a small message periodically sent to the Realtime Messaging servers. When the Realtime Messaging Server detects that a given client isn't sending the heartbeat for a specified period (the default is 3 lost heartbeats) it will consider that the user has disconnected and perform the normal disconnection operations (e.g. decrease the number of subscribers).
 * 
 * @author RTCS Development Team
 *
 */
public class Heartbeat {
  Boolean active;
  Integer fails;
  Integer time;
  
  /**
   * Retrieves the current state of the heartbeat feature.
   * 
   * @return The current active state. 
   */
  public Boolean getActive() {
    return active;
  }
  
  /**
   * Enables/Disables the heartbeat feature.
   * 
   * @param active The active state.
   */
  public void setActive(Boolean active) {
    this.active = active;
  }
  
  /**
   * Retrieves the number of lost messages a server should expect before the servers consider the client has disconnected.
   * 
   * @return The number of fails.
   */
  public Integer getFails() {
    return fails;
  }
  
  /**
   * Assigns the number of lost messages a server should expect before the servers consider the client has disconnected. Ranges between 1 and 6.
   * 
   * @param fails 
   *     The number of times, heartbeat messages, are lost before the server considers the client has disconnected.
   * @throws StorageException 
   *     Exception thrown if the value set is outside the allowed range.
   */
  public void setFails(Integer fails) throws StorageException {
    if(fails > 0 && fails < 7)
      this.fails = fails;
    else
      throw new StorageException("Parameter 'fails' must be between 1 and 6.");
  }
  
  /**
   * Retrieves the time (seconds) between heartbeat messages sent to the server.
   * 
   * @return The time (seconds) between heartbeat messages sent to the server.
   */
  public Integer getTime() {
    return time;
  }
  
  /**
   * Assigns the time (seconds) between heartbeat messages sent to the server.
   * 
   * @param time 
   *     (seconds) Ranges between 10 and 60 seconds.
   * @throws StorageException 
   *     Exception thrown if the value set is outside the allowed range.
   */
  public void setTime(Integer time) throws StorageException {
    if(time > 9 && time < 61)
      this.time = time;
    else
      throw new StorageException("Parameter 'time' must be between 10 and 60.");
  }
  
  /**
   * Creates an empty Heartbeat instance.
   */
  public Heartbeat() {
    active = null;
    fails = null;
    time = null;
  }
  
  /**
   * Creates a Heartbeat instance with the given configuration.
   * 
   * @param active 
   *     Enables/Disables the heartbeat feature.
   * @param fails 
   *     The number of times, heartbeat messages, are lost before the server considers the client has disconnected.
   * @param time 
   *     Assigns the time (seconds) between heartbeat messages sent to the server.
   * @throws StorageException 
   *     Exception thrown if any of the specified attributes are outside the allowed range. 
   */
  public Heartbeat(Boolean active, Integer fails, Integer time) throws StorageException {
    setActive(active);
    setFails(fails);
    setTime(time);
  }
}




Java Source Code List

adapters.TodoCustomAdapter.java
co.realtime.sample.ApplicationTest.java
co.realtime.sample.MainActivity.java
co.realtime.storage.ApplicationTest.java
co.realtime.storage.EventCollection.java
co.realtime.storage.Event.java
co.realtime.storage.Filter.java
co.realtime.storage.ItemAttribute.java
co.realtime.storage.ItemRef.java
co.realtime.storage.ItemSnapshot.java
co.realtime.storage.LHMItemsComparator.java
co.realtime.storage.OnRestCompleted.java
co.realtime.storage.PostBodyBuilder.java
co.realtime.storage.ProcessRestResponse.java
co.realtime.storage.RestWebservice.java
co.realtime.storage.Rest.java
co.realtime.storage.StorageContext.java
co.realtime.storage.StorageRef.java
co.realtime.storage.TableRef.java
co.realtime.storage.TableSnapshot.java
co.realtime.storage.entities.Heartbeat.java
co.realtime.storage.entities.IORMapping.java
co.realtime.storage.entities.KeySchema.java
co.realtime.storage.entities.Key.java
co.realtime.storage.entities.TableMetadata.java
co.realtime.storage.entities.Throughput.java
co.realtime.storage.ext.OnBooleanResponse.java
co.realtime.storage.ext.OnError.java
co.realtime.storage.ext.OnHeartbeat.java
co.realtime.storage.ext.OnItemSnapshot.java
co.realtime.storage.ext.OnPresence.java
co.realtime.storage.ext.OnReconnected.java
co.realtime.storage.ext.OnReconnecting.java
co.realtime.storage.ext.OnTableCreation.java
co.realtime.storage.ext.OnTableMetadata.java
co.realtime.storage.ext.OnTableSnapshot.java
co.realtime.storage.ext.OnTableUpdate.java
co.realtime.storage.ext.StorageException.java
config.Config.java
handlers.StorageHandler.java
helpers.ListNameHelper.java
listeners.ClickListener.java
listeners.EditorListener.java
ui.MyViewPager.java