001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.aspects.asynchronous.aspects.jboss;
023:
024: import org.apache.commons.logging.Log;
025: import org.apache.commons.logging.LogFactory;
026: import org.jboss.aop.joinpoint.MethodInvocation;
027:
028: import java.text.SimpleDateFormat;
029: import java.util.Date;
030:
031: /**
032: * @author <a href="mailto:chussenet@yahoo.com">{Claude Hussenet Independent Consultant}</a>.
033: * @version <tt>$Revision: 57186 $</tt>
034: */
035:
036: public class TraceThreadAspect {
037:
038: static private final Log log = LogFactory
039: .getLog(TraceThreadAspect.class);
040:
041: static private SimpleDateFormat formatter =
042:
043: new SimpleDateFormat("hh:mm:ss:SSS aaa z");
044:
045: public TraceThreadAspect() {
046: }
047:
048: public Object trace(MethodInvocation methodInvocation)
049: throws Throwable {
050:
051: String className = null;
052:
053: if (methodInvocation.getTargetObject() != null)
054:
055: className = methodInvocation.getTargetObject().getClass()
056: .getName();
057:
058: else
059:
060: className = methodInvocation.getMethod()
061: .getDeclaringClass().getName();
062:
063: StringBuffer txt =
064:
065: new StringBuffer(Thread.currentThread().toString())
066:
067: .append(" ")
068:
069: .append(methodInvocation.getMethod().getReturnType().getName())
070:
071: .append(" ")
072:
073: .append(className)
074:
075: .append(".")
076:
077: .append(methodInvocation.getMethod().getName())
078:
079: .append("(");
080:
081: Class[] parameterTypes =
082:
083: methodInvocation.getActualMethod().getParameterTypes();
084:
085: for (int i = 0; i < parameterTypes.length; i++) {
086:
087: txt.append(parameterTypes[i].getName());
088:
089: if (i + 1 < parameterTypes.length)
090:
091: txt.append(",");
092:
093: }
094:
095: txt.append(")");
096:
097: log.info(new StringBuffer("TRACE ENTER: ").append(
098: getCurrentDate()).append(" ").append(txt));
099:
100: Object rsp = methodInvocation.invokeNext();
101:
102: log.info(new StringBuffer("TRACE EXIT: ").append(
103: getCurrentDate()).append(" ").append(txt));
104:
105: return rsp;
106:
107: }
108:
109: static public String getCurrentDate() {
110:
111: return formatter.format(new Date(System.currentTimeMillis()));
112:
113: }
114:
115: }
|