Skip to content

ClickerMonkey/Surfice

Repository files navigation

surfice

Stable

A Java library centered around the concept of a Service, which is a glorified thread that continually loops performing some job and handling events sent to the Service.

Features

  • Services can be started, paused, resumed, and stopped whenever. This is entirely thread-safe.
  • A service can be interrupted in several fashions, it can be paused/stopped immediately, after it's done executing the current task, after it's done handling events, or after the service is done entirely.
  • A service can have multiple listeners that are notified when it receives an event, it has just executed it's main piece of code, it has started, it has been paused, it was resumed, and it has stopped.

Documentation

Example

// A service which receives string events and echoes them.
public class EchoService extends AbstractService<String> 
{
    protected void onStart() {
        System.out.println("Service started");
    }
    protected void onEvent(String event) {
        // This occurs in the context of the service, not the thread that added the event.
        System.out.println(event);
    }
    protected void onExecute() {
        System.out.println("Service execute");
    }
    protected void onPause() {
        System.out.println("Service paused");
    }
    protected void onResume() {
        System.out.println("Service resumed");
    }
    protected void onStop() {
        System.out.println("Service stopped");
    }
}

// Create the service
EchoService service = new EchoService();
// Restrict the number of events it can process before it automatically stops.
service.setRemainingEvents(5);

// Start the service and add the event
service.start();
service.addEvent("Hello World");
// Request the service to pause and wait until it has paused
service.pause();
// Finally resume the service once it has paused.
service.resume();
// Stop the service now.
service.stop();

// Restart the service and stop it again.
service.start();
service.stop();

Builds

Projects using surfice:

Dependencies

Testing Examples

About

A Java library centered around the concept of a Service, which is a glorified thread that continually loops performing some job and handling events sent to the Service.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages