%line | %branch | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
org.apache.commons.jelly.tags.jms.StopwatchTag |
|
|
1 | /* |
|
2 | * Copyright 2002,2004 The Apache Software Foundation. |
|
3 | * |
|
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
5 | * you may not use this file except in compliance with the License. |
|
6 | * You may obtain a copy of the License at |
|
7 | * |
|
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
9 | * |
|
10 | * Unless required by applicable law or agreed to in writing, software |
|
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
13 | * See the License for the specific language governing permissions and |
|
14 | * limitations under the License. |
|
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: 1.5 $ |
|
34 | */ |
|
35 | 0 | 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 | 0 | private Log log = LogFactory.getLog( StopwatchTag.class ); |
42 | ||
43 | /** the message group size */ |
|
44 | 0 | private int groupSize = 1000; |
45 | ||
46 | 0 | public StopwatchTag() { |
47 | 0 | } |
48 | ||
49 | // Tag interface |
|
50 | //------------------------------------------------------------------------- |
|
51 | public void doTag(XMLOutput output) throws JellyTagException { |
|
52 | ||
53 | // evaluate body as it may contain child tags to register a MessageListener |
|
54 | 0 | invokeBody(output); |
55 | ||
56 | 0 | MessageListener listener = getMessageListener(); |
57 | ||
58 | 0 | ConsumerTag tag = (ConsumerTag) findAncestorWithClass(ConsumerTag.class); |
59 | 0 | if (tag == null) { |
60 | 0 | throw new JellyTagException("This tag must be nested within a ConsumerTag like the subscribe tag"); |
61 | } |
|
62 | ||
63 | // clear the listener for the next tag invocation, if caching is employed |
|
64 | 0 | setMessageListener(null); |
65 | ||
66 | 0 | StopWatchMessageListener stopWatch = new StopWatchMessageListener(listener); |
67 | 0 | stopWatch.setGroupSize(groupSize); |
68 | 0 | stopWatch.setLog(log); |
69 | ||
70 | // perform the consumption |
|
71 | 0 | tag.setMessageListener(stopWatch); |
72 | 0 | } |
73 | ||
74 | // Properties |
|
75 | //------------------------------------------------------------------------- |
|
76 | ||
77 | /** |
|
78 | * @return the number of messages in the group before the performance statistics are logged |
|
79 | */ |
|
80 | public int getGroupSize() { |
|
81 | 0 | 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 | 0 | this.groupSize = groupSize; |
89 | 0 | } |
90 | ||
91 | ||
92 | /** |
|
93 | * @return the logger to which statistic messages will be sent |
|
94 | */ |
|
95 | public Log getLog() { |
|
96 | 0 | return log; |
97 | } |
|
98 | ||
99 | /** |
|
100 | * Sets the logger to which statistic messages will be sent |
|
101 | */ |
|
102 | public void setLog(Log log) { |
|
103 | 0 | this.log = log; |
104 | 0 | } |
105 | ||
106 | /** |
|
107 | * @return the MessageListener which this listener delegates to |
|
108 | */ |
|
109 | public MessageListener getMessageListener() { |
|
110 | 0 | 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 | 0 | this.messageListener = messageListener; |
118 | 0 | } |
119 | ||
120 | } |
This report is generated by jcoverage, Maven and Maven JCoverage Plugin. |