001 package org.shiftone.jrat.provider.tree; 002 003 004 import org.shiftone.jrat.core.MethodKey; 005 006 007 /** 008 * This is basically a thread specific MethodHandler. The typical JRat model is 009 * to have a seperate handler for each method. This is also true for the 010 * TreeMethodHandler, however that handler delegates to an instance of this 011 * class, passing it the method key with each invocation. One instance of this 012 * class will exist for each thread that is creating JRat events. This class 013 * manipulates a tree structure as invocations are made. 014 * 015 * @author jeff@shiftone.org (Jeff Drost) 016 */ 017 public class Delegate { 018 019 private TreeNode currentNode = null; 020 021 public Delegate(TreeNode rootNode) { 022 023 if (rootNode == null) { 024 throw new NullPointerException("delegate created to null initial node"); 025 } 026 027 currentNode = rootNode; 028 } 029 030 031 public final void onMethodStart(MethodKey methodKey) { 032 033 currentNode = currentNode.getChild(methodKey); 034 035 currentNode.getAccumulator().onMethodStart(); 036 } 037 038 039 public final void onMethodFinish(MethodKey methodKey, long duration, boolean success) { 040 041 currentNode.getAccumulator().onMethodFinish(duration, success); 042 043 currentNode = currentNode.getParentNode(); 044 } 045 }