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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Aug 16 12:09:53 EDT 2007


Author: adamw
Date: 2007-08-16 12:09:53 -0400 (Thu, 16 Aug 2007)
New Revision: 14312

Added:
   labs/shotoku/trunk/shotoku-cache/cache-admin/src/java/org/jboss/shotoku/cache/admin/CacheItemBean.java
   labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/RenewableCacheItemData.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
Removed:
   labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/RenewableCacheItemConfiguration.java
   labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/service/RenewableCacheService.java
Modified:
   labs/shotoku/trunk/shotoku-cache/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/faces-config.xml
   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/RenewableCacheItem.java
   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/UpdateThreadData.java
   labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/service/DummyRenewableCacheService.java
   labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/service/RenewableCacheServiceMBean.java
   labs/shotoku/trunk/shotoku-cache/cache-service/src/java/org/jboss/shotoku/cache/service/RenewableCacheService.java
Log:
Admin panel - beans

Modified: labs/shotoku/trunk/shotoku-cache/build.xml
===================================================================
--- labs/shotoku/trunk/shotoku-cache/build.xml	2007-08-16 15:24:48 UTC (rev 14311)
+++ labs/shotoku/trunk/shotoku-cache/build.xml	2007-08-16 16:09:53 UTC (rev 14312)
@@ -44,7 +44,7 @@
 	</target>
 
 	<!-- Main tasks -->
-	<target name="clean">
+	<target name="clean" depends="undeploy">
 		<delete dir="${dist}" />
 		<antcall target="each-module">
 			<param name="target.name" value="clean" />
@@ -63,7 +63,7 @@
 		</antcall>
 	</target>
 
