com.squareup.tape.FileObjectQueue Java Examples

The following examples show how to use com.squareup.tape.FileObjectQueue. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AppModule.java    From goro with Apache License 2.0 5 votes vote down vote up
@Provides @Singleton
public TaskQueue<TransactionTask> tokenTaskTaskQueue() {
  try {
    TaskSerializer serializer = new TaskSerializer();
    return new TaskQueue<>(
        new FileObjectQueue<>(appContext.getFileStreamPath("token-tasks"), serializer)
    );
  } catch (IOException e) {
    throw new AssertionError(e);
  }
}
 
Example #2
Source File: TaskQueueDelegateFactory.java    From glimmr with Apache License 2.0 5 votes vote down vote up
public FileObjectQueue<T> get(String fileName, Class<T> taskType) {
    final Converter<T> converter =
        new GsonConverter<T>(new Gson(), taskType);
    final File queueFile = new File(mContext.getFilesDir(), fileName);
    FileObjectQueue<T> delegate = null;
    try {
        delegate = new FileObjectQueue<T>(queueFile, converter);
    } catch (IOException e) {
        // TODO: how should we handle this
        e.printStackTrace();
    }
    return delegate;
}
 
Example #3
Source File: JandyWorker.java    From jandy with GNU General Public License v3.0 4 votes vote down vote up
@Async
  public void start(long travisBuildId, Class<? extends JandyTaskExecutor> taskExecutorClass) {
    JandyTaskExecutor executor = applicationContext.getBean(taskExecutorClass);

    File parent = new File("/tmp/"+env.getProperty("spring.application.name", "jandy")),
      stored = new File(parent, "build-"+travisBuildId);

    parent.mkdirs();

    FileObjectQueue<JandyTask> q = null;
    try {
      q = new FileObjectQueue<>(stored, new SerializedConverter<>());

      queues.put(travisBuildId, q);

      ThreadLocal<Boolean> stop = new ThreadLocal<>();
      stop.set(false);
      while (!stop.get()) {
        JandyTask jandyTask = q.peek();

        if (jandyTask != null) {

          executor.execute(jandyTask, () -> stop.set(true));
//          switch (jandyTask.getType()) {
//            case JandyTask.UPDATE:
//              profService.doUpdateTreeNodes((List<TreeNode>) jandyTask.getData());
//              break;
//            case JandyTask.SAVE:
//              profService.doSaveProf((ProfilingContext) jandyTask.getData());
//              break;
//            case JandyTask.FINISH:
//              profService.doFinish((Long) jandyTask.getData());
//              stop = true;
//              break;
//            default:
//              throw new IllegalStateException();
//          }

          q.remove();
        } else {
          Thread.sleep(1);
        }
      }

    } catch (Exception e) {
      log.error(e.getMessage(), e);
    } finally {
      if (q != null)
        q.close();
      queues.remove(travisBuildId);
      FileUtils.deleteQuietly(stored);
    }
  }