| 1 4 package com.tctest.performance.http.load; 5 6 import EDU.oswego.cs.dl.util.concurrent.PooledExecutor; 7 8 import java.io.IOException ; 9 import java.util.concurrent.LinkedBlockingQueue ; 10 11 final class HttpLoadClient { 12 13 private final LinkedBlockingQueue workQ; 14 private final PooledExecutor requestExecutor; 15 private final RequestCounter counter; 16 private final StatsCollector collector; 17 18 protected HttpLoadClient(LinkedBlockingQueue workQ, PooledExecutor requestExecutor, String [] hosts, int sessionCount, 19 int stickyRatio, RequestCounter counter) { 20 21 this.counter = counter; 22 this.workQ = workQ; 23 this.requestExecutor = requestExecutor; 24 this.collector = new StatsCollector(); 25 } 26 27 public void execute() throws InterruptedException { 28 while (true) { 29 WorkItem workItem = (WorkItem) workQ.take(); 30 if (workItem.expired(System.currentTimeMillis())) continue; 31 if (workItem.stop()) break; 32 requestExecutor.execute(new Requestor(workItem)); 33 } 34 requestExecutor.shutdownAfterProcessingCurrentlyQueuedTasks(); 35 requestExecutor.awaitTerminationAfterShutdown(); 36 37 collector.finalStat(); 38 } 39 40 public StatsCollector getCollector() { 41 return collector; 42 } 43 44 private void err(String str) { 45 System.err.println(str); 46 } 47 48 private class Requestor implements Runnable { 49 private WorkItem workItem; 50 51 private Requestor(WorkItem workItem) { 52 this.workItem = workItem; 53 } 54 55 public void run() { 56 try { 57 workItem.execute(collector); 58 counter.increment(); 59 } catch (IOException e) { 60 err("--Host Response Dropped"); 61 } catch (NullPointerException e) { 62 err("--Client Connection Stale"); 63 } catch (IllegalStateException e) { 64 err("--Client Connection is not Open"); 65 } finally { 66 workItem.done(); 67 } 68 } 69 } 70 71 } 72 | Popular Tags |