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.rmi.RemoteException;
022: import java.util.Iterator;
023: import java.util.List;
024:
025: import org.apache.jmeter.engine.event.LoopIterationEvent;
026: import org.apache.jmeter.testelement.TestListener;
027:
028: /**
029: * @version $Revision: 493779 $
030: */
031: public class RemoteSampleListenerImpl extends
032: java.rmi.server.UnicastRemoteObject implements
033: RemoteSampleListener, SampleListener, TestListener {
034: TestListener testListener;
035:
036: SampleListener sampleListener;
037:
038: public RemoteSampleListenerImpl() throws RemoteException {
039: super ();
040: }
041:
042: public void setListener(Object listener) {
043: if (listener instanceof TestListener) {
044: testListener = (TestListener) listener;
045: }
046: if (listener instanceof SampleListener) {
047: sampleListener = (SampleListener) listener;
048: }
049: }
050:
051: public RemoteSampleListenerImpl(Object listener)
052: throws RemoteException {
053: super ();
054: setListener(listener);
055: }
056:
057: public void testStarted() {
058: if (testListener != null) {
059: testListener.testStarted();
060: }
061: }
062:
063: public void testStarted(String host) {
064: if (testListener != null) {
065: testListener.testStarted(host);
066: }
067: }
068:
069: public void testEnded() {
070: if (testListener != null) {
071: testListener.testEnded();
072: }
073: }
074:
075: public void testEnded(String host) {
076: if (testListener != null) {
077: testListener.testEnded(host);
078: }
079: }
080:
081: /**
082: * This method is called remotely and fires a list of samples events
083: * recieved locally. The function is to reduce network load when using
084: * remote testing.
085: *
086: * @param samples
087: * the list of sample events to be fired locally
088: */
089: public void processBatch(List samples) {
090: if (samples != null) {
091: Iterator iter = samples.iterator();
092: while (iter.hasNext()) {
093: SampleEvent e = (SampleEvent) iter.next();
094: sampleOccurred(e);
095: }
096: }
097: }
098:
099: public void sampleOccurred(SampleEvent e) {
100: if (sampleListener != null) {
101: sampleListener.sampleOccurred(e);
102: }
103: }
104:
105: /**
106: * A sample has started.
107: */
108: public void sampleStarted(SampleEvent e) {
109: if (sampleListener != null) {
110: sampleListener.sampleStarted(e);
111: }
112: }
113:
114: /**
115: * A sample has stopped.
116: */
117: public void sampleStopped(SampleEvent e) {
118: if (sampleListener != null) {
119: sampleListener.sampleStopped(e);
120: }
121: }
122:
123: /*
124: * (non-Javadoc)
125: *
126: * @see TestListener#testIterationStart(LoopIterationEvent)
127: */
128: public void testIterationStart(LoopIterationEvent event) {
129: }
130: }
|