Add a QueryCommandParser

In this section, you will learn how to add or remove a query command parser at runtime using the SampleServiceImpl code.


The QueryParserService service supports adding or removing parsers through the two methods below.

  • addCommandParser(): Adds a new query command parser.
  • removeCommandParser(): Removes an existing query command parser.

Plugin in or out parsers

The SampleServiceImpl component is implemented to add all query command parsers to the QueryParserService on startup and remove all query commands from the QueryParserService on stop.

@Component(name = "sample-service")
public class SampleServiceImpl {

	private QueryParserService queryParserService;

	private ConnectProfileService connectProfileService;

	private SampleQueryCommandParser subnetGroupsParser = new SampleSubnetGroupsCommandParser();
	private SampleQueryCommandParser createSubnetGroupParser = new SampleCreateSubnetGroupCommandParser();

	public void start() {
		for (SampleQueryCommandParser parser : getParsers()) {

	public void stop() {
		if (queryParserService == null)

		for (SampleQueryCommandParser parser : getParsers()) {

	private List<SampleQueryCommandParser> getParsers() {
		return Arrays.asList(subnetGroupsParser, createSubnetGroupParser);

Note that because the SampleQueryCommandParser class inherits from ConnectProfileQueryCommandParser, you must set the ConnectProfileService object at the time of initializing each parser.

In the Logpresso shell, iterate through bundle.start and bundle.stop to see how the sample-subnet-groups query is executed. For example, if your com.logpresso.sonar.sample bundle is number 133, you can stop it as follows.

logpresso> bundle.stop 133
bundle 133 stopped.