Java command annotations are used for the developing Java commands in PAK.
This chapter describes the functionality of the @LiteService
annotation.
It also gives an example of how you can use this annotation in your implementation.
1. Basics
The @LiteService
annotation basically works like @Service
. A LiteService is basically a class,
which implements the marker-interface ILiteService
. The respective class is
mostly located in the same java module like the command itself. Also, its registered as a Java Service, using java.util.ServiceLoader
.
It was introduced to differentiate between a normal Service- and a LiteService-injection. If the usage of @Service
is not wanted, or simply too expensive, an ILiteService
can be injected, using @LiteService
, which provides the option of creating utility-Services.
2. Usage
Like previously mentioned, Services must extend or implement ILiteService
in order to be annotated by @LiteService
.
This class should then operate as a Service within the Command.
Listing 1 shows how to use the @LiteService
annotation.
@LiteService
/**
* @workflowDocu This is a sample-command
*/
@JavaCommand
@CommandGroup("Generic.Sample")
public class SampleCommand {
/**
* @workflowDocu ICommandRestService injected as a LiteService in order to provide the functionality to
* conduct simple rest-calls
*/
@LiteService (1)
private ICommandRestService restService;
/**
* @workflowDocu Store response in this map
*/
@Persistent(scope = FieldScope.WRITE_ONLY)
private Map<String, Object> responseMap;
@Run
public void run() {
final IEndpointClientService endpointClientService = this.restService.createEndpointClientServiceFor("myRequesterId"); (2)
endpointClientService.register(JacksonFeature.class);
final Response response = endpointClientService.getBaseTarget().path("/service/rest/v1/tasks").request().get(); (3)
this.responseMap = response.readEntity(new GenericType<>() {
}); (4)
}
}
1 | Use of @LiteService , to inject an implementation of ILiteService . |
2 | Create an IEndpointClientService , using ICommandRestService , by passing specific requesterId. |
3 | Fetch response from IEndpointClientService . |
4 | Save response as map. |