Writing Services

Subscribe here to follow Infinitic's development. Please ⭐️ us on Github!

A service is a Java/Kotlin class that:

  • must extend io.infinitic.tasks.Task abstract class
  • must have an empty constructor
  • have serializable methods parameters and return value
  • must be thread-safe

Besides that, it can contain arbitrary code. The Task abstract class is very simple, it contains only:

  • a context variable (maintained by Infinitic),
  • a getDurationBeforeRetry method, we can override to describe how the task will react in case of failure

The other constraints are implied by the execution process: when receiving instructions to run a task, a task worker uses the empty constructor to instantiate the class, deserializes the parameters, executes the requested method and returns the serialized result. The class must be thread-safe to be run in parallel if we chose to.

Here is an example of task implementation, from our Hello World app:

import io.infinitic.tasks.Task;

public class HelloWorldServiceImpl extends Task implements HelloWorldService {
    public String sayHello(String name) {

        return "Hello " + ((name == null) ? "World" : name);

    public String addEnthusiasm(String str) {

        return str + "!";
import io.infinitic.tasks.Task

class HelloWorldServiceImpl: Task(), HelloWorldService {
    override fun sayHello(name: String) = "Hello $name"

    override fun addEnthusiasm(str: String) = "$str!"
Edit this page on GitHub Updated at Sat, Sep 10, 2022