Android Open Source - tape In Memory Object Queue






From Project

Back to project page tape.

License

The source code is released under:

Apache License

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

// Copyright 2012 Square, Inc.
package com.squareup.tape;
/*ww w  .  ja  v a 2 s.c  o m*/
import java.util.LinkedList;
import java.util.Queue;

/**
 * A queue for objects that are not serious enough to be written to disk.  Objects in this queue
 * are kept in memory and will not be serialized.
 *
 * @param <T> The type of elements in the queue.
 */
public class InMemoryObjectQueue<T> implements ObjectQueue<T> {
  private final Queue<T> tasks;
  private Listener<T> listener;

  @SuppressWarnings("unchecked")
  public InMemoryObjectQueue() {
    tasks = (Queue<T>) new LinkedList();
  }

  @Override public void add(T entry) {
    tasks.add(entry);
    if (listener != null) listener.onAdd(this, entry);
  }

  @Override public T peek() {
    return tasks.peek();
  }

  @Override public int size() {
    return tasks.size();
  }

  @Override public void remove() {
    tasks.remove();
    if (listener != null) listener.onRemove(this);
  }

  @Override public void setListener(Listener<T> listener) {
    if (listener != null) {
      for (T task : tasks) {
        listener.onAdd(this, task);
      }
    }
    this.listener = listener;
  }
}




Java Source Code List

com.squareup.tape.FileException.java
com.squareup.tape.FileObjectQueue.java
com.squareup.tape.InMemoryObjectQueue.java
com.squareup.tape.ObjectQueue.java
com.squareup.tape.QueueFile.java
com.squareup.tape.SerializedConverter.java
com.squareup.tape.TaskInjector.java
com.squareup.tape.TaskQueue.java
com.squareup.tape.Task.java
com.squareup.tape.sample.GsonConverter.java
com.squareup.tape.sample.ImageUploadQueueSizeEvent.java
com.squareup.tape.sample.ImageUploadSuccessEvent.java
com.squareup.tape.sample.ImageUploadTaskQueue.java
com.squareup.tape.sample.ImageUploadTaskService.java
com.squareup.tape.sample.ImageUploadTask.java
com.squareup.tape.sample.SampleActivity.java
com.squareup.tape.sample.SampleApplication.java