01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.jmeter.samplers;
20:
21: import org.apache.log.Logger;
22: import org.apache.jorphan.logging.LoggingManager;
23:
24: import java.util.Iterator;
25: import java.util.List;
26: import java.util.ArrayList;
27: import java.io.Serializable;
28:
29: /**
30: * Lars-Erik Helander provided the idea (and original implementation) for the
31: * caching functionality (sampleStore).
32: */
33:
34: public class HoldSampleSender implements SampleSender, Serializable {
35: private static final Logger log = LoggingManager
36: .getLoggerForClass();
37:
38: private List sampleStore = new ArrayList();
39:
40: private RemoteSampleListener listener;
41:
42: public HoldSampleSender() {
43: log.warn("Constructor only intended for use in testing"); // $NON-NLS-1$
44: }
45:
46: HoldSampleSender(RemoteSampleListener listener) {
47: log.info("Using Sample store for this test run");
48: this .listener = listener;
49: }
50:
51: public void testEnded() {
52: log.info("Test ended()");
53: try {
54: synchronized (sampleStore) {
55: Iterator i = sampleStore.iterator();
56: while (i.hasNext()) {
57: SampleEvent se = (SampleEvent) i.next();
58: listener.sampleOccurred(se);
59: }
60: }
61: listener.testEnded();
62: sampleStore = null;
63: } catch (Throwable ex) {
64: log.warn("testEnded()", ex);
65: }
66:
67: }
68:
69: public void testEnded(String host) {
70: log.info("Test Ended on " + host); // should this be debug?
71: try {
72: Iterator i = sampleStore.iterator();
73: while (i.hasNext()) {
74: SampleEvent se = (SampleEvent) i.next();
75: listener.sampleOccurred(se);
76: }
77: listener.testEnded(host);
78: sampleStore = null;
79: } catch (Throwable ex) {
80: log.error("testEnded(host)", ex);
81: }
82:
83: }
84:
85: public void SampleOccurred(SampleEvent e) {
86: log.debug("Sample occurred");
87: synchronized (sampleStore) {
88: sampleStore.add(e);
89: }
90: }
91: }
|