View Javadoc

1   /*
2    * Jour - java profiler and monitoring library
3    *
4    * Copyright (C) 2004 Jour team
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Library General Public
8    * License as published by the Free Software Foundation; either
9    * version 2 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Library General Public License for more details.
15   *
16   * You should have received a copy of the GNU Library General Public
17   * License along with this library; if not, write to the
18   * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19   * Boston, MA  02111-1307, USA.
20   */
21  package net.sf.jour.rt.agent;
22  
23  /***
24   * TODO Add docs
25   * Created on 02.12.2004
26   *
27   * Contributing Author(s):
28   *
29   *   Misha Lifschitz <mishalifschitz at users.sourceforge.net> (Inital implementation)
30   *   Vlad Skarzhevskyy <vlads at users.sourceforge.net> (Inital implementation)
31   *
32   * @author vlads
33   * @version $Revision: 1.5 $ ($Author: vlads $) $Date: 2004/12/12 01:51:24 $
34   */
35  public class MapedEventID implements EventIdentifier {
36  
37  	/***
38  	 * Stable <code>serialVersionUID</code>.
39  	 */
40  	private static final long serialVersionUID = 39132123L;
41  	
42  	public static final int ID_DISPATCH_QUEUE = -1;
43  	
44      long id;
45  
46      final static int INIT = 0;
47      final static int METHOD = 1;
48      final static int FINALIZE = 2;
49  
50      int methodType;
51      transient private String methodName;
52      transient private String className;
53  	transient private String methodSignature;
54  
55  	private MapedEventID() {
56  		this.id = 0;
57  		this.methodType = METHOD;
58  	}
59  	
60      public MapedEventID(long id) {
61          this.id = id;
62          this.methodType = METHOD;
63      }
64  
65      public MapedEventID(long id, int methodType) {
66          this.id = id;
67          this.methodType = methodType;
68      }
69  
70      public MapedEventID(String className, String methodName, String methodSignature) {
71          this.id = InstrumentationMap.instance().getID(className, methodName, methodSignature);
72          this.methodName = methodName;
73          this.className = className;
74          this.methodSignature = methodSignature;
75      }
76  
77      public boolean isConstruction() {
78          return (this.methodType == INIT);
79      }
80  
81      public boolean isDeletion() {
82          return (this.methodType == FINALIZE);
83      }
84  
85      /* (non-Javadoc)
86       * @see com.amdocs.csc.vspoc.jour.rt.agent.EventIdentifier#equals(com.amdocs.csc.vspoc.jour.rt.agent.EventIdentifier)
87       */
88      public boolean equals(EventIdentifier obj) {
89          if (!(obj instanceof  MapedEventID)) {
90              return false;
91          }
92          return (this.id == ((MapedEventID)obj).id);
93      }
94  
95      private void unMap() {
96          if (this.id <= 0) {
97              // Internal Jour events
98              switch ((int)this.id) {
99              	case ID_DISPATCH_QUEUE:
100             	    this.methodName = "dispatchQueue";
101                     this.methodSignature = "";
102                     this.className = "jour";
103             	    break;
104             }
105             return;
106         }
107         
108         String name = InstrumentationMap.instance().getName(this.id);
109         int idx = name.indexOf(InstrumentationMap.separator);
110         if (idx >= 0) {
111             this.className = name.substring(0, idx);
112             String s = name.substring(idx + 1);
113 			int idx2 = s.indexOf(InstrumentationMap.separator);
114             this.methodName = s.substring(0, idx2);
115 			this.methodSignature = s.substring(idx2 + 1);
116         } else {
117             this.methodName = name;
118             this.methodSignature = "";
119             this.className = "n/a";
120         }
121     }
122 
123     public long getID() {
124         return this.id;
125     }
126 	
127 	public Object getKey() {
128 		return new Long(this.id);	
129 	}
130 	
131     /* (non-Javadoc)
132      * @see com.amdocs.csc.vspoc.jour.rt.agent.EventIdentifier#getClassName()
133      */
134     public String getClassName() {
135         if (this.className == null) {
136             unMap();
137         }
138         return this.className;
139     }
140 
141     /* (non-Javadoc)
142      * @see com.amdocs.csc.vspoc.jour.rt.agent.EventIdentifier#getMethodName()
143      */
144     public String getMethodName() {
145         if (this.methodName == null) {
146             unMap();
147         }
148         return this.methodName;
149     }
150 
151 	public String getMethodSignature() {
152 		if (this.methodSignature == null) {
153 			unMap();
154 		}
155 		return this.methodSignature;		
156 	}
157 }