From commits-return-216-apmail-jmeter-commits-archive=jmeter.apache.org@jmeter.apache.org Thu Nov 24 21:18:49 2011 Return-Path: X-Original-To: apmail-jmeter-commits-archive@minotaur.apache.org Delivered-To: apmail-jmeter-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id ADBF293E6 for ; Thu, 24 Nov 2011 21:18:49 +0000 (UTC) Received: (qmail 90579 invoked by uid 500); 24 Nov 2011 21:18:49 -0000 Delivered-To: apmail-jmeter-commits-archive@jmeter.apache.org Received: (qmail 90560 invoked by uid 500); 24 Nov 2011 21:18:49 -0000 Mailing-List: contact commits-help@jmeter.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@jmeter.apache.org Delivered-To: mailing list commits@jmeter.apache.org Received: (qmail 90553 invoked by uid 99); 24 Nov 2011 21:18:49 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Nov 2011 21:18:49 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 24 Nov 2011 21:18:46 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id E44FB23888EA for ; Thu, 24 Nov 2011 21:18:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1205982 - in /jmeter/trunk/src/components/org/apache/jmeter/timers: SyncTimer.java SyncTimer.java.tmp Date: Thu, 24 Nov 2011 21:18:24 -0000 To: commits@jmeter.apache.org From: pmouawad@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111124211824.E44FB23888EA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: pmouawad Date: Thu Nov 24 21:18:24 2011 New Revision: 1205982 URL: http://svn.apache.org/viewvc?rev=1205982&view=rev Log: temporary move, restoring the history of SyncTimer Added: jmeter/trunk/src/components/org/apache/jmeter/timers/SyncTimer.java (with props) jmeter/trunk/src/components/org/apache/jmeter/timers/SyncTimer.java.tmp Added: jmeter/trunk/src/components/org/apache/jmeter/timers/SyncTimer.java URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/timers/SyncTimer.java?rev=1205982&view=auto ============================================================================== --- jmeter/trunk/src/components/org/apache/jmeter/timers/SyncTimer.java (added) +++ jmeter/trunk/src/components/org/apache/jmeter/timers/SyncTimer.java Thu Nov 24 21:18:24 2011 @@ -0,0 +1,153 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.jmeter.timers; + +import java.io.Serializable; +import java.util.concurrent.BrokenBarrierException; + +import org.apache.jmeter.engine.event.LoopIterationEvent; +import org.apache.jmeter.testbeans.TestBean; +import org.apache.jmeter.testelement.AbstractTestElement; +import org.apache.jmeter.testelement.TestListener; +import org.apache.jmeter.testelement.ThreadListener; +import org.apache.jmeter.threads.JMeterContextService; + +/** + * The purpose of the SyncTimer is to block threads until X number of threads + * have been blocked, and then they are all released at once. A SyncTimer can + * thus create large instant loads at various points of the test plan. + * + */ +public class SyncTimer extends AbstractTestElement implements Timer, Serializable, TestBean, TestListener, ThreadListener { + private static final long serialVersionUID = 2; + + private BarrierWrapper barrier; + + private int groupSize; + + // Ensure transient object is created by the server + private Object readResolve(){ + createBarrier(); + return this; + } + + /** + * @return Returns the numThreads. + */ + public int getGroupSize() { + return groupSize; + } + + /** + * @param numThreads + * The numThreads to set. + */ + public void setGroupSize(int numThreads) { + this.groupSize = numThreads; + } + + /** + * {@inheritDoc} + */ + public long delay() { + if(getGroupSize()>=0) { + int arrival = 0; + try { + arrival = this.barrier.await(); + } catch (InterruptedException e) { + return 0; + } catch (BrokenBarrierException e) { + return 0; + } finally { + if(arrival == 0) { + barrier.reset(); + } + } + } + return 0; + } + + /** + * We have to control the cloning process because we need some cross-thread + * communication if our synctimers are to be able to determine when to block + * and when to release. + */ + @Override + public Object clone() { + SyncTimer newTimer = (SyncTimer) super.clone(); + newTimer.barrier = barrier; + return newTimer; + } + + /** + * {@inheritDoc} + */ + public void testEnded() { + this.testEnded(null); + } + + /** + * Reset timerCounter + */ + public void testEnded(String host) { + createBarrier(); + } + + /** + * {@inheritDoc} + */ + public void testStarted() { + testStarted(null); + } + + /** + * Reset timerCounter + */ + public void testStarted(String host) { + createBarrier(); + } + + public void testIterationStart(LoopIterationEvent event) { + // NOOP + } + + /** + * + */ + private void createBarrier() { + if(getGroupSize() == 0) { + // Lazy init + this.barrier = new BarrierWrapper(); + } else { + this.barrier = new BarrierWrapper(getGroupSize()); + } + } + + public void threadStarted() { + int numThreadsInGroup = JMeterContextService.getContext().getThreadGroup().getNumThreads(); + if(getGroupSize() == 0) { + // Unique Barrier creation ensured by synchronized setup + this.barrier.setup(numThreadsInGroup); + } + } + + public void threadFinished() { + // NOOP + } +} \ No newline at end of file Propchange: jmeter/trunk/src/components/org/apache/jmeter/timers/SyncTimer.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: jmeter/trunk/src/components/org/apache/jmeter/timers/SyncTimer.java.tmp URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/timers/SyncTimer.java.tmp?rev=1205982&view=auto ============================================================================== --- jmeter/trunk/src/components/org/apache/jmeter/timers/SyncTimer.java.tmp (added) +++ jmeter/trunk/src/components/org/apache/jmeter/timers/SyncTimer.java.tmp Thu Nov 24 21:18:24 2011 @@ -0,0 +1,153 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + */ + +package org.apache.jmeter.timers; + +import java.io.Serializable; +import java.util.concurrent.BrokenBarrierException; + +import org.apache.jmeter.engine.event.LoopIterationEvent; +import org.apache.jmeter.testbeans.TestBean; +import org.apache.jmeter.testelement.AbstractTestElement; +import org.apache.jmeter.testelement.TestListener; +import org.apache.jmeter.testelement.ThreadListener; +import org.apache.jmeter.threads.JMeterContextService; + +/** + * The purpose of the SyncTimer is to block threads until X number of threads + * have been blocked, and then they are all released at once. A SyncTimer can + * thus create large instant loads at various points of the test plan. + * + */ +public class SyncTimer extends AbstractTestElement implements Timer, Serializable, TestBean, TestListener, ThreadListener { + private static final long serialVersionUID = 2; + + private BarrierWrapper barrier; + + private int groupSize; + + // Ensure transient object is created by the server + private Object readResolve(){ + createBarrier(); + return this; + } + + /** + * @return Returns the numThreads. + */ + public int getGroupSize() { + return groupSize; + } + + /** + * @param numThreads + * The numThreads to set. + */ + public void setGroupSize(int numThreads) { + this.groupSize = numThreads; + } + + /** + * {@inheritDoc} + */ + public long delay() { + if(getGroupSize()>=0) { + int arrival = 0; + try { + arrival = this.barrier.await(); + } catch (InterruptedException e) { + return 0; + } catch (BrokenBarrierException e) { + return 0; + } finally { + if(arrival == 0) { + barrier.reset(); + } + } + } + return 0; + } + + /** + * We have to control the cloning process because we need some cross-thread + * communication if our synctimers are to be able to determine when to block + * and when to release. + */ + @Override + public Object clone() { + SyncTimer newTimer = (SyncTimer) super.clone(); + newTimer.barrier = barrier; + return newTimer; + } + + /** + * {@inheritDoc} + */ + public void testEnded() { + this.testEnded(null); + } + + /** + * Reset timerCounter + */ + public void testEnded(String host) { + createBarrier(); + } + + /** + * {@inheritDoc} + */ + public void testStarted() { + testStarted(null); + } + + /** + * Reset timerCounter + */ + public void testStarted(String host) { + createBarrier(); + } + + public void testIterationStart(LoopIterationEvent event) { + // NOOP + } + + /** + * + */ + private void createBarrier() { + if(getGroupSize() == 0) { + // Lazy init + this.barrier = new BarrierWrapper(); + } else { + this.barrier = new BarrierWrapper(getGroupSize()); + } + } + + public void threadStarted() { + int numThreadsInGroup = JMeterContextService.getContext().getThreadGroup().getNumThreads(); + if(getGroupSize() == 0) { + // Unique Barrier creation ensured by synchronized setup + this.barrier.setup(numThreadsInGroup); + } + } + + public void threadFinished() { + // NOOP + } +} \ No newline at end of file