View Javadoc
1   /*
2    * Licensed under the GPL License. You may not use this file except in compliance with the License.
3    * You may obtain a copy of the License at
4    *
5    *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6    *
7    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8    * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9    * PURPOSE.
10   */
11  package psiprobe.controllers.connectors;
12  
13  import jakarta.inject.Inject;
14  import jakarta.servlet.http.HttpServletRequest;
15  import jakarta.servlet.http.HttpServletResponse;
16  
17  import java.util.List;
18  
19  import org.springframework.beans.factory.annotation.Value;
20  import org.springframework.stereotype.Controller;
21  import org.springframework.web.bind.annotation.RequestMapping;
22  import org.springframework.web.servlet.ModelAndView;
23  
24  import psiprobe.beans.ContainerListenerBean;
25  import psiprobe.controllers.AbstractTomcatContainerController;
26  import psiprobe.model.Connector;
27  import psiprobe.model.RequestProcessor;
28  import psiprobe.tools.TimeExpression;
29  
30  /**
31   * The Class ListConnectorsController.
32   */
33  @Controller
34  public class ListConnectorsController extends AbstractTomcatContainerController {
35  
36    /** The container listener bean. */
37    @Inject
38    private ContainerListenerBean containerListenerBean;
39  
40    /** The include request processors. */
41    private boolean includeRequestProcessors;
42  
43    /** The collection period. */
44    private long collectionPeriod;
45  
46    /**
47     * Gets the container listener bean.
48     *
49     * @return the container listener bean
50     */
51    public ContainerListenerBean getContainerListenerBean() {
52      return containerListenerBean;
53    }
54  
55    /**
56     * Sets the container listener bean.
57     *
58     * @param containerListenerBean the new container listener bean
59     */
60    public void setContainerListenerBean(ContainerListenerBean containerListenerBean) {
61      this.containerListenerBean = containerListenerBean;
62    }
63  
64    /**
65     * Gets the collection period.
66     *
67     * @return the collection period
68     */
69    public long getCollectionPeriod() {
70      return collectionPeriod;
71    }
72  
73    /**
74     * Sets the collection period.
75     *
76     * @param collectionPeriod the new collection period
77     */
78    public void setCollectionPeriod(long collectionPeriod) {
79      this.collectionPeriod = collectionPeriod;
80    }
81  
82    /**
83     * Sets the collection period using expression.
84     *
85     * @param collectionPeriod the new collection period using expression
86     */
87    @Value("${psiprobe.beans.stats.collectors.connector.period}")
88    public void setCollectionPeriod(String collectionPeriod) {
89      this.collectionPeriod = TimeExpression.inSeconds(collectionPeriod);
90    }
91  
92    /**
93     * Checks if is include request processors.
94     *
95     * @return true, if is include request processors
96     */
97    public boolean isIncludeRequestProcessors() {
98      return includeRequestProcessors;
99    }
100 
101   /**
102    * Sets the include request processors.
103    *
104    * @param includeRequestProcessors the new include request processors
105    */
106   @Value("true")
107   public void setIncludeRequestProcessors(boolean includeRequestProcessors) {
108     this.includeRequestProcessors = includeRequestProcessors;
109   }
110 
111   @RequestMapping(path = "/connectors.htm")
112   @Override
113   public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
114       throws Exception {
115     return super.handleRequest(request, response);
116   }
117 
118   @Override
119   protected ModelAndView handleRequestInternal(HttpServletRequest request,
120       HttpServletResponse response) throws Exception {
121 
122     boolean workerThreadNameSupported = false;
123     List<Connector> connectors = containerListenerBean.getConnectors(includeRequestProcessors);
124 
125     if (!connectors.isEmpty()) {
126       List<RequestProcessor> reqProcs = connectors.get(0).getRequestProcessors();
127       if (!reqProcs.isEmpty()) {
128         RequestProcessor reqProc = reqProcs.get(0);
129         workerThreadNameSupported = reqProc.isWorkerThreadNameSupported();
130       }
131     }
132 
133     return new ModelAndView(getViewName()).addObject("connectors", connectors)
134         .addObject("workerThreadNameSupported", workerThreadNameSupported)
135         .addObject("collectionPeriod", getCollectionPeriod());
136   }
137 
138   @Value("connectors")
139   @Override
140   public void setViewName(String viewName) {
141     super.setViewName(viewName);
142   }
143 
144 }