1 package org.e2etrace.trace; 2 3 /* 4 * Copyright 2006 Gunther Popp 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 /** 20 * Root trace step for {@link org.e2etrace.trace.ITraceSession}. 21 * <p> 22 * 23 * Each trace session contains one implicit trace step that serves as root of 24 * the tree of "real" trace steps. The duration of this trace step is by 25 * definition the accumulated duration of all children. In additon, the isolated 26 * duration of this step is by definion 0ms. 27 * <p> 28 * 29 * In practice, an instance of the root step represents a complete service 30 * call. The children of the root step are the single execution steps of the 31 * service. 32 * <p> 33 * 34 * A root step can savely be added as child to any other trace step (e.g. if a 35 * client invokes a remote service, the root step of the service can be added 36 * to any trace step of the client). However, if a client spawns multiple services 37 * asynchronously and waits until all of them return, the isolated duration of 38 * the client step will return a meaningless value (since the overall processing 39 * time of the parallel services exceeds the execution time of the client step).<p> 40 * 41 * This class is only instantiated by implementations of 42 * {@link org.e2etrace.trace.ITraceSession} 43 * 44 * @author Gunther Popp 45 * 46 */ 47 public class TraceSessionRootStep extends AbstractTraceStep { 48 49 private static final long serialVersionUID = 1L; 50 51 /** 52 * Constructor. 53 * 54 * @param id ID of the root step 55 */ 56 public TraceSessionRootStep(TraceSessionRootStepId id) { 57 super(id); 58 } 59 60 /** 61 * Returns the overall duration of this TraceStep and all children. 62 * <p> 63 * 64 * @return duration in ms 65 */ 66 public long getDuration() { 67 long duration; 68 ITraceStep[] children; 69 70 // Sum up the durations of all direct children of the root 71 // step 72 children = this.getChildren(); 73 duration = 0; 74 for (int i = 0; i < children.length; i++) { 75 duration += children[i].getDuration(); 76 } 77 78 return duration; 79 } 80 81 /** 82 * The isolated duration of the root step is by definition 0ms. 83 * 84 * @return duration of this TraceStep in ms (-1:<code>leave</code> has not 85 * been called yet) 86 */ 87 public long getIsolatedDuration() { 88 return 0; 89 } 90 91 /** {@inheritDoc} */ 92 public void enter() throws IllegalStateException { 93 // This method is intentionally left blank 94 95 } 96 97 /** 98 * Checks, if the current trace step is active. 99 * <p> 100 * 101 * The session root step is always active by definition. 102 * <p> 103 * 104 * @return true 105 */ 106 public boolean isActive() { 107 return true; 108 } 109 110 /** {@inheritDoc} */ 111 public void leave() throws IllegalStateException { 112 // Forward the call to all children 113 leaveAllChildren(); 114 115 } 116 117 }