We used cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it. What For?

« Back to Blogs

SystemCheckers in Liferay 7.2/DXP

Introduction

Liferay 7.2 introduces so many new features compared to older version. In this blog I’ll show you one of the Liferay 7.2 feature called SystemCheckers. In older versions of liferay sometimes we faced an issue is that when an environment started, they might have a false impression that everything was fine because there were no errors generated into the logs. But still we are not able to use some of the services or modules. For example we might have DS services in our Component classes which didn't start because they have an unsatisfied reference or circular references.

To overcome this issue Liferay introduce new feature in 7.2 version which is SystemCheckers. SystemCheckers helps us to verify that whether an environment is in proper working order or not. The SystemCheckers gives info that would be useful in diagnosing and resolving a potential problem like BSN, component names, bundle version, etc.SystemCheckers will report commonly considered issues, but if we want to diagnose some custom issues then we can also achieve that by implementing SystemChecker interface.

In this blog I’ll show how you can add your custom logic which will run during SystemCheckers.

Step 1: Implement SystemChecker interface in your custom class
@Component(
	immediate = true, 
	service = SystemChecker.class
)
public class CustomSystemChecker implements SystemChecker {
}
Step 2: Override Unimplemented Method of SystemChecker
@Override
public String check() {
	return "Hello World"; // Return result of your custom logic
}

@Override
public String getName() {
	return "Hello World Checker"; // Name of your custom System Checker
}

@Override
public String getOSGiCommand() {
	return "osgi:helloworld"; // Name of your custom osgi command
}

@Override
public String toString() {
	return getName();
}

 

That’s it using the above code you can implement your custom system checker which will run when you type “system:check” command in your gogo shell.

Note: Above implementation will be executed along with LR’s default System Checker implementation. If you want to check your custom logic then you can create your own custom osgi command. Here I’ll also show you how you can create your own osgi command which you can directly execute in gogo shell.

@Component(
	immediate = true,
	property = {"osgi.command.function=helloworld", "osgi.command.scope=osgi"},
	service = CustomOSGiCommands.class
)
public class CustomOSGiCommands {
	
	public void helloworld() {
		System.out.println("Hello World");
	}
}

 

By using above code when you execute “osgi:helloworld” command in gogo shell, it will run helloworld method and return appropriate output.

Hope this will help to kick start in implementing your custom SystemCheker !!!

contact-us Request a callback WhatsApp