1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.jms;
17
18 import javax.jms.MessageListener;
19
20 import org.apache.commons.jelly.JellyTagException;
21 import org.apache.commons.jelly.XMLOutput;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25
26 import org.apache.commons.messenger.tool.StopWatchMessageListener;
27
28 /***
29 * This tag can be used to measure the amount of time it takes to process JMS messages.
30 * This tag can be wrapped around any custom JMS tag which consumes JMS messages.
31 *
32 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
33 * @version $Revision: 155420 $
34 */
35 public class StopwatchTag extends MessageOperationTag implements ConsumerTag {
36
37 /*** the underlying MessageListener */
38 private MessageListener messageListener;
39
40 /*** The Log to which logging calls will be made. */
41 private Log log = LogFactory.getLog( StopwatchTag.class );
42
43 /*** the message group size */
44 private int groupSize = 1000;
45
46 public StopwatchTag() {
47 }
48
49
50
51 public void doTag(XMLOutput output) throws JellyTagException {
52
53
54 invokeBody(output);
55
56 MessageListener listener = getMessageListener();
57
58 ConsumerTag tag = (ConsumerTag) findAncestorWithClass(ConsumerTag.class);
59 if (tag == null) {
60 throw new JellyTagException("This tag must be nested within a ConsumerTag like the subscribe tag");
61 }
62
63
64 setMessageListener(null);
65
66 StopWatchMessageListener stopWatch = new StopWatchMessageListener(listener);
67 stopWatch.setGroupSize(groupSize);
68 stopWatch.setLog(log);
69
70
71 tag.setMessageListener(stopWatch);
72 }
73
74
75
76
77 /***
78 * @return the number of messages in the group before the performance statistics are logged
79 */
80 public int getGroupSize() {
81 return groupSize;
82 }
83
84 /***
85 * Sets the number of messages in the group before the performance statistics are logged
86 */
87 public void setGroupSize(int groupSize) {
88 this.groupSize = groupSize;
89 }
90
91
92 /***
93 * @return the logger to which statistic messages will be sent
94 */
95 public Log getLog() {
96 return log;
97 }
98
99 /***
100 * Sets the logger to which statistic messages will be sent
101 */
102 public void setLog(Log log) {
103 this.log = log;
104 }
105
106 /***
107 * @return the MessageListener which this listener delegates to
108 */
109 public MessageListener getMessageListener() {
110 return messageListener;
111 }
112
113 /***
114 * Sets the JMS messageListener used to consume JMS messages on the given destination
115 */
116 public void setMessageListener(MessageListener messageListener) {
117 this.messageListener = messageListener;
118 }
119
120 }