-	<target name="deploy" depends="dist,undeploy">
+	<target name="deploy" depends="dist">
 		<antcall target="each-module">
 			<param name="target.name" value="deploy" />
 		</antcall>

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-16 15:24:48 UTC (rev 14311)
+++ labs/shotoku/trunk/shotoku-cache/cache-admin/src/java/org/jboss/shotoku/cache/admin/AdminBean.java	2007-08-16 16:09:53 UTC (rev 14312)
@@ -1,17 +1,86 @@
 package org.jboss.shotoku.cache.admin;
 
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import javax.management.MalformedObjectNameException;
+
+import org.jboss.shotoku.cache.RenewableCacheItemData;
+import org.jboss.shotoku.cache.service.RenewableCacheServiceMBean;
+import org.jboss.shotoku.cache.service.RenewableCacheStatistics;
+import org.jboss.shotoku.tools.CacheTools;
+
 public class AdminBean {
-	private String testText;
+	private String mbeanName;
 
-	public String getTestText() {
-		return testText;
+	private RenewableCacheServiceMBean service;
+	private List<CacheItemBean> cacheItems;
+	private long newServiceInterval;
+	
+	public RenewableCacheServiceMBean getService() {
+		if (service == null) {
+			String mbean = getMbeanName();
+			if (mbean == null) {
+				mbean = CacheTools.DEFAULT_RENEWABLE_CACHE_MBEAN;
+			}
+			
+			try {
+				service = CacheTools.getService(mbean);
+			} catch (MalformedObjectNameException e) {
+				throw new RuntimeException(e);
+			}
+		}
+		
+		return service;
 	}
+	
+	public List<CacheItemBean> getCacheItems() {
+		if (cacheItems == null) {
+			cacheItems = new ArrayList<CacheItemBean>();
+			for (RenewableCacheItemData cacheItemData : getService().getCacheItemsData()) {
+				cacheItems.add(new CacheItemBean(cacheItemData));
+			}
+		}
+		
+		return cacheItems;
+	}
 
-	public void setTestText(String testText) {
-		this.testText = testText;
+	public String getMbeanName() {
+		return mbeanName;
 	}
 
-	public String getText() {
-		return "Hello world!";
+	public void setMbeanName(String mbeanName) {
+		this.mbeanName = mbeanName;
 	}
+	
+	public long getServiceLastUpdateSecondsAgo() {
+    	return (System.currentTimeMillis() - getService().getLastUpdate())/1000;
+    }
+	
+	public Date getServiceLastUpdateDate() {
+        return new Date(getService().getLastUpdate());
+    }
+	
+	public int getCurrentQueueSize() {
+		return getService().getCurrentQueueSize();
+	}
+	
+    public RenewableCacheStatistics getStatistics() {
+    	return getService().getStatistics();
+    }
+    
+    public long getServiceInterval() {
+    	return getService().getInterval();
+    }
+    
+    public void setServiceInterval(long newServiceInterval) {
+    	this.newServiceInterval = newServiceInterval;
+    }
+    
+    public String changeServiceInterval() {
+    	System.out.println("Changing interval to: " + newServiceInterval);
+    	
+    	return null;
+    }
 }

Added: labs/shotoku/trunk/shotoku-cache/cache-admin/src/java/org/jboss/shotoku/cache/admin/CacheItemBean.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/cache-admin/src/java/org/jboss/shotoku/cache/admin/CacheItemBean.java	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/cache-admin/src/java/org/jboss/shotoku/cache/admin/CacheItemBean.java	2007-08-16 16:09:53 UTC (rev 14312)
@@ -0,0 +1,43 @@
+package org.jboss.shotoku.cache.admin;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.shotoku.cache.RenewableCacheItemData;
+
+public class CacheItemBean {
+	private RenewableCacheItemData cacheItem;
+	private Set keysDuringUpdate;
+	private Set keysNotDuringUpdate;
+	private Map keysUpdates;
+	
+	@SuppressWarnings("unchecked")
+	public CacheItemBean(RenewableCacheItemData cacheItem) {
+		this.cacheItem = cacheItem;
+
+		keysDuringUpdate = cacheItem.getKeysDuringUpdate();
+		keysUpdates = cacheItem.getKeysUpdates();
+		keysNotDuringUpdate = keysUpdates.keySet();
+		keysNotDuringUpdate.removeAll(keysDuringUpdate);
+	}
+	
+	public String getName() {
+		return cacheItem.getClass().getName();
+	}
+	
+	public long getInterval() {
+		return cacheItem.getInterval();
+	}
+	
+	public Set getKeysDuringUpdate() {
+		return keysDuringUpdate;
+	}
+	
+	public Set getKeysNotDuringUpdate() {
+		return keysNotDuringUpdate;
+	}
+	
+	public Long getLastUpdateForKey(Object key) {
+		return (Long) keysUpdates.get(key);
+	}
+}

Modified: labs/shotoku/trunk/shotoku-cache/cache-admin/src/web/WEB-INF/faces-config.xml
===================================================================
--- labs/shotoku/trunk/shotoku-cache/cache-admin/src/web/WEB-INF/faces-config.xml	2007-08-16 15:24:48 UTC (rev 14311)
+++ labs/shotoku/trunk/shotoku-cache/cache-admin/src/web/WEB-INF/faces-config.xml	2007-08-16 16:09:53 UTC (rev 14312)
@@ -8,5 +8,9 @@
 		<managed-bean-name>admin</managed-bean-name>
 		<managed-bean-class>org.jboss.shotoku.cache.admin.AdminBean</managed-bean-class>
 		<managed-bean-scope>request</managed-bean-scope>
+		<managed-property>
+			<property-name>mbeanName</property-name>
+			<null-value/>
+		</managed-property>
 	</managed-bean>
 </faces-config>
\ No newline at end of file

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-16 15:24:48 UTC (rev 14311)
+++ labs/shotoku/trunk/shotoku-cache/cache-admin/src/web/WEB-INF/web.xml	2007-08-16 16:09:53 UTC (rev 14312)
@@ -1,9 +1,7 @@
-<?xml version="1.0"?>
-<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
-            http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
-         version="2.4">
+         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
 	<context-param>
 		<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
 		<param-value>server</param-value>
@@ -24,8 +22,11 @@
 		<param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
 		<param-value>true</param-value>
 	</context-param>
+	<context-param>
+        <param-name>org.ajax4jsf.SKIN</param-name>
+        <param-value>ruby</param-value>
+	</context-param>
 
-
 	<!-- WelcomeFile Filter -->
 	<!--
 		<filter>
@@ -44,16 +45,17 @@
 	-->
 
 	<filter>
-		<filter-name>ajax4jsf</filter-name>
-		<filter-class>org.ajax4jsf.Filter</filter-class>
-	</filter>
-	<filter-mapping>
-		<filter-name>ajax4jsf</filter-name>
-		<servlet-name>Faces Servlet</servlet-name>
-		<dispatcher>REQUEST</dispatcher>
-		<dispatcher>FORWARD</dispatcher>
-		<dispatcher>INCLUDE</dispatcher>
-	</filter-mapping>
+        <display-name>Ajax4jsf Filter</display-name>
+        <filter-name>ajax4jsf</filter-name>
+        <filter-class>org.ajax4jsf.Filter</filter-class>
+    </filter>
+    <filter-mapping>
+        <filter-name>ajax4jsf</filter-name>
+        <servlet-name>Faces Servlet</servlet-name>
+        <dispatcher>REQUEST</dispatcher>
+        <dispatcher>FORWARD</dispatcher>
+        <dispatcher>INCLUDE</dispatcher>
+    </filter-mapping>
 
 	<!-- Listener, that does all the startup work (configuration, init). -->
 	<listener>

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-16 15:24:48 UTC (rev 14311)
+++ labs/shotoku/trunk/shotoku-cache/cache-admin/src/web/pages/admin.jsp	2007-08-16 16:09:53 UTC (rev 14312)
@@ -1,6 +1,7 @@
 <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
 <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
 <%@ taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%>
+<%@ taglib uri="http://richfaces.ajax4jsf.org/rich" prefix="rich" %>
 
 <html>
 	<head>
@@ -8,14 +9,52 @@
 	</head>
 	<body>
 		<f:view>
-			<h1><h:outputText value="#{admin.text}" /></h1>
+			<rich:panel>
+				<f:verbatim><h1>Shotoku cache administration</h1></f:verbatim>
+			</rich:panel>
 			
+			<rich:panel id="messages">
+				<h:messages />
+			</rich:panel>
+			
 			<h:form>
-				<h:inputText size="50" value="#{admin.testText}">
-					<a4j:support event="onkeyup" reRender="rep" />
-				</h:inputText>
-				<h:outputText value="#{admin.testText}" id="rep" />
+				<a4j:poll interval="10000" reRender="information" />
 			</h:form>
+			
+			<h:panelGrid columns="3" width="100%" cellspacing="10">
+					<rich:simpleTogglePanel switchType="client" label="Information">
+						<h:panelGrid columns="2" id="information">
+							<h:outputText value="Last update date: "/>
+							<h:outputText value="#{admin.serviceLastUpdateDate}" />
+								
+							<h:outputText value="Last update seconds ago: "/>
+							<h:outputText value="#{admin.serviceLastUpdateSecondsAgo}" />
+						</h:panelGrid>
+					</rich:simpleTogglePanel>
+					
+					<rich:simpleTogglePanel switchType="client" label="Statistics">
+
+					</rich:simpleTogglePanel>
+				
+					<rich:simpleTogglePanel switchType="client" label="Configuration">
+					<h:form>
+						<h:panelGrid columns="2">
+							<h:outputText value="Interval: "/>
+							<h:inputText value="#{admin.serviceInterval}" id="Interval" required="true">
+								<f:validateLongRange minimum="1000" />
+							</h:inputText>
+							
+							<h:outputText value="" />
+							<a4j:commandButton value="Submit" action="#{admin.changeServiceInterval}" 
+								reRender="serviceIntervalError,messages" />
+						</h:panelGrid>
+						
+						<h:panelGroup id="serviceIntervalError">
+							<h:message for="Interval"/>
+						</h:panelGroup>
+					</h:form>
+					</rich:simpleTogglePanel>
+			</h:panelGrid>
 		</f:view>
 	</body>
 </html>

Modified: labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/RenewableCacheItem.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/RenewableCacheItem.java	2007-08-16 15:24:48 UTC (rev 14311)
+++ labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/RenewableCacheItem.java	2007-08-16 16:09:53 UTC (rev 14312)
@@ -58,7 +58,7 @@
  * 
  * @author <a href="mailto:adam.warski at jboss.org">Adam Warski</a>
  */
-public abstract class RenewableCacheItem<K, T> implements RenewableCacheItemConfiguration<K> {
+public abstract class RenewableCacheItem<K, T> implements RenewableCacheItemData<K> {
 	private final Logger log = Logger.getLogger(RenewableCacheItem.class);
 	
     private Fqn fqn;

Deleted: labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/RenewableCacheItemConfiguration.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/RenewableCacheItemConfiguration.java	2007-08-16 15:24:48 UTC (rev 14311)
+++ labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/RenewableCacheItemConfiguration.java	2007-08-16 16:09:53 UTC (rev 14312)
@@ -1,97 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat                                               *
- * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
- * contributors as indicated by the @authors tag. See the                     *
- * copyright.txt in the distribution for a full listing of                    *
- * individual contributors.                                                   *
- *                                                                            *
- * This is free software; you can redistribute it and/or modify it            *
- * under the terms of the GNU Lesser General Public License as                *
- * published by the Free Software Foundation; either version 2.1 of           *
- * the License, or (at your option) any later version.                        *
- *                                                                            *
- * This software is distributed in the hope that it will be useful,           *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           *
- * Lesser General Public License for more details.                            *
- *                                                                            *
- * You should have received a copy of the GNU Lesser General Public           *
- * License along with this software; if not, write to the Free                *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
- ******************************************************************************/
-package org.jboss.shotoku.cache;
-
-import java.util.Map;
-import java.util.Set;
-
-import org.jboss.cache.Fqn;
-import org.jboss.shotoku.cache.service.RenewableCacheServiceMBean;
-
-/**
- * Configuration data of a cache item.
- * @param <K> Type of the key of the objects held in cache. The keys
- * should bahave well as map keys (most probably, the hashCode() and
- * equals() methods should be overriden).
- * @author <a href="mailto:adam.warski at jboss.org">Adam Warski</a>
- */
-public interface RenewableCacheItemConfiguration<K> {
-	/**
-	 * 
-	 * @return A fqn of a TreeCache node associated with this cache item. This is a node in which
-	 * data will be kept.
-	 */
-	public Fqn getFqn();
-	
-	/**
-	 * 
-	 * @return Interval at which the update operation will be executed.
-     * Effectively, the interval will be rounded to the nearest multiplicity of
-     * the service update thread interval. The interval should be given in milliseconds.
-     * If it is 0, the {@link RenewableCacheItem#update()} method will be executed on every service
-     * thread update.
-	 */
-	public long getInterval();
-	/**
-	 * 
-	 * @param interval Interval at which the update operation will be executed.
-     * Effectively, the interval will be rounded to the nearest multiplicity of
-     * the service update thread interval. The interval should be given in milliseconds.
-     * If it is 0, the {@link RenewableCacheItem#update()} method will be executed on every service
-     * thread update.
-	 */
-	public void setInterval(long interval);
-	
-	/**
-	 * 
-	 * @return How long, at a maximum, an update method for a key can last. If this
-     * value is non-zero, and is exceeded, a monitoring thread will interupt the update.
-	 */
-	public long getTimeout();
-	/**
-	 * 
-	 * @param timeout How long, at a maximum, an update method for a key can last. If this
-     * value is non-zero, and is exceeded, a monitoring thread will interupt the update.
-	 */
-	public void setTimeout(long timeout);
-	
-	/**
-	 * 
-	 * @return Name of an mbean implementing the {@link RenewableCacheServiceMBean} interface, associated
-	 * with this cache item.
-	 */
-	public String getMbeanName();
-	
-	/**
-	 * 
-	 * @return A map of keys, which are handeled by this cache item, and corresponding last
-	 * update times.
-	 */
-	public Map<K, Long> getKeysUpdates();
-	
-	/**
-	 * 
-	 * @return A set of keys, which are currently being updated.
-	 */
-	public Set<K> getKeysDuringUpdate();
-}

Added: labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/RenewableCacheItemData.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/RenewableCacheItemData.java	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/RenewableCacheItemData.java	2007-08-16 16:09:53 UTC (rev 14312)
@@ -0,0 +1,97 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat                                               *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
+ * contributors as indicated by the @authors tag. See the                     *
+ * copyright.txt in the distribution for a full listing of                    *
+ * individual contributors.                                                   *
+ *                                                                            *
+ * This is free software; you can redistribute it and/or modify it            *
+ * under the terms of the GNU Lesser General Public License as                *
+ * published by the Free Software Foundation; either version 2.1 of           *
+ * the License, or (at your option) any later version.                        *
+ *                                                                            *
+ * This software is distributed in the hope that it will be useful,           *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           *
+ * Lesser General Public License for more details.                            *
+ *                                                                            *
+ * You should have received a copy of the GNU Lesser General Public           *
+ * License along with this software; if not, write to the Free                *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
+ ******************************************************************************/
+package org.jboss.shotoku.cache;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.cache.Fqn;
+import org.jboss.shotoku.cache.service.RenewableCacheServiceMBean;
+
+/**
+ * Configuration data of a cache item.
+ * @param <K> Type of the key of the objects held in cache. The keys
+ * should bahave well as map keys (most probably, the hashCode() and
+ * equals() methods should be overriden).
+ * @author <a href="mailto:adam.warski at jboss.org">Adam Warski</a>
+ */
+public interface RenewableCacheItemData<K> {
+	/**
+	 * 
+	 * @return A fqn of a TreeCache node associated with this cache item. This is a node in which
+	 * data will be kept.
+	 */
+	public Fqn getFqn();
+	
+	/**
+	 * 
+	 * @return Interval at which the update operation will be executed.
+     * Effectively, the interval will be rounded to the nearest multiplicity of
+     * the service update thread interval. The interval should be given in milliseconds.
+     * If it is 0, the {@link RenewableCacheItem#update()} method will be executed on every service
+     * thread update.
+	 */
+	public long getInterval();
+	/**
+	 * 
+	 * @param interval Interval at which the update operation will be executed.
+     * Effectively, the interval will be rounded to the nearest multiplicity of
+     * the service update thread interval. The interval should be given in milliseconds.
+     * If it is 0, the {@link RenewableCacheItem#update()} method will be executed on every service
+     * thread update.
+	 */
+	public void setInterval(long interval);
+	
+	/**
+	 * 
+	 * @return How long, at a maximum, an update method for a key can last. If this
+     * value is non-zero, and is exceeded, a monitoring thread will interupt the update.
+	 */
+	public long getTimeout();
+	/**
+	 * 
+	 * @param timeout How long, at a maximum, an update method for a key can last. If this
+     * value is non-zero, and is exceeded, a monitoring thread will interupt the update.
+	 */
+	public void setTimeout(long timeout);
+	
+	/**
+	 * 
+	 * @return Name of an mbean implementing the {@link RenewableCacheServiceMBean} interface, associated
+	 * with this cache item.
+	 */
+	public String getMbeanName();
+	
+	/**
+	 * 
+	 * @return A map of keys, which are handeled by this cache item, and corresponding last
+	 * update times.
+	 */
+	public Map<K, Long> getKeysUpdates();
+	
+	/**
+	 * 
+	 * @return A set of keys, which are currently being updated.
+	 */
+	public Set<K> getKeysDuringUpdate();
+}

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-16 15:24:48 UTC (rev 14311)
+++ labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/UpdateThread.java	2007-08-16 16:09:53 UTC (rev 14312)
@@ -35,9 +35,11 @@
     private static final Logger log = Logger.getLogger(UpdateThread.class);
     
     private BlockingQueue<UpdateThreadData> queue;
+    private RenewableCacheServiceMBean service;
 
     public UpdateThread(RenewableCacheServiceMBean service, LinkedBlockingQueue<UpdateThreadData> queue) {
         this.queue = queue;
+        this.service = service;
 
         setDaemon(true);
     }
@@ -54,10 +56,11 @@
                 
                 try {
                     data.execute();
+                    service.getStatistics().addPacketElapsedTime(System.currentTimeMillis() - data.getCreateTime(), false);
                 } catch (Throwable t) {
                     log.error("Exception while executing an update thread data.", t);
+                    service.getStatistics().addPacketElapsedTime(System.currentTimeMillis() - data.getCreateTime(), true);
                 }
-
             } catch (InterruptedException e) {
                 log.error("Update thread interrupted.", e);
             }

Modified: labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/UpdateThreadData.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/UpdateThreadData.java	2007-08-16 15:24:48 UTC (rev 14311)
+++ labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/UpdateThreadData.java	2007-08-16 16:09:53 UTC (rev 14312)
@@ -27,5 +27,15 @@
  * @author <a href="mailto:adam.warski at jboss.org">Adam Warski</a>
  */
 public abstract class UpdateThreadData {
-    public abstract void execute();
+	private long createTime;
+	
+    public UpdateThreadData() {
+		createTime = System.currentTimeMillis();
+	}
+
+	public long getCreateTime() {
+		return createTime;
+	}
+
+	public abstract void execute();
 }

Modified: labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/service/DummyRenewableCacheService.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/service/DummyRenewableCacheService.java	2007-08-16 15:24:48 UTC (rev 14311)
+++ labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/service/DummyRenewableCacheService.java	2007-08-16 16:09:53 UTC (rev 14312)
@@ -7,7 +7,7 @@
 import org.jboss.cache.Fqn;
 import org.jboss.cache.TreeCacheMBean;
 import org.jboss.shotoku.cache.RenewableCacheItem;
-import org.jboss.shotoku.cache.RenewableCacheItemConfiguration;
+import org.jboss.shotoku.cache.RenewableCacheItemData;
 import org.jboss.shotoku.cache.UpdateThreadData;
 
 /**
@@ -88,7 +88,15 @@
 	public void update() {
 	}
 
-	public Set<? extends RenewableCacheItemConfiguration> getCacheItemsConfigurations() {
+	public Set<? extends RenewableCacheItemData> getCacheItemsData() {
 		return null;
 	}
+
+	public int getCurrentQueueSize() {
+		return 0;
+	}
+
+	public RenewableCacheStatistics getStatistics() {
+		return null;
+	}
 }

Deleted: labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/service/RenewableCacheService.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/service/RenewableCacheService.java	2007-08-16 15:24:48 UTC (rev 14311)
+++ labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/service/RenewableCacheService.java	2007-08-16 16:09:53 UTC (rev 14312)
@@ -1,242 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat                                               *
- * Copyright 2006, Red Hat Middleware, LLC, and individual                    *
- * contributors as indicated by the @authors tag. See the                     *
- * copyright.txt in the distribution for a full listing of                    *
- * individual contributors.                                                   *
- *                                                                            *
- * This is free software; you can redistribute it and/or modify it            *
- * under the terms of the GNU Lesser General Public License as                *
- * published by the Free Software Foundation; either version 2.1 of           *
- * the License, or (at your option) any later version.                        *
- *                                                                            *
- * This software is distributed in the hope that it will be useful,           *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           *
- * Lesser General Public License for more details.                            *
- *                                                                            *
- * You should have received a copy of the GNU Lesser General Public           *
- * License along with this software; if not, write to the Free                *
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
- ******************************************************************************/
-package org.jboss.shotoku.cache.service;
-
-import org.jboss.cache.CacheException;
-import org.jboss.cache.Fqn;
-import org.jboss.cache.TreeCacheMBean;
-import org.jboss.shotoku.cache.RenewableCacheItem;
-import org.jboss.shotoku.cache.RenewableCacheItemConfiguration;
-import org.jboss.shotoku.cache.SignalExitUpdateThreadData;
-import org.jboss.shotoku.cache.UpdateThread;
-import org.jboss.shotoku.cache.UpdateThreadData;
-import org.jboss.shotoku.tools.ConcurrentSet;
-import org.jboss.shotoku.tools.ConcurrentHashSet;
-import org.jboss.shotoku.tools.CacheTools;
-import org.apache.log4j.Logger;
-
-import java.util.Calendar;
-import java.util.Date;
-import java.util.Set;
-import java.util.concurrent.LinkedBlockingQueue;
-
-/**
- * 
- * @author <a href="mailto:adam.warski at jboss.org">Adam Warski</a>
- */
-public class RenewableCacheService implements RenewableCacheServiceMBean {
-    private final static Logger log = Logger.getLogger(RenewableCacheServiceMBean.class);
-    
-    private TreeCacheMBean treeCache;
-    private long interval;
-    private long lastUpdate;
-    private Thread updateThread;
-    
-    /*
-     * Service-handling functions.
-     */
-
-    public void start() {
-    	log.info("Starting main update thread.");
-    	
-    	startUpdateThread();
-    }
-
-    public void stop() {
-        getUpdateThread().interrupt();
-        
-        log.info("Signaled the main update thread to stop.");
-    }
-    
-    /*
-     * 
-     */
-    
-	public TreeCacheMBean getTreeCache() {
-		return treeCache;
-	}
-
-	public void setTreeCache(TreeCacheMBean treeCache) {
-		this.treeCache = treeCache;
-	}
-
-	public long getInterval() {
-		return interval;
-	}
-
-	public void setInterval(long interval) {
-		this.interval = interval;
-	}
-
-	public long getLastUpdate() {
-		return lastUpdate;
-	}
-
-	public void setLastUpdate(long lastUpdate) {
-		this.lastUpdate = lastUpdate;
-	}
-	
-	public long lastUpdateSecondsAgo() {
-    	return (System.currentTimeMillis() - getLastUpdate())/1000;
-    }
-	
-	public Date lastUpdateDate() {
-        return new Date(getLastUpdate());
-    }
-	
-	public Thread getUpdateThread() {
-		return updateThread;
-	}
-
-	public void setUpdateThread(Thread updateThread) {
-		this.updateThread = updateThread;
-	}
-	
-	/*
-	 * 
-	 */
-
-	public void startUpdateThread() {
-        Thread ut = new Thread() {
-            {
-                setDaemon(true);
-            }
-
-            public void run() {
-                while (true) {
-                    try {
-                        sleep(getInterval());
-                    } catch (InterruptedException e) {
-                    	// Quit.
-                        log.info("Stopping update thread for " + getName() + " (interrupted).");
-                        return;
-                    }
-
-                    try {
-                        update();
-                    } catch (Throwable t) {
-                        // Making sure that an exception won't stop the thread.
-                        log.error("Update method for " + getName() + " threw an exception.", t);
-                    }
-
-                    setLastUpdate(Calendar.getInstance().getTimeInMillis());
-                }
-            }
-        };
-        
-        ut.start();
-        setUpdateThread(ut);
-    }
-	
-    /*
-     * Cache handling
-     */
-
-    private final ConcurrentSet<RenewableCacheItem> cacheItems =
-            new ConcurrentHashSet<RenewableCacheItem>();
-
-	public Object get(Fqn fqn, Object key) throws CacheException {
-		return treeCache.get(fqn, key);
-	}
-
-	public void put(Fqn fqn, Object key, Object o) throws CacheException {
-		treeCache.put(fqn, key, o);
-	}
-
-	public void remove(Fqn fqn, Object key) throws CacheException {
-		treeCache.remove(fqn, key);
-	}
-
-    public void register(RenewableCacheItem cacheItem) {
-        cacheItems.add(cacheItem);
-    }
-    
-    public void unregister(RenewableCacheItem cacheItem) throws CacheException {
-    	cacheItems.remove(cacheItem);
-    	
-    	for (Object key : cacheItem.getKeysUpdates().keySet()) {
-    		remove(cacheItem.getFqn(), key);
-    	}
-    }
-   
-    public Set<? extends RenewableCacheItemConfiguration> getCacheItemsConfigurations() {
-		return cacheItems;
-	}
-
-	private int counter = 0;
-    private final Object counterSync = new Object();
-
-    public Fqn generateNextFqn() {
-        int c;
-        synchronized(counterSync) { c = counter++; }
-
-        return new Fqn(new Object[] {CacheTools.GENERATED_FQN_BASE, c});
-    }
-
-    /*
-     * Update threads management.
-     */
-
-    private final LinkedBlockingQueue<UpdateThreadData> updateThreadDataQueue =
-        new LinkedBlockingQueue<UpdateThreadData>();
-    
-    private int updateThreadCount;
-
-    public void addUpdateThreadData(UpdateThreadData data) {
-    	updateThreadDataQueue.offer(data);
-    }
-    
-    public int getUpdateThreadCount() {
-        return updateThreadCount;
-    }
-
-    public synchronized void setUpdateThreadCount(int n) {
-		if (updateThreadCount < n) {
-			for (int i = updateThreadCount; i < n; i++) {
-				UpdateThread ut = new UpdateThread(this, updateThreadDataQueue);
-				ut.start();
-			}
-		} else if (n < updateThreadCount) {
-			for (int i = updateThreadCount; i > n; i--) {
-				updateThreadDataQueue.offer(new SignalExitUpdateThreadData());
-			}
-		}
-
-		log.info("Update thread count set to: " + n + ".");
-		updateThreadCount = n;
-	}
-
-    /*
-	 * Update function.
-	 */
-
-    public void update() {
-        for (RenewableCacheItem sci : cacheItems) {
-            try {
-                sci.update();
-            } catch (Throwable t) {
-                log.error("Exception while updating a cache item.", t);
-            }
-        }
-    }
-}

Modified: labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/service/RenewableCacheServiceMBean.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/service/RenewableCacheServiceMBean.java	2007-08-16 15:24:48 UTC (rev 14311)
+++ labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/service/RenewableCacheServiceMBean.java	2007-08-16 16:09:53 UTC (rev 14312)
@@ -22,14 +22,13 @@
  ******************************************************************************/
 package org.jboss.shotoku.cache.service;
 
-import java.util.Date;
 import java.util.Set;
 
 import org.jboss.cache.CacheException;
 import org.jboss.cache.Fqn;
 import org.jboss.cache.TreeCacheMBean;
 import org.jboss.shotoku.cache.RenewableCacheItem;
-import org.jboss.shotoku.cache.RenewableCacheItemConfiguration;
+import org.jboss.shotoku.cache.RenewableCacheItemData;
 import org.jboss.shotoku.cache.UpdateThreadData;
 
 /**
@@ -47,7 +46,10 @@
     public Fqn generateNextFqn();
 
     public void addUpdateThreadData(UpdateThreadData data);
+    public int getCurrentQueueSize(); 
     
+    public RenewableCacheStatistics getStatistics();
+    
     public TreeCacheMBean getTreeCache();
 	public void setTreeCache(TreeCacheMBean treeCache);
 	
@@ -57,13 +59,10 @@
 	public long getLastUpdate();
 	public void setLastUpdate(long lastUpdate);
 	
-	public long lastUpdateSecondsAgo();
-	public Date lastUpdateDate();
-	
 	public int getUpdateThreadCount();
     public void setUpdateThreadCount(int n);
     
-    public Set<? extends RenewableCacheItemConfiguration> getCacheItemsConfigurations();
+    public Set<? extends RenewableCacheItemData> getCacheItemsData();
     
     public void update();
     

Added: 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	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/service/RenewableCacheStatistics.java	2007-08-16 16:09:53 UTC (rev 14312)
@@ -0,0 +1,9 @@
+package org.jboss.shotoku.cache.service;
+
+public interface RenewableCacheStatistics {
+	public void addPacketElapsedTime(long elapsedTime, boolean exception);
+	
+	public long getAveragePacketTimeInQueue();
+	public long getNumberOfPacketsProcessed();
+	public long getNumberOfPacketsWithExceptions();
+}

Added: 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	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/service/RenewableCacheStatisticsImpl.java	2007-08-16 16:09:53 UTC (rev 14312)
@@ -0,0 +1,29 @@
+package org.jboss.shotoku.cache.service;
+
+public class RenewableCacheStatisticsImpl implements RenewableCacheStatistics {
+	private long allPackets;
+	private long packetsWithErrors;
+	private long time;
+	
+	public void addPacketElapsedTime(long elapsedTime, boolean exception) {
+		time += elapsedTime;
+		allPackets++;
+		
+		if (exception) {
+			packetsWithErrors++;
+		}
+	}
+
+	public long getAveragePacketTimeInQueue() {
+		return time/allPackets;
+	}
+
+	public long getNumberOfPacketsProcessed() {
+		return allPackets;
+	}
+
+	public long getNumberOfPacketsWithExceptions() {
+		return packetsWithErrors;
+	}
+
+}

Modified: labs/shotoku/trunk/shotoku-cache/cache-service/src/java/org/jboss/shotoku/cache/service/RenewableCacheService.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/cache-service/src/java/org/jboss/shotoku/cache/service/RenewableCacheService.java	2007-08-16 15:24:48 UTC (rev 14311)
+++ labs/shotoku/trunk/shotoku-cache/cache-service/src/java/org/jboss/shotoku/cache/service/RenewableCacheService.java	2007-08-16 16:09:53 UTC (rev 14312)
@@ -26,7 +26,7 @@
 import org.jboss.cache.Fqn;
 import org.jboss.cache.TreeCacheMBean;
 import org.jboss.shotoku.cache.RenewableCacheItem;
-import org.jboss.shotoku.cache.RenewableCacheItemConfiguration;
+import org.jboss.shotoku.cache.RenewableCacheItemData;
 import org.jboss.shotoku.cache.SignalExitUpdateThreadData;
 import org.jboss.shotoku.cache.UpdateThread;
 import org.jboss.shotoku.cache.UpdateThreadData;
@@ -36,7 +36,6 @@
 import org.apache.log4j.Logger;
 
 import java.util.Calendar;
-import java.util.Date;
 import java.util.Set;
 import java.util.concurrent.LinkedBlockingQueue;
 
@@ -51,6 +50,7 @@
     private long interval;
     private long lastUpdate;
     private Thread updateThread;
+    private RenewableCacheStatistics statistics;
     
     /*
      * Service-handling functions.
@@ -60,6 +60,8 @@
     	log.info("Starting main update thread.");
     	
     	startUpdateThread();
+    	
+    	statistics = new RenewableCacheStatisticsImpl();
     }
 
     public void stop() {
@@ -96,14 +98,6 @@
 		this.lastUpdate = lastUpdate;
 	}
 	
-	public long lastUpdateSecondsAgo() {
-    	return (System.currentTimeMillis() - getLastUpdate())/1000;
-    }
-	
-	public Date lastUpdateDate() {
-        return new Date(getLastUpdate());
-    }
-	
 	public Thread getUpdateThread() {
 		return updateThread;
 	}
@@ -112,6 +106,10 @@
 		this.updateThread = updateThread;
 	}
 	
+	public RenewableCacheStatistics getStatistics() {
+		return statistics;
+	}
+	
 	/*
 	 * 
 	 */
@@ -179,7 +177,7 @@
     	}
     }
    
-    public Set<? extends RenewableCacheItemConfiguration> getCacheItemsConfigurations() {
+    public Set<? extends RenewableCacheItemData> getCacheItemsData() {
 		return cacheItems;
 	}
 
@@ -225,6 +223,10 @@
 		log.info("Update thread count set to: " + n + ".");
 		updateThreadCount = n;
 	}
+    
+    public int getCurrentQueueSize() {
+    	return updateThreadDataQueue.size();
+    }
 
     /*
 	 * Update function.




More information about the jboss-svn-commits mailing list