[jboss-svn-commits] JBL Code SVN: r14333 - in labs/shotoku/trunk/shotoku-cache: cache-admin and 5 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Aug 17 07:14:45 EDT 2007


Author: adamw
Date: 2007-08-17 07:14:45 -0400 (Fri, 17 Aug 2007)
New Revision: 14333

Added:
   labs/shotoku/trunk/shotoku-cache/cache-admin/src/java/org/jboss/shotoku/cache/admin/WebFilesystemFilter.java
   labs/shotoku/trunk/shotoku-cache/cache-admin/src/web/pages/admin.css
Modified:
   labs/shotoku/trunk/shotoku-cache/build.xml
   labs/shotoku/trunk/shotoku-cache/cache-admin/build.xml
   labs/shotoku/trunk/shotoku-cache/cache-admin/src/java/org/jboss/shotoku/cache/admin/AdminBean.java
   labs/shotoku/trunk/shotoku-cache/cache-admin/src/web/WEB-INF/web.xml
   labs/shotoku/trunk/shotoku-cache/cache-admin/src/web/pages/admin.jsp
   labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/UpdateThread.java
   labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/service/RenewableCacheStatistics.java
   labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/service/RenewableCacheStatisticsImpl.java
Log:
Admin panel

Modified: labs/shotoku/trunk/shotoku-cache/build.xml
===================================================================
--- labs/shotoku/trunk/shotoku-cache/build.xml	2007-08-17 10:44:46 UTC (rev 14332)
+++ labs/shotoku/trunk/shotoku-cache/build.xml	2007-08-17 11:14:45 UTC (rev 14333)
@@ -24,6 +24,9 @@
 	<fileset id="jboss.lib.2" dir="${jboss.home}/lib">
 		<include name="**/*.jar"/>
 	</fileset>
+	<fileset id="jboss.lib.3" dir="${jboss.deploy}/jbossweb-tomcat55.sar/jsf-libs">
+		<include name="**/*.jar"/>
+	</fileset>
 	<fileset id="richfaces.lib" dir="lib/richfaces">
 		<include name="**/*.jar"/>
 	</fileset>
@@ -74,4 +77,10 @@
 			<param name="target.name" value="undeploy" />
 		</antcall>
 	</target>
+	
+	<target name="deploy-admin">			
+		<antcall target="deploy">
+			<param name="modules.list" value="cache-admin" />
+		</antcall>
+	</target>
 </project>

Modified: labs/shotoku/trunk/shotoku-cache/cache-admin/build.xml
===================================================================
--- labs/shotoku/trunk/shotoku-cache/cache-admin/build.xml	2007-08-17 10:44:46 UTC (rev 14332)
+++ labs/shotoku/trunk/shotoku-cache/cache-admin/build.xml	2007-08-17 11:14:45 UTC (rev 14333)
@@ -7,6 +7,7 @@
 	<path id="base.jars">
 		<fileset refid="jboss.lib.1" />
 		<fileset refid="jboss.lib.2" />
+		<fileset refid="jboss.lib.3" />
 	</path>
 
 	<!-- BUILD TARGETS -->

Modified: labs/shotoku/trunk/shotoku-cache/cache-admin/src/java/org/jboss/shotoku/cache/admin/AdminBean.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/cache-admin/src/java/org/jboss/shotoku/cache/admin/AdminBean.java	2007-08-17 10:44:46 UTC (rev 14332)
+++ labs/shotoku/trunk/shotoku-cache/cache-admin/src/java/org/jboss/shotoku/cache/admin/AdminBean.java	2007-08-17 11:14:45 UTC (rev 14333)
@@ -4,7 +4,9 @@
 import java.util.Date;
 import java.util.List;
 
+import javax.faces.context.FacesContext;
 import javax.management.MalformedObjectNameException;
+import javax.servlet.http.HttpServletRequest;
 
 import org.jboss.shotoku.cache.RenewableCacheItemData;
 import org.jboss.shotoku.cache.service.RenewableCacheServiceMBean;
@@ -18,6 +20,11 @@
 	private List<CacheItemBean> cacheItems;
 	private long newServiceInterval;
 	
