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 collection period.
48     *
49     * @return the collection period
50     */
51    public long getCollectionPeriod() {
52      return collectionPeriod;
53    }
54  
55    /**
56     * Sets the collection period.
57     *
58     * @param collectionPeriod the new collection period
59     */
60    public void setCollectionPeriod(long collectionPeriod) {
61      this.collectionPeriod = collectionPeriod;
62    }
63  
64    /**
65     * Sets the collection period using expression.
66     *
67     * @param collectionPeriod the new collection period using expression
68     */
69    @Value("${psiprobe.beans.stats.collectors.connector.period}")
70    public void setCollectionPeriod(String collectionPeriod) {
71      this.collectionPeriod = TimeExpression.inSeconds(collectionPeriod);
72    }
73  
74    /**
75     * Checks if is include request processors.
76     *
77     * @return true, if is include request processors
78     */
79    public boolean isIncludeRequestProcessors() {
80      return includeRequestProcessors;
81    }
82  
83    /**
84     * Sets the include request processors.
85     *
86     * @param includeRequestProcessors the new include request processors
87     */
88    @Value("true")
89    public void setIncludeRequestProcessors(boolean includeRequestProcessors) {
90      this.includeRequestProcessors = includeRequestProcessors;
91    }
92  
93    @RequestMapping(path = "/connectors.htm")
94    @Override
95    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
96        throws Exception {
97      return super.handleRequest(request, response);
98    }
99  
100   @Override
101   protected ModelAndView handleRequestInternal(HttpServletRequest request,
102       HttpServletResponse response) throws Exception {
103 
104     boolean workerThreadNameSupported = false;
105     List<Connector> connectors = containerListenerBean.getConnectors(includeRequestProcessors);
106 
107     if (!connectors.isEmpty()) {
108       List<RequestProcessor> reqProcs = connectors.get(0).getRequestProcessors();
109       if (!reqProcs.isEmpty()) {
110         RequestProcessor reqProc = reqProcs.get(0);
111         workerThreadNameSupported = reqProc.isWorkerThreadNameSupported();
112       }
113     }
114 
115     return new ModelAndView(getViewName()).addObject("connectors", connectors)
116         .addObject("workerThreadNameSupported", workerThreadNameSupported)
117         .addObject("collectionPeriod", getCollectionPeriod());
118   }
119 
120   @Value("connectors")
121   @Override
122   public void setViewName(String viewName) {
123     super.setViewName(viewName);
124   }
125 
126 }