View Javadoc

1   /*
2    * Copyright 2007-2008 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.gwe.app.client.web.view;
18  
19  import org.gwe.api.Session4ClientAPIEnhancer;
20  import org.gwe.app.client.SessionsRepository;
21  import org.gwe.app.client.config.ClientConfig;
22  import org.gwe.app.client.web.request.Param;
23  import org.gwe.persistence.model.HeadResourceInfo;
24  import org.gwe.utils.web.HtmlLink;
25  import org.gwe.utils.web.HtmlTable;
26  import org.gwe.utils.web.HtmlTableCell;
27  import org.gwe.utils.web.WebIcon;
28  
29  /**
30   * @author Marco Ruiz
31   * @since Dec 18, 2008
32   */
33  public class HtmlClustersTable extends HtmlTable {
34  
35  	public static String getStatusIcon(Session4ClientAPIEnhancer session) {
36  		return (session == null) ? "icon_error_sml.gif" : "icon_success_sml.gif";
37  	}
38  	
39  	public HtmlClustersTable(ClientConfig config) {
40  	    super("Status", "Name", "Host", "Queue Size", "Wait Connection Timeout", "Hijack Timeout", "Idle Timeout", "Variables");
41  	    SessionsRepository sessionsRepo = config.getSessionsRepository();
42      	for (HeadResourceInfo obj : config.getGrid().getHeadResources()) {
43      		Session4ClientAPIEnhancer session = null;
44  			try {
45  	            session = sessionsRepo.getSession(obj, false);
46              } catch (Exception e) {}
47      	    WebIcon statusImage = WebIcon.getImageFor(session);
48  			String tootip = (statusImage == WebIcon.STATUS_OK) ?  "GWE enabled cluster" : "Cluster not enabled with GWE";
49  			HtmlTableCell status = new HtmlTableCell("", tootip, null, statusImage);
50      	    HtmlTableCell name = new HtmlTableCell(obj.getName(), "", new HtmlClusterLink(obj.getName()));
51          	addRow(status, name, obj.getHost(), obj.getQueueSize(), getMinutes(obj.getMaxWaitMins()), getMinutes(obj.getMaxHijackMins()), getMinutes(obj.getMaxIdleMins()), obj.getVarsAsMap());
52      	}
53      }
54  	
55  	private String getMinutes(float minutes) {
56  		return minutes + " minutes";
57  	}
58  }
59  
60  class HtmlClusterLink extends HtmlLink {
61  
62  	public HtmlClusterLink(String clusterId) {
63  	    super(false, "cluster");
64  	    addParam(Param.CLUSTER_ID, clusterId);
65      }
66  }