01: /*
02: @COPYRIGHT@
03: */
04: package demo.jmx.web;
05:
06: import demo.jmx.ICounter;
07: import demo.jmx.IHistory;
08: import java.util.HashMap;
09: import java.util.Map;
10: import javax.servlet.http.HttpServletRequest;
11: import javax.servlet.http.HttpServletResponse;
12: import org.springframework.web.servlet.ModelAndView;
13: import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
14:
15: /**
16: * Web controller
17: */
18: public class CounterFormController extends MultiActionController {
19: private transient ICounter localCounter;
20: private transient IHistory localHistory;
21: private transient ICounter clusteredCounter;
22: private transient IHistory clusteredHistory;
23:
24: public void setLocalCounter(ICounter counter) {
25: this .localCounter = counter;
26: }
27:
28: public void setLocalHistory(IHistory history) {
29: this .localHistory = history;
30: }
31:
32: public void setClusteredCounter(ICounter clusteredCounter) {
33: this .clusteredCounter = clusteredCounter;
34: }
35:
36: public void setClusteredHistory(IHistory clusteredHistory) {
37: this .clusteredHistory = clusteredHistory;
38: }
39:
40: /**
41: * Controller method to handle refresh action
42: */
43: public ModelAndView handleRefresh(HttpServletRequest request,
44: HttpServletResponse response) throws Exception {
45: Map model = new HashMap();
46: model.put("localCounter",
47: new Integer(localCounter.getCurrent()));
48: model.put("localHistory", localHistory.getHistory());
49: model.put("clusteredCounter", new Integer(clusteredCounter
50: .getCurrent()));
51: model.put("clusteredHistory", clusteredHistory.getHistory());
52: return new ModelAndView("index", model);
53: }
54:
55: /**
56: * Controller method to handle counter increment action
57: */
58: public ModelAndView incrementLocal(HttpServletRequest request,
59: HttpServletResponse response) throws Exception {
60: localCounter.next();
61: return new ModelAndView("redirect:index.jsp", null);
62: }
63:
64: public ModelAndView incrementClustered(HttpServletRequest request,
65: HttpServletResponse response) throws Exception {
66: clusteredCounter.next();
67: return new ModelAndView("redirect:index.jsp", null);
68: }
69: }
|