KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > monitor > session > component > UILiveSessions


1 /**
2  * Copyright 2001-2003 The eXo platform SARL All rights reserved.
3  * Please look at license.txt in info directory for more license detail.
4  */

5 package org.exoplatform.portlets.monitor.session.component;
6
7 import java.io.IOException JavaDoc;
8 import java.util.ArrayList JavaDoc;
9 import org.exoplatform.container.PortalContainer;
10 import org.exoplatform.container.SessionContainer;
11 import org.exoplatform.container.client.http.HttpClientInfo;
12 import org.exoplatform.container.monitor.SessionMonitor;
13 import org.exoplatform.faces.core.component.UIGrid;
14 import org.exoplatform.faces.core.component.model.*;
15 import org.exoplatform.faces.core.event.ExoActionEvent;
16 import org.exoplatform.faces.core.event.ExoActionListener;
17 /**
18  * Created y the eXo platform team
19  * User: Benjamin Mestrallet
20  * Date: 22 juin 2004
21  */

22 public class UILiveSessions extends UIGrid {
23   final static public String JavaDoc VIEW_ACTION = "view" ;
24   private static Parameter[] VIEW_PARAMS = {new Parameter(ACTION , VIEW_ACTION) } ;
25
26   private SessionContainerDataHandler dataHandler_ ;
27   private PortalContainer pcontainer_ ;
28   private boolean adminRole_ ;
29
30   public UILiveSessions() throws Exception JavaDoc {
31     setId("UILiveSessions") ;
32     pcontainer_ = PortalContainer.getInstance() ;
33     dataHandler_ = new SessionContainerDataHandler() ;
34     dataHandler_.setDatas(new ArrayList JavaDoc()) ;
35     adminRole_ = hasRole("admin") ;
36     add(new Rows(dataHandler_, "even", "odd").
37         add(new Column("#{UILiveSessions.header.user}", "user")).
38         add(new Column("#{UILiveSessions.header.client-name}", "clientName")).
39         add(new Column("#{UILiveSessions.header.ip-address}", "ipAddress")).
40         add(new Column("#{UILiveSessions.header.request-counter}", "requestCounter")).
41         add(new Column("#{UILiveSessions.header.live-time}", "liveTime")).
42         add(new Column("#{UILiveSessions.header.context-path}", "path")).
43         add(new ActionColumn("#{UILiveSessions.header.action}", "sessionId").
44             add(adminRole_ ,new Button("#{UILiveSessions.button.view}", VIEW_PARAMS)))) ;
45     addActionListener(ViewActionListener.class, VIEW_ACTION) ;
46   }
47
48   static public class SessionContainerDataHandler extends ListDataHandler {
49     private SessionContainer scontainer_ ;
50     private HttpClientInfo info ;
51     private SessionMonitor monitor ;
52     
53     public String JavaDoc getData(String JavaDoc fieldName) {
54       if("sessionId".equals(fieldName)) return scontainer_.getId() ;
55       if("user".equals(fieldName)) return scontainer_.getOwner() ;
56       if(info != null && "clientName".equals(fieldName)) return info.getClientName() ;
57       if(info != null && "ipAddress".equals(fieldName)) return info.getIpAddress() ;
58       if("requestCounter".equals(fieldName)) return Integer.toString(monitor.getActionCount()) ;
59       if("liveTime".equals(fieldName)) return Long.toString(monitor.getLiveTimeInMinute()) ;
60       if("path".equals(fieldName)) return "N/A";
61         return "unknown" ;
62     }
63     
64     public void setCurrentObject(Object JavaDoc o) {
65       scontainer_ = (SessionContainer) o;
66       info = (HttpClientInfo) scontainer_.getMonitor().getClientInfo() ;
67       monitor = scontainer_.getMonitor() ;
68     }
69   }
70   
71   public void encodeBegin(javax.faces.context.FacesContext context) throws IOException JavaDoc {
72     dataHandler_.setDatas(pcontainer_.getLiveSessions()) ;
73     super.encodeBegin(context) ;
74   }
75   
76   static public class ViewActionListener extends ExoActionListener {
77     public void execute(ExoActionEvent event) throws Exception JavaDoc {
78       UILiveSessions uiComp = (UILiveSessions) event.getSource() ;
79       UIActionHistory uiMonitor = (UIActionHistory) uiComp.getSibling(UIActionHistory.class) ;
80       String JavaDoc sessionId = event.getParameter(OBJECTID) ;
81       PortalContainer pcontainer = PortalContainer.getInstance() ;
82       SessionContainer scontainer =
83         (SessionContainer) pcontainer.getComponentInstance(sessionId) ;
84       uiMonitor.setActionHistory(UILiveSessions.class, scontainer.getMonitor().getHistory()) ;
85       uiComp.setRenderedSibling(UIActionHistory.class) ;
86     }
87   }
88 }
Popular Tags