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 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.getLoggerForClass();
   36   
   37       private List sampleStore = new ArrayList();
   38   
   39       private RemoteSampleListener listener;
   40   
   41       public HoldSampleSender(){
   42           log.warn("Constructor only intended for use in testing"); // $NON-NLS-1$
   43       }
   44   
   45       HoldSampleSender(RemoteSampleListener listener) {
   46           log.info("Using Sample store for this test run");
   47           this.listener = listener;
   48       }
   49   
   50       public void testEnded() {
   51           log.info("Test ended()");
   52           try {
   53               synchronized (sampleStore) {
   54                   Iterator i = sampleStore.iterator();
   55                   while (i.hasNext()) {
   56                       SampleEvent se = (SampleEvent) i.next();
   57                       listener.sampleOccurred(se);
   58                   }
   59               }
   60               listener.testEnded();
   61               sampleStore = null;
   62           } catch (Throwable ex) {
   63               log.warn("testEnded()", ex);
   64           }
   65   
   66       }
   67   
   68       public void testEnded(String host) {
   69           log.info("Test Ended on " + host); // should this be debug?
   70           try {
   71               Iterator i = sampleStore.iterator();
   72               while (i.hasNext()) {
   73                   SampleEvent se = (SampleEvent) i.next();
   74                   listener.sampleOccurred(se);
   75               }
   76               listener.testEnded(host);
   77               sampleStore = null;
   78           } catch (Throwable ex) {
   79               log.error("testEnded(host)", ex);
   80           }
   81   
   82       }
   83   
   84       public void sampleOccurred(SampleEvent e) {
   85           log.debug("Sample occurred");
   86           synchronized (sampleStore) {
   87               sampleStore.add(e);
   88           }
   89       }
   90   }

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