myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lof...@apache.org
Subject svn commit: r1003403 - in /myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main: java/org/apache/myfaces/tobago/example/demo/activity/ webapp/
Date Fri, 01 Oct 2010 06:26:45 GMT
Author: lofwyr
Date: Fri Oct  1 06:26:45 2010
New Revision: 1003403

URL: http://svn.apache.org/viewvc?rev=1003403&view=rev
Log:
Monitoring of user sessions and activity. Can be helpful for performance tests.

Added:
    myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/
    myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/Activity.java
    myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/ActivityList.java
    myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/ActivityPhaseListener.java
    myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/ActivityServletContextListener.java
    myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/ActivitySessionListener.java
Modified:
    myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/webapp/server-info.jsp

Added: myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/Activity.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/Activity.java?rev=1003403&view=auto
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/Activity.java
(added)
+++ myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/Activity.java
Fri Oct  1 06:26:45 2010
@@ -0,0 +1,67 @@
+package org.apache.myfaces.tobago.example.demo.activity;
+
+import javax.servlet.http.HttpSession;
+import java.util.Date;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: lofwyr
+ * Date: 30.09.2010
+ * Time: 16:47:47
+ * To change this template use File | Settings | File Templates.
+ */
+public class Activity {
+
+  private String sessionId;
+
+  private Date creationDate;
+
+  private int jsfRequest;
+
+  private int ajaxRequest;
+
+  public Activity(HttpSession session) {
+    this.sessionId = session.getId();
+    this.creationDate = new Date(session.getCreationTime());
+  }
+
+  public void jsfRequest() {
+    jsfRequest++;
+  }
+
+  public void ajaxRequest() {
+      ajaxRequest++;
+  }
+
+  public String getSessionId() {
+    return sessionId;
+  }
+
+  public void setSessionId(String sessionId) {
+    this.sessionId = sessionId;
+  }
+
+  public Date getCreationDate() {
+    return creationDate;
+  }
+
+  public void setCreationDate(Date creationDate) {
+    this.creationDate = creationDate;
+  }
+
+  public int getJsfRequest() {
+    return jsfRequest;
+  }
+
+  public void setJsfRequest(int jsfRequest) {
+    this.jsfRequest = jsfRequest;
+  }
+
+  public int getAjaxRequest() {
+    return ajaxRequest;
+  }
+
+  public void setAjaxRequest(int ajaxRequest) {
+    this.ajaxRequest = ajaxRequest;
+  }
+}

Added: myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/ActivityList.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/ActivityList.java?rev=1003403&view=auto
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/ActivityList.java
(added)
+++ myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/ActivityList.java
Fri Oct  1 06:26:45 2010
@@ -0,0 +1,51 @@
+package org.apache.myfaces.tobago.example.demo.activity;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: lofwyr
+ * Date: 30.09.2010
+ * Time: 16:47:47
+ * To change this template use File | Settings | File Templates.
+ */
+public class ActivityList {
+
+  private static final Log LOG = LogFactory.getLog(ActivityList.class);
+
+  public static final String NAME = "activities";
+
+  private Map<String, Activity> data = new ConcurrentHashMap<String, Activity>();
+  
+  public void add(Activity activity) {
+    LOG.info("Adding session id: " + activity.getSessionId());
+    data.put(activity.getSessionId(),activity);
+  }
+
+  public void remove(String sessionId) {
+    LOG.info("Removing session id: " + sessionId);
+    final Activity activity = data.remove(sessionId);
+  }
+
+  public List<Activity> getValues() {
+    final Collection<Activity> values = data.values();
+    ArrayList<Activity> result = new ArrayList<Activity>();
+    result.addAll(values);
+    return result;
+  }
+
+  public void jsfRequest(String sessionId) {
+    data.get(sessionId).jsfRequest();
+  }
+
+  public void ajaxRequest(String sessionId) {
+    data.get(sessionId).ajaxRequest();
+  }
+}

Added: myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/ActivityPhaseListener.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/ActivityPhaseListener.java?rev=1003403&view=auto
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/ActivityPhaseListener.java
(added)
+++ myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/ActivityPhaseListener.java
Fri Oct  1 06:26:45 2010
@@ -0,0 +1,37 @@
+package org.apache.myfaces.tobago.example.demo.activity;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.myfaces.tobago.ajax.api.AjaxUtils;
+import org.apache.myfaces.tobago.util.VariableResolverUtil;
+
+import javax.faces.context.FacesContext;
+import javax.faces.event.PhaseEvent;
+import javax.faces.event.PhaseId;
+import javax.faces.event.PhaseListener;
+import javax.servlet.http.HttpSession;
+
+public class ActivityPhaseListener implements PhaseListener {
+
+  private static final Log LOG = LogFactory.getLog(ActivityPhaseListener.class);
+
+  public void afterPhase(PhaseEvent event) {
+  }
+
+  public void beforePhase(PhaseEvent event) {
+    final FacesContext facesContext = event.getFacesContext();
+    final ActivityList activityList
+        = (ActivityList) VariableResolverUtil.resolveVariable(facesContext, ActivityList.NAME);
+    String sessionId = ((HttpSession) facesContext.getExternalContext().getSession(true)).getId();
+
+    if (AjaxUtils.isAjaxRequest(facesContext)) {
+      activityList.ajaxRequest(sessionId);
+    } else {
+      activityList.jsfRequest(sessionId);
+    }
+  }
+
+  public PhaseId getPhaseId() {
+    return PhaseId.RENDER_RESPONSE;
+  }
+}

