CounterFormController.java
01 /**
02  *
03  * All content copyright (c) 2003-2008 Terracotta, Inc.,
04  * except as may otherwise be noted in a separate copyright notice.
05  * All rights reserved.
06  *
07  */
08 package demo.jmx.web;
09 
10 import demo.jmx.ICounter;
11 import demo.jmx.IHistory;
12 import java.util.HashMap;
13 import java.util.Map;
14 import javax.servlet.http.HttpServletRequest;
15 import javax.servlet.http.HttpServletResponse;
16 import org.springframework.web.servlet.ModelAndView;
17 import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
18 
19 /**
20  *  Web controller
21  *
22  *@author    Terracotta, Inc.
23  */
24 public class CounterFormController
25        extends MultiActionController {
26    private transient ICounter localCounter;
27    private transient IHistory localHistory;
28    private transient ICounter clusteredCounter;
29    private transient IHistory clusteredHistory;
30 
31    public void setLocalCounter(ICounter counter) {
32       this.localCounter = counter;
33    }
34 
35    public void setLocalHistory(IHistory history) {
36       this.localHistory = history;
37    }
38 
39    public void setClusteredCounter(ICounter clusteredCounter) {
40       this.clusteredCounter = clusteredCounter;
41    }
42 
43    public void setClusteredHistory(IHistory clusteredHistory) {
44       this.clusteredHistory = clusteredHistory;
45    }
46 
47    /**
48     *  Controller method to handle refresh action
49     *
50     *@param  request        Description of Parameter
51     *@param  response       Description of Parameter
52     *@return                Description of the Returned Value
53     *@exception  Exception  Description of Exception
54     */
55    public ModelAndView handleRefresh(HttpServletRequest request, HttpServletResponse response)
56           throws Exception {
57       Map model = new HashMap();
58       model.put("localCounter"new Integer(localCounter.getCurrent()));
59       model.put("localHistory", localHistory.getHistory());
60       model.put("clusteredCounter"new Integer(clusteredCounter.getCurrent()));
61       model.put("clusteredHistory", clusteredHistory.getHistory());
62       return new ModelAndView("index", model);
63    }
64 
65    /**
66     *  Controller method to handle counter increment action
67     *
68     *@param  request        Description of Parameter
69     *@param  response       Description of Parameter
70     *@return                Description of the Returned Value
71     *@exception  Exception  Description of Exception
72     */
73    public ModelAndView incrementLocal(HttpServletRequest request, HttpServletResponse response)
74           throws Exception {
75       localCounter.next();
76       return new ModelAndView("redirect:index.jsp"null);
77    }
78 
79    public ModelAndView incrementClustered(HttpServletRequest request, HttpServletResponse response)
80           throws Exception {
81       clusteredCounter.next();
82       return new ModelAndView("redirect:index.jsp"null);
83    }
84 }