01: /**
02: *
03: */package org.getahead.dwrdemo.stress;
04:
05: import org.apache.commons.logging.LogFactory;
06: import org.apache.commons.logging.Log;
07: import org.directwebremoting.ScriptSession;
08: import org.directwebremoting.WebContextFactory;
09: import org.directwebremoting.proxy.ScriptProxy;
10:
11: /**
12: * @author Joe Walker [joe at getahead dot ltd dot uk]
13: */
14: public class Stress implements Runnable {
15: public Stress() {
16: session = WebContextFactory.get().getScriptSession();
17: }
18:
19: /**
20: * Call for use in client side stress testing
21: */
22: public void ping() {
23: }
24:
25: /**
26: *
27: * @param publishing
28: */
29: public void setPublishing(boolean publishing) {
30: this .publishing = publishing;
31:
32: if (publishing) {
33: Thread worker = new Thread(this );
34: worker.setName("Stress on ScriptSession: "
35: + session.getId().substring(10));
36: worker.start();
37: }
38: }
39:
40: /* (non-Javadoc)
41: * @see java.lang.Runnable#run()
42: */
43: public void run() {
44: try {
45: log.debug("Stress: Starting server-side thread");
46: int pings = 0;
47:
48: while (publishing) {
49: ScriptProxy pages = new ScriptProxy(session);
50: pages.addFunctionCall("serverPing", new Integer(pings));
51:
52: pings++;
53: Thread.sleep(delay);
54: }
55:
56: log.debug("Stress: Stopping server-side thread");
57: } catch (InterruptedException ex) {
58: ex.printStackTrace();
59: }
60: }
61:
62: /**
63: * Accessor for the delay between server publishes
64: * @param delay The new delay between server publishes
65: */
66: public void setHitDelay(int delay) {
67: this .delay = delay;
68: }
69:
70: /**
71: * Our key to get hold of ServerContexts
72: */
73: private ScriptSession session;
74:
75: /**
76: * Are we in a server publish cycle
77: */
78: private boolean publishing = false;
79:
80: /**
81: * How long between server publishes
82: */
83: private int delay = 1000;
84:
85: /**
86: * The log stream
87: */
88: private static final Log log = LogFactory.getLog(Stress.class);
89: }
|