All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.transferwise.tasks.handler.TaskHandlerAdapter Maven / Gradle / Ivy

There is a newer version: 1.43.0
Show newest version
package com.transferwise.tasks.handler;

import com.transferwise.tasks.domain.IBaseTask;
import com.transferwise.tasks.handler.interfaces.ITaskConcurrencyPolicy;
import com.transferwise.tasks.handler.interfaces.ITaskHandler;
import com.transferwise.tasks.handler.interfaces.ITaskProcessingPolicy;
import com.transferwise.tasks.handler.interfaces.ITaskProcessor;
import com.transferwise.tasks.handler.interfaces.ITaskRetryPolicy;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.function.Predicate;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

@Getter
@Setter
@Accessors(chain = true)
public class TaskHandlerAdapter implements ITaskHandler {

  private ITaskProcessor processor;
  private ITaskRetryPolicy retryPolicy;
  private ITaskConcurrencyPolicy concurrencyPolicy;
  private ITaskProcessingPolicy processingPolicy;

  private Predicate handlesPredicate;

  public TaskHandlerAdapter() {
  }

  public TaskHandlerAdapter(Predicate handlesPredicate, ITaskProcessor processor) {
    this.handlesPredicate = handlesPredicate;
    this.processor = processor;
    this.retryPolicy = new NoRetryPolicy();
    this.concurrencyPolicy = new SimpleTaskConcurrencyPolicy(1);
    this.processingPolicy = new SimpleTaskProcessingPolicy().setMaxProcessingDuration(Duration.of(1, ChronoUnit.HOURS));
  }

  @Override
  public ITaskProcessor getProcessor(IBaseTask task) {
    return processor;
  }

  @Override
  public ITaskRetryPolicy getRetryPolicy(IBaseTask task) {
    return retryPolicy;
  }

  @Override
  public ITaskConcurrencyPolicy getConcurrencyPolicy(IBaseTask task) {
    return concurrencyPolicy;
  }

  @Override
  public ITaskProcessingPolicy getProcessingPolicy(IBaseTask task) {
    return processingPolicy;
  }

  @Override
  public boolean handles(IBaseTask task) {
    return handlesPredicate.test(task);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy