Android Open Source - client-android Log Event Dispatcher






From Project

Back to project page client-android.

License

The source code is released under:

Apache License

If you think the Android project client-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 com.qmonix.sdk;
/* ww w  .ja  va 2 s .c  o  m*/
import org.json.JSONException;


/**
 * Prints events to the log output. Good for testing or as a fallback default dispatcher when
 * other dispatchers fails or are not present.
 *
 * All methods are thread safe.
 */
public class LogEventDispatcher implements EventDispatcher {

  private EventMessage eventMessage = new EventMessage();


  /**
   * Caches event. It will be dispatched explicitly with dispatch() method.
   *
   * @param event event to dispatch.
   */
  @Override
  synchronized public void submit(Event event) {
    if (event == null) {
      throw new IllegalArgumentException("Event cannot be null.");
    }

    this.eventMessage.addEvent(event);
  }

  /**
   * Sends events encoded to JSON to log output. Clears collected events on success.
   *
   * @param handler success handler.
   */
  @Override
  synchronized public void dispatch(EventDispatchHandler handler) {
    try {
      QLog.info(this.eventMessage.toJson());
      this.eventMessage = new EventMessage();
      handler.onSuccess();

    } catch (JSONException e) {
      String errMsg = "Failed to encode events to JSON: " + e.toString();
      handler.onError(errMsg);
    }
  }
}




Java Source Code List

com.qmonix.sample.basic.MainActivity.java
com.qmonix.sdk.EventDispatchHandler.java
com.qmonix.sdk.EventDispatcher.java
com.qmonix.sdk.EventMessage.java
com.qmonix.sdk.Event.java
com.qmonix.sdk.FireableTimingEvent.java
com.qmonix.sdk.HttpEventDispatcher.java
com.qmonix.sdk.LogEventDispatcher.java
com.qmonix.sdk.QLog.java
com.qmonix.sdk.TimingEvent.java
com.qmonix.sdk.Tracker.java
com.qmonix.sdk.VolumeEvent.java
com.qmonix.sdk.helpers.HttpHelper.java
com.qmonix.sdk.helpers.exceptions.HttpHelperException.java
com.qmonix.sdk.utils.AsyncTaskResult.java
com.qmonix.sdk.utils.Utils.java