Satellite :: Plugins :: Runner

Provide a way to run a class that implements Satellite Daemon interface

License

License

MIT
Categories

Categories

Maven Build Tools
GroupId

GroupId

io.zatarox.satellite
ArtifactId

ArtifactId

satellite-maven-plugin
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

maven-plugin
Description

Description

Satellite :: Plugins :: Runner
Provide a way to run a class that implements Satellite Daemon interface

Download satellite-maven-plugin

How to add to project

<plugin>
    <groupId>io.zatarox.satellite</groupId>
    <artifactId>satellite-maven-plugin</artifactId>
    <version>1.0.0</version>
</plugin>

Dependencies

compile (3)

Group / Artifact Type Version
io.zatarox.satellite : satellite-impl jar 1.0.0
org.apache.maven : maven-core jar 3.3.9
org.apache.maven : maven-compat jar 3.3.9

provided (1)

Group / Artifact Type Version
org.apache.maven.plugin-tools : maven-plugin-annotations jar 3.5

test (4)

Group / Artifact Type Version
org.apache.maven.plugin-testing : maven-plugin-testing-harness jar 3.3.0
junit : junit jar 4.12
org.powermock : powermock-api-mockito jar 1.6.6
org.powermock : powermock-module-junit4 jar 1.6.6

Project Modules

There are no modules declared in this project.

Satellite Toolkit

Satellite is a set of utilities and Java support classes for running Java applications as server processes. Commonly known as 'daemon' processes in Unix terminology, on Windows they are called 'services'.

Build Status Coverage Status Maven Central

Requirements

Compilation process is performed under Linux. Cross-compilation fanboy :-)

  • Gradle 4.4.x
  • Java Development Kit >= 7
  • Clang 5.x
  • mingw-w64-x86-64-dev (gcc 5.x)
  • libc6-dev-i386

Satellite in action

Writing an independent OS background process become pretty simple. The first step is to implement a java interface who manage background process behaviors. The second step require Phobos or Deimos depending if you are under Windows or Linux. The Daemon behavior has been designed as the same manner as Windows service. Under Windows, only certain service state transitions are valid. The following diagram shows the valid transitions (credits to Microsoft) :

Dependency

In your project, add the Satellite API dependency (Maven POM):

<dependency>
    <groupId>io.zatarox.satellite</groupId>
    <artifactId>satellite-api</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <scope>provided</scope>
</dependency>

Core of the background process

This is the facade of your service. Attention : calls on these methods are synchronous.

import io.zatarox.satellite.*;

public final class FooBackgroundProcess implements BackgroundProcess {

    @Override
    public void initialize(BackgroundContext dc) throws BackgroundException, Exception {
        System.err.println("Initialized");
    }

    @Override
    public void resume() throws Exception {
        System.err.println("Started...");
    }

    @Override
    public void pause() throws Exception {
        System.err.println("Stopped !");
    }

    @Override
    public void shutdown() {
        System.err.println("Destroyed");
    }
}

Main jar assembly

Finally, add a manifest entry in your main jar (and dependency jars OFC).

<plugin>
  <artifactId>maven-jar-plugin</artifactId>
    <version>3.0.2</version>
        <configuration>
        <archive>
            <index>true</index>
            <manifestEntries>
                <Background-Process-Class>io.zatarox.satellite.FooBackgroundProcess</Background-Process-Class>
            </manifestEntries>
        </archive>
    </configuration>
</plugin>

Sample

To a look to the sample project submodule to see how to get binary frontends from Gradle

Inspiration

This project is based on Apache Commons Daemon.

Versions

Version
1.0.0