Home » jakarta-jmeter-2.3.4_src » org.apache.jmeter.samplers » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *   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 java.rmi.RemoteException;
   22   import java.util.Iterator;
   23   import java.util.List;
   24   
   25   import org.apache.jmeter.engine.event.LoopIterationEvent;
   26   import org.apache.jmeter.testelement.TestListener;
   27   
   28   /**
   29    * Implementation of remote sampler listener, also supports TestListener
   30    */
   31   public class RemoteSampleListenerImpl extends java.rmi.server.UnicastRemoteObject 
   32       implements RemoteSampleListener, SampleListener, TestListener {
   33   
   34       private final TestListener testListener;
   35   
   36       private final SampleListener sampleListener;
   37   
   38       public RemoteSampleListenerImpl(Object listener) throws RemoteException {
   39           super();
   40           if (listener instanceof TestListener) {
   41               testListener = (TestListener) listener;
   42           } else {
   43               testListener = null;
   44           }
   45           if (listener instanceof SampleListener) {
   46               sampleListener = (SampleListener) listener;
   47           } else {
   48               sampleListener = null;
   49           }
   50       }
   51   
   52       public void testStarted() {
   53           if (testListener != null) {
   54               testListener.testStarted();
   55           }
   56       }
   57   
   58       public void testStarted(String host) {
   59           if (testListener != null) {
   60               testListener.testStarted(host);
   61           }
   62       }
   63   
   64       public void testEnded() {
   65           if (testListener != null) {
   66               testListener.testEnded();
   67           }
   68       }
   69   
   70       public void testEnded(String host) {
   71           if (testListener != null) {
   72               testListener.testEnded(host);
   73           }
   74       }
   75   
   76       public void testIterationStart(LoopIterationEvent event) {
   77           if (testListener != null) {
   78               testListener.testIterationStart(event);
   79           }
   80       }
   81   
   82       /**
   83        * This method is called remotely and fires a list of samples events
   84        * received locally. The function is to reduce network load when using
   85        * remote testing.
   86        *
   87        * @param samples
   88        *            the list of sample events to be fired locally
   89        */
   90       public void processBatch(List samples) {
   91           if (samples != null) {
   92               Iterator iter = samples.iterator();
   93               while (iter.hasNext()) {
   94                   SampleEvent e = (SampleEvent) iter.next();
   95                   sampleOccurred(e);
   96               }
   97           }
   98       }
   99   
  100       public void sampleOccurred(SampleEvent e) {
  101           if (sampleListener != null) {
  102               sampleListener.sampleOccurred(e);
  103           }
  104       }
  105   
  106       /**
  107        * A sample has started.
  108        */
  109       public void sampleStarted(SampleEvent e) {
  110           if (sampleListener != null) {
  111               sampleListener.sampleStarted(e);
  112           }
  113       }
  114   
  115       /**
  116        * A sample has stopped.
  117        */
  118       public void sampleStopped(SampleEvent e) {
  119           if (sampleListener != null) {
  120               sampleListener.sampleStopped(e);
  121           }
  122       }
  123   }

Home » jakarta-jmeter-2.3.4_src » org.apache.jmeter.samplers » [javadoc | source]