Examples of Using Method Tracking

For method tracking to be enabled, the following entry is made in the JADE initialization file used by the database server.

[JadeSecurity]
MethodTrackingEnabled = true

The following example initiates method tracking for a method defined on the Customer class, where the preamble and postamble methods are defined on the Process class in the same schema as the tracked method.

startTracking(targetProcess : Process);
vars
begin
   targetProcess.startMethodTracking(Customer::getAddress,// tracked method
                                     Process::beforeCall, // preamble method
                                     Process::afterCall,  // postamble method
                                     targetProcess);      // receiver
end;

In the following example, method tracking is initiated for a method defined in a different schema from where the preamble and postamble methods are defined. The Tracker class is defined within the user schema and the tracker parameter is a persistent instance of the Tracker class.

initiateTracking(targetProcess: Process, tracker: Tracker);
vars
   scm : Schema;
   cls : Class;
   mth : Method;
begin
   scm := rootSchema.getSchema("AcctSchema");
   cls := scm.getClass("Customer");
   mth := mth.getMethod("getAddress");
   targetProcess.startMethodTracking(mth,                 // tracked method
                                     Tracker::beforeCall, // preamble method
                                     Tracker::afterCall,  // postamble method
                                     tracker);            // receiver
end;

Define the preamble and postamble methods in the Tracker class. The afterCall postamble method in the following example uses simple write instructions to provide tracking information.

afterCall(paramList: ParamListType);
vars
   status : Integer;
   num, i : Integer;
begin
   // Status information - Is this the preamble or postamble?
   //                      Or has there been an exception?
   status := process.getTrackedMethodStatus;
   if status = 0 then write "no tracked method";
   elseif status = 1 then write "in preamble method";
   elseif status = 2 then write "in postamble method";
   elseif status = 3 then write "exception occurred";
   endif;
   // Tracked method
   write "tracked method: " & process.getTrackedMethod.name;
   // Receiver
   write "receiver: " & process.getTrackedMethodReceiver.String;
   // Parameters
   num := app.getParamListTypeLength(paramList);
   foreach i in 1 to num do
      write "parameter " & i.String & ": "
            & app.getParamListTypeEntry(i, paramList).String;
   endforeach;
   // Return value
   write "return value: " & process.getTrackedMethodReturnValue.String;
end;