+	public AdminBean() {
+		// For development only.
+		((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getSession().invalidate();
+	}
+	
 	public RenewableCacheServiceMBean getService() {
 		if (service == null) {
 			String mbean = getMbeanName();

Added: labs/shotoku/trunk/shotoku-cache/cache-admin/src/java/org/jboss/shotoku/cache/admin/WebFilesystemFilter.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/cache-admin/src/java/org/jboss/shotoku/cache/admin/WebFilesystemFilter.java	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/cache-admin/src/java/org/jboss/shotoku/cache/admin/WebFilesystemFilter.java	2007-08-17 11:14:45 UTC (rev 14333)
@@ -0,0 +1,148 @@
+package org.jboss.shotoku.cache.admin;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * A filter, which reads files from a filesystem and makes them visible to the
+ * application as deployed files --- useful for development. Specifically,
+ * if a request for a file is captured, the <code>repoAccessDir</code> init-parameter
+ * value is removed from the path, and the <code>realPath</code> init-parameter value
+ * is prepended to the path. The file referenced by the path is then included
+ * in the request. 
+ * 
+ * @author <a href="mailto:adam.warski at jboss.org">Adam Warski</a>
+ */
+public class WebFilesystemFilter implements Filter {
+	/**
+	 * Name of a directory to which files
+	 * will be copied; this will be a subdirectory of the deployment directory
+	 * of a web application using this filter.
+	 */
+	private final static String COPIED_TO_REPO_DIR = "copied-to-repo";
+
+	/**
+	 * Base path to a directory where files will
+	 * be copied; it's a subdirectory of a deployment directory created by the
+	 * app server.
+	 */
+	private String basePath;
+
+	/**
+	 * Directory, through which the filter is invoked (when files are requested).
+	 */
+	private String repoAccessDir;
+
+	/**
+	 * Length of repoAccessDir
+	 */
+	private int repoAccessDirLength;
+
+	/**
+	 * Real directory in the filesystem from which to read the files.
+	 */
+	private String realDir;
+
+	/**
+	 * Transferes all bytes from the given input stream to the given output
+	 * stream.
+	 *
+	 * @param is
+	 *            Input stream to read from.
+	 * @param os
+	 *            Output stream to write to.
+	 * @throws IOException In case of an IO exception.
+	 */
+	private void transfer(InputStream is, OutputStream os) throws IOException {
+		byte[] buffer = new byte[1024];
+		int read;
+		while ((read = is.read(buffer)) != -1) {
+			os.write(buffer, 0, read);
+		}
+	}
+
+	public void init(FilterConfig conf) {
+		repoAccessDir = conf.getInitParameter("repoAccessDir");
+		repoAccessDirLength = repoAccessDir.length();
+
+		realDir = conf.getInitParameter("realDir");
+
+		// Constructing the base path.
+		basePath = conf.getServletContext().getRealPath("") + File.separator
+				+ COPIED_TO_REPO_DIR;
+	}
+
+	public void doFilter(ServletRequest request, ServletResponse response,
+			FilterChain chain) throws IOException, ServletException {
+		if (request instanceof HttpServletRequest) {
+			HttpServletRequest httpRequest = (HttpServletRequest) request;
+
+			// Constructing the path of the requested path as relative to the
+			// content's repository root.
+			String requestURI = httpRequest.getRequestURI();
+			int indexOfRepoAccessDir = requestURI.indexOf(repoAccessDir);
+			if (indexOfRepoAccessDir == -1) {
+				chain.doFilter(request, response);
+				return;
+			}
+
+			String requestedFile = requestURI.substring(indexOfRepoAccessDir
+					+ repoAccessDirLength + 1);
+
+			// We have to replace .jsf with .jsp.
+			String realRequestedFile = requestedFile;
+			if (realRequestedFile.endsWith(".jsf")) {
+				realRequestedFile = realRequestedFile.replace(".jsf", ".jsp");
+			}
+
+			File realFile = new File(realDir + File.separator + realRequestedFile);
+
+			String filePath = basePath + File.separator + realRequestedFile;
+
+			InputStream in = null;
+			OutputStream out = null;
+
+			try {
+				File copyTo = new File(filePath);
+				copyTo.getParentFile().mkdirs();
+				copyTo.setLastModified(System.currentTimeMillis());
+
+				in = new FileInputStream(realFile);
+				out = new FileOutputStream(copyTo);
+
+				transfer(in, out);
+			} finally {
+				if (in != null) {
+					in.close();
+				}
+
+				if (out != null) {
+					out.close();
+				}
+			}
+
+			request.getRequestDispatcher(
+					File.separator + COPIED_TO_REPO_DIR + File.separator
+							+ requestedFile).include(request, response);
+		} else {
+			response.setContentType("text/html");
+			response.getWriter().write("Unsupported request class");
+		}
+	}
+
+	public void destroy() {
+
+	}
+}

Modified: labs/shotoku/trunk/shotoku-cache/cache-admin/src/web/WEB-INF/web.xml
===================================================================
--- labs/shotoku/trunk/shotoku-cache/cache-admin/src/web/WEB-INF/web.xml	2007-08-17 10:44:46 UTC (rev 14332)
+++ labs/shotoku/trunk/shotoku-cache/cache-admin/src/web/WEB-INF/web.xml	2007-08-17 11:14:45 UTC (rev 14333)
@@ -56,7 +56,29 @@
         <dispatcher>FORWARD</dispatcher>
         <dispatcher>INCLUDE</dispatcher>
     </filter-mapping>
+    
+    <!-- Filter for development -->
+    <filter>
+        <filter-name>filesFromRepoFilter</filter-name>
+        <filter-class>org.jboss.shotoku.cache.admin.WebFilesystemFilter</filter-class>
+        <init-param>
+            <param-name>repoAccessDir</param-name>
+            <param-value>pages</param-value>
+        </init-param>
+        <init-param>
+            <param-name>realDir</param-name>
+            <param-value>/home/adamw/shotoku/shotoku-cache/cache-admin/src/web/pages</param-value>
+        </init-param>
+    </filter>
 
+    <filter-mapping>
+        <filter-name>filesFromRepoFilter</filter-name>
+        <url-pattern>/pages/*</url-pattern>
+        <dispatcher>INCLUDE</dispatcher>
+        <dispatcher>FORWARD</dispatcher>
+        <dispatcher>REQUEST</dispatcher>
+    </filter-mapping>
+
 	<!-- Listener, that does all the startup work (configuration, init). -->
 	<listener>
 		<listener-class>

Added: labs/shotoku/trunk/shotoku-cache/cache-admin/src/web/pages/admin.css
===================================================================
--- labs/shotoku/trunk/shotoku-cache/cache-admin/src/web/pages/admin.css	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/cache-admin/src/web/pages/admin.css	2007-08-17 11:14:45 UTC (rev 14333)
@@ -0,0 +1,34 @@
+.header {
+    font-weight: bold;
+    font-size: large;
+}
+
+.header_panel {
+    text-align: center;	
+}
+
+.info_table {
+	width: 100%;
+}
+
+.info_table td {
+	width: 30%;
+	padding: 5px;
+	font-size: small;
+	vertical-align: top;
+}
+
+.messages {
+	margin-top: 10px;
+}
+
+.info_table .left_text {
+	
+	width: 70%;
+	text-align: right;	
+	font-weight: bold;
+}
+
+.info_table .right_text {
+	vertical-align: bottom;
+}
\ No newline at end of file

Modified: labs/shotoku/trunk/shotoku-cache/cache-admin/src/web/pages/admin.jsp
===================================================================
--- labs/shotoku/trunk/shotoku-cache/cache-admin/src/web/pages/admin.jsp	2007-08-17 10:44:46 UTC (rev 14332)
+++ labs/shotoku/trunk/shotoku-cache/cache-admin/src/web/pages/admin.jsp	2007-08-17 11:14:45 UTC (rev 14333)
@@ -5,15 +5,17 @@
 
 <html>
 	<head>
-	<title>Hello world page.</title>
+		<title>Hello world page.</title>
+		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
+		<link rel="stylesheet" href="admin.css" type="text/css" />	
 	</head>
 	<body>
 		<f:view>
-			<rich:panel>
-				<f:verbatim><h1>Shotoku cache administration</h1></f:verbatim>
+			<rich:panel styleClass="header_panel">
+				<h:outputText styleClass="header" value="Shotoku Cache Administration" />
 			</rich:panel>
 			
-			<rich:panel id="messages">
+			<rich:panel id="messages" styleClass="messages">
 				<h:messages />
 			</rich:panel>
 			
@@ -21,19 +23,34 @@
 				<a4j:poll interval="10000" reRender="information" />
 			</h:form>
 			
-			<h:panelGrid columns="3" width="100%" cellspacing="10">
+			<h:panelGrid columns="3" styleClass="info_table">
 					<rich:simpleTogglePanel switchType="client" label="Information">
-						<h:panelGrid columns="2" id="information">
+						<h:panelGrid columns="2" id="information" columnClasses="left_text,right_text">
 							<h:outputText value="Last update date: "/>
 							<h:outputText value="#{admin.serviceLastUpdateDate}" />
 								
-							<h:outputText value="Last update seconds ago: "/>
-							<h:outputText value="#{admin.serviceLastUpdateSecondsAgo}" />
+							<h:outputText value="Last update: "/>
+							<h:outputText value="#{admin.serviceLastUpdateSecondsAgo} seconds ago" />
+							
+							<h:outputText value="Current data packet queue size: "/>
+							<h:outputText value="#{admin.currentQueueSize}" />
 						</h:panelGrid>
 					</rich:simpleTogglePanel>
 					
 					<rich:simpleTogglePanel switchType="client" label="Statistics">
-
+						<h:panelGrid columns="2" columnClasses="left_text,right_text">
+							<h:outputText value="Total number of data packets processed: "/>
+							<h:outputText value="#{admin.statistics.numberOfPacketsProcessed}" />
+							
+							<h:outputText value="Number of data packets, which threw an exception during processing: "/>
+							<h:outputText value="#{admin.statistics.numberOfPacketsWithExceptions}" />
+							
+							<h:outputText value="Average waiting time of a data packet in the queue: "/>
+							<h:outputText value="#{admin.statistics.averagePacketTimeInQueue} ms" />
+							
+							<h:outputText value="Average processing time of a data packet: "/>
+							<h:outputText value="#{admin.statistics.averagePacketProcessingTime} ms" />
+						</h:panelGrid>
 					</rich:simpleTogglePanel>
 				
 					<rich:simpleTogglePanel switchType="client" label="Configuration">

Modified: labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/UpdateThread.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/UpdateThread.java	2007-08-17 10:44:46 UTC (rev 14332)
+++ labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/UpdateThread.java	2007-08-17 11:14:45 UTC (rev 14333)
@@ -50,16 +50,19 @@
             try {
                 data = queue.take();
 
+                long start = System.currentTimeMillis();
+                service.getStatistics().addPacketWaitingTime(start - data.getCreateTime());
+                
                 if (data instanceof SignalExitUpdateThreadData) {
                 	break;
                 }
                 
                 try {
                     data.execute();
-                    service.getStatistics().addPacketElapsedTime(System.currentTimeMillis() - data.getCreateTime(), false);
+                    service.getStatistics().addPacketProcessingTime(System.currentTimeMillis() - start, false);
                 } catch (Throwable t) {
                     log.error("Exception while executing an update thread data.", t);
-                    service.getStatistics().addPacketElapsedTime(System.currentTimeMillis() - data.getCreateTime(), true);
+                    service.getStatistics().addPacketProcessingTime(System.currentTimeMillis() - start, true);
                 }
             } catch (InterruptedException e) {
                 log.error("Update thread interrupted.", e);

Modified: labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/service/RenewableCacheStatistics.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/service/RenewableCacheStatistics.java	2007-08-17 10:44:46 UTC (rev 14332)
+++ labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/service/RenewableCacheStatistics.java	2007-08-17 11:14:45 UTC (rev 14333)
@@ -1,9 +1,16 @@
 package org.jboss.shotoku.cache.service;
 
+/**
+ * 
+ * 
+ * @author <a href="mailto:adam.warski at jboss.org">Adam Warski</a>
+ */
 public interface RenewableCacheStatistics {
-	public void addPacketElapsedTime(long elapsedTime, boolean exception);
+	public void addPacketWaitingTime(long elapsedTime);
+	public void addPacketProcessingTime(long elapsedTime, boolean exception);
 	
 	public long getAveragePacketTimeInQueue();
+	public long getAveragePacketProcessingTime();
 	public long getNumberOfPacketsProcessed();
 	public long getNumberOfPacketsWithExceptions();
 }

Modified: labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/service/RenewableCacheStatisticsImpl.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/service/RenewableCacheStatisticsImpl.java	2007-08-17 10:44:46 UTC (rev 14332)
+++ labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/service/RenewableCacheStatisticsImpl.java	2007-08-17 11:14:45 UTC (rev 14333)
@@ -1,29 +1,49 @@
 package org.jboss.shotoku.cache.service;
 
 public class RenewableCacheStatisticsImpl implements RenewableCacheStatistics {
-	private long allPackets;
+	private long allStartedPackets;
+	private long allProcessedPackets;
 	private long packetsWithErrors;
-	private long time;
+	private long totalProcessingTime;
+	private long totalWaitingTime;
 	
-	public void addPacketElapsedTime(long elapsedTime, boolean exception) {
-		time += elapsedTime;
-		allPackets++;
+	public void addPacketProcessingTime(long elapsedTime, boolean exception) {
+		totalProcessingTime += elapsedTime;
 		
+		allProcessedPackets++;
+		
 		if (exception) {
 			packetsWithErrors++;
 		}
 	}
 
+	public void addPacketWaitingTime(long elapsedTime) {
+		totalWaitingTime += elapsedTime;
+		
+		allStartedPackets++;
+	}
+
 	public long getAveragePacketTimeInQueue() {
-		return time/allPackets;
+		if (allStartedPackets == 0) {
+			return 0;
+		}
+		
+		return totalWaitingTime/allStartedPackets;
 	}
 
+	public long getAveragePacketProcessingTime() {
+		if (allProcessedPackets == 0) {
+			return 0;
+		}
+		
+		return totalProcessingTime/allProcessedPackets;
+	}
+
 	public long getNumberOfPacketsProcessed() {
-		return allPackets;
+		return allProcessedPackets;
 	}
 
 	public long getNumberOfPacketsWithExceptions() {
 		return packetsWithErrors;
 	}
-
 }




More information about the jboss-svn-commits mailing list