Define custom Java services
Before you can create a custom Java service, ensure that your system meets the following prerequisites:
- DESK version 1.144
- OneAgent version 1.133
How to define a custom Java service
Consider creating a custom service that is based on a particular incarnation of a component. In this example, we have created a sample service called Booking for the EasyTravel application:
-
Select all the methods that you want to monitor. These methods must exist across all components. As long as the same method signature exists across all classes, you can use the base class or an interface to select these methods.
-
Go to Settings > Server-side service monitoring > Custom service detection.
-
Under the Java services tab, click Define Java services.
- The Monitor all subclasses of the specified class section displays the class that defines the class search scope.
- The Annotation filter section displays the annotations that are used to match the specific implementations of the class that you are interested in.
-
Click the Edit scope button to view the processes that are available in the process group.
-
Select the process that contains the desired entry point.
-
To view all the annotations that exist in that class, click Continue.
-
Select one or more of the annotations provided by your custom service classes.
-
To widen the class match, select an interface or superclass as the basis for the match.
-
To load the inheritance of superclasses, click the Load inheritance button and expand the list of annotations.
The custom service monitors the getId
method in all implementations of com.desk.easytravel.jpa.Base
that have the javax.persistence.Entity
annotation.
The resulting request list for the new custom service looks like the following screen:
Therefore, instead of just looking for one specific implementation (the Booking class) or all implementations of the base class, you can just tell DESK to monitor all implementations of an interface or base class that feature defined annotations. This makes it possible to use Spring controllers and similar concepts to define custom services.
Indirect matching in all superclasses
This feature looks for the specified annotations in all superclasses and interfaces. This makes indirect matching possible, where the annotation is on a base class not directly related to the interface match.
As an example, look at the following class hierarchy:
code block public interface component { boolean executeService(); } @MyComponent public abstract class BaseServiceA { } public class MyServiceA extends BaseServiceA implements Component { }
While you can easily define a custom service based on the Component interface method executeService
, you may want only those implementations that have the MyComponent
annotation. To do this:
- Define the custom service for
MyServiceA
. Here,MyServiceA
acts as a template. - Edit the scope to use the
Component
interface and theMyComponent
annotation.
Annotation matches by application
A number of frameworks rely solely on annotations. In such cases, you may not always be able to define an interface or base class. To handle such scenarios, DESK gives you the ability to monitor all classes that match the annotation filter in a certain package.
The Edit scope page offers an additional option for this express purpose: Use all classes and interfaces with selected annotations and names starting with... This option is greyed out until you select an annotation.
Once you select an annotation, you can select the Use all classes and interfaces... option and specify a package match instead of an interface. DESK then looks for any class that starts with the given string which has the selected annotations within itself or any of its superclasses and interfaces.
The result looks like the following screen:
With this option, you can also perform the following actions:
- You can instrument your own Enterprise Java Beans (EJBs) using EJB annotation and your package.
- You can instrument your own Spring controllers by using the Spring controller annotation and your package.