001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.samplers;
020:
021: import java.io.Serializable;
022: import java.rmi.RemoteException;
023:
024: import org.apache.jmeter.engine.event.LoopIterationEvent;
025: import org.apache.jmeter.engine.util.NoThreadClone;
026: import org.apache.jmeter.testelement.AbstractTestElement;
027: import org.apache.jmeter.testelement.TestListener;
028: import org.apache.jorphan.logging.LoggingManager;
029: import org.apache.log.Logger;
030:
031: /**
032: * @author unascribed
033: *
034: * Lars-Erik Helander provided the idea (and original implementation) for the
035: * caching functionality (sampleStore).
036: *
037: * @version $Revision: 493779 $ Updated on: $Date: 2007-01-07 17:46:38 +0000 (Sun, 07 Jan 2007) $
038: */
039: public class RemoteListenerWrapper extends AbstractTestElement
040: implements SampleListener, TestListener, Serializable,
041: NoThreadClone {
042: private static final Logger log = LoggingManager
043: .getLoggerForClass();
044:
045: private RemoteSampleListener listener = null;
046:
047: private SampleSender mode;
048:
049: public RemoteListenerWrapper(RemoteSampleListener l) {
050: listener = l;
051: // Get appropriate class governed by the behaviour set in the Jmeter
052: // property mode.
053: this .mode = SampleSenderFactory.getInstance(listener);
054: }
055:
056: public RemoteListenerWrapper() // TODO: not used - make private?
057: {
058: }
059:
060: public void testStarted() {
061: log.info("Test Started()");
062: try {
063: listener.testStarted();
064: } catch (Throwable ex) {
065: log.warn("testStarted()", ex);
066: }
067:
068: }
069:
070: public void testEnded() {
071: mode.testEnded();
072: }
073:
074: public void testStarted(String host) {
075: log.info("Test Started on " + host); // should this be debug?
076: try {
077: listener.testStarted(host);
078: } catch (Throwable ex) {
079: log.error("testStarted(host)", ex);
080: }
081: }
082:
083: public void testEnded(String host) {
084: mode.testEnded(host);
085: }
086:
087: public void sampleOccurred(SampleEvent e) {
088: mode.SampleOccurred(e);
089: }
090:
091: // Note that sampleStarted() and sampleStopped() is not made to appear
092: // in synch with sampleOccured() when replaying held samples.
093: // For now this is not critical since sampleStarted() and sampleStopped()
094: // is not used, but it may become an issue in the future. Then these
095: // events must also be stored so that replay of all events may occur and
096: // in the right order. Each stored event must then be tagged with something
097: // that lets you distinguish between occured, started and ended.
098:
099: public void sampleStarted(SampleEvent e) {
100: log.debug("Sample started");
101: try {
102: listener.sampleStarted(e);
103: } catch (RemoteException err) {
104: log.error("sampleStarted", err);
105: }
106: }
107:
108: public void sampleStopped(SampleEvent e) {
109: log.debug("Sample stopped");
110: try {
111: listener.sampleStopped(e);
112: } catch (RemoteException err) {
113: log.error("sampleStopped", err);
114: }
115: }
116:
117: /*
118: * (non-Javadoc)
119: *
120: * @see TestListener#testIterationStart(LoopIterationEvent)
121: */
122: public void testIterationStart(LoopIterationEvent event) {
123: }
124:
125: }
|