Added: myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/ActivityServletContextListener.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/ActivityServletContextListener.java?rev=1003403&view=auto
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/ActivityServletContextListener.java
(added)
+++ myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/ActivityServletContextListener.java
Fri Oct  1 06:26:45 2010
@@ -0,0 +1,23 @@
+package org.apache.myfaces.tobago.example.demo.activity;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+public class ActivityServletContextListener implements ServletContextListener {
+
+  private static final Log LOG = LogFactory.getLog(ActivityServletContextListener.class);
+
+  public void contextInitialized(ServletContextEvent event) {
+    final ServletContext application = event.getServletContext();
+    application.setAttribute(ActivityList.NAME, new ActivityList());
+  }
+
+  public void contextDestroyed(ServletContextEvent event) {
+    final ServletContext application = event.getServletContext();
+    application.removeAttribute(ActivityList.NAME);
+  }
+}

Added: myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/ActivitySessionListener.java
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/ActivitySessionListener.java?rev=1003403&view=auto
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/ActivitySessionListener.java
(added)
+++ myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/java/org/apache/myfaces/tobago/example/demo/activity/ActivitySessionListener.java
Fri Oct  1 06:26:45 2010
@@ -0,0 +1,30 @@
+package org.apache.myfaces.tobago.example.demo.activity;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpSession;
+import javax.servlet.http.HttpSessionEvent;
+import javax.servlet.http.HttpSessionListener;
+
+public class ActivitySessionListener implements HttpSessionListener {
+
+  private static final Log LOG = LogFactory.getLog(ActivitySessionListener.class);
+
+  private static final String SESSION_MAP = ActivitySessionListener.class.getName() + ".SESSION_MAP";
+
+  public void sessionCreated(HttpSessionEvent event) {
+    final HttpSession session = event.getSession();
+    final ServletContext application = session.getServletContext();
+    final ActivityList activityList = (ActivityList) application.getAttribute(ActivityList.NAME);
+    activityList.add(new Activity(session));
+  }
+
+  public void sessionDestroyed(HttpSessionEvent event) {
+    final HttpSession session = event.getSession();
+    final ServletContext application = session.getServletContext();
+    final ActivityList activityList = (ActivityList) application.getAttribute(ActivityList.NAME);
+    activityList.remove(session.getId());
+  }
+}

Modified: myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/webapp/server-info.jsp
URL: http://svn.apache.org/viewvc/myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/webapp/server-info.jsp?rev=1003403&r1=1003402&r2=1003403&view=diff
==============================================================================
--- myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/webapp/server-info.jsp (original)
+++ myfaces/tobago/branches/tobago-1.0.x/example/demo/src/main/webapp/server-info.jsp Fri
Oct  1 06:26:45 2010
@@ -23,22 +23,38 @@
   <jsp:body>
     <tc:box label="Server Info">
       <f:facet name="layout">
-        <tc:gridLayout rows="fixed;fixed;fixed;fixed;*" />
+        <tc:gridLayout rows="fixed;fixed;fixed;fixed;*"/>
       </f:facet>
 
       <tx:in value="#{info.version}" readonly="true"
-          label="Tobago Version" />
+             label="Tobago Version"/>
 
       <tx:in value="#{info.serverInfo}" readonly="true"
-          label="Server Info" />
+             label="Server Info"/>
 
-      <tx:in value="#{info.systemProperties['java.runtime.version']} - #{info.systemProperties['java.vm.vendor']}"
readonly="true"
-          label="Java" />
-
-      <tx:in value="#{info.systemProperties['os.name']} - #{info.systemProperties['os.version']}
- #{info.systemProperties['os.arch']}" readonly="true"
-          label="Operating System" />
-
-      <tc:cell/>
+      <tx:in value="#{info.systemProperties['java.runtime.version']} - #{info.systemProperties['java.vm.vendor']}"
+             readonly="true"
+             label="Java"/>
+
+      <tx:in
+          value="#{info.systemProperties['os.name']} - #{info.systemProperties['os.version']}
- #{info.systemProperties['os.arch']}"
+          readonly="true"
+          label="Operating System"/>
+
+      <tc:sheet value="#{activities.values}" var="activity">
+        <tc:column label="Session Id" sortable="true">
+          <tc:out value="#{activity.sessionId}"/>
+        </tc:column>
+        <tc:column label="Creation Date" sortable="true">
+          <tc:out value="#{activity.creationDate}"/>
+        </tc:column>
+        <tc:column label="Jsf Request Count" sortable="true">
+          <tc:out value="#{activity.jsfRequest}"/>
+        </tc:column>
+        <tc:column label="Ajax Request Count" sortable="true">
+          <tc:out value="#{activity.ajaxRequest}"/>
+        </tc:column>
+      </tc:sheet>
 
     </tc:box>
   </jsp:body>



Mime
View raw message