1 4 package com.tctest.performance.generate.load; 5 6 import com.tc.util.Assert; 7 import com.tctest.performance.simulate.type.SimulatedType; 8 9 12 public final class LinearTransitionLoadGenerator implements LoadGenerator { 13 14 private static final int BUFFER_SIZE_SECONDS = 10; 15 private static final int WORKQUEUE_SIZE_SECONDS = 10; 16 private volatile boolean started; 17 private MonitoredWorkQueue workQueue; 18 private Measurement[] waitTimes; 19 20 public synchronized void start(int duration, int minLoad, int maxLoad, SimulatedType factory, int percentUnique) { 21 Assert.assertTrue(!started); 22 started = true; 23 Thread.currentThread().setPriority(Thread.MAX_PRIORITY); 24 25 LoadBuffer buffer = new LoadBuffer(maxLoad * BUFFER_SIZE_SECONDS); 26 workQueue = new MonitoredWorkQueue(maxLoad * WORKQUEUE_SIZE_SECONDS, true); 27 28 LoadProducer producer = new LoadProducer(buffer, duration, minLoad, maxLoad, factory, percentUnique); 29 LoadConsumer consumer = new LoadConsumer(buffer, workQueue); 30 31 producer.start(); 32 try { 33 Thread.sleep(10000); 34 } catch (InterruptedException e) { 35 throw new RuntimeException (e); 36 } 37 consumer.start(); 38 } 39 40 public Object getNext() throws InterruptedException , WorkQueueOverflowException { 41 Assert.assertTrue(started); 42 try { 43 Object obj = workQueue.get(); 44 if (obj == null) waitTimes = workQueue.getWaitTimes(); 45 return obj; 46 } catch (WorkQueueOverflowException e) { 47 waitTimes = workQueue.getWaitTimes(); 48 throw e; 49 } 50 } 51 52 public Measurement[] getWaitTimes() { 53 return waitTimes; 54 } 55 } 56 | Popular Tags |