01: package example;
02:
03: import java.io.PrintWriter;
04: import java.io.IOException;
05:
06: import javax.servlet.ServletRequest;
07: import javax.servlet.ServletResponse;
08: import javax.servlet.GenericServlet;
09: import javax.servlet.ServletException;
10:
11: /**
12: * A client listener servlet to show the MBean listener pattern.
13: *
14: * The ListenerServlet follows the Dependency Injection pattern,
15: * letting Resin's web.xml configure the emitter and listener.
16: */
17: public class ListenerServlet extends GenericServlet {
18: private EmitterMBean _emitter;
19: private ListenerMBean _listener;
20:
21: /**
22: * The web.xml will configure the emitter.
23: */
24: public void setEmitter(EmitterMBean emitter) {
25: _emitter = emitter;
26: }
27:
28: /**
29: * The web.xml will configure the listener.
30: */
31: public void setListener(ListenerMBean listener) {
32: _listener = listener;
33: }
34:
35: public void service(ServletRequest request, ServletResponse response)
36: throws ServletException, IOException {
37: PrintWriter out = response.getWriter();
38:
39: _emitter.send();
40:
41: out.println("listener count: "
42: + _listener.getNotificationCount());
43: }
44: }
|