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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Aug 22 17:00:58 EDT 2007


Author: adamw
Date: 2007-08-22 17:00:58 -0400 (Wed, 22 Aug 2007)
New Revision: 14454

Added:
   labs/shotoku/trunk/shotoku-cache/cache-admin/src/java/org/jboss/shotoku/cache/admin/CacheFacesTools.java
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/CacheItemBean.java
   labs/shotoku/trunk/shotoku-cache/cache-admin/src/web/pages/admin.css
   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/RenewableCacheItemData.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/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-base/src/java/org/jboss/shotoku/tools/CacheTools.java
   labs/shotoku/trunk/shotoku-cache/cache-service/src/java/org/jboss/shotoku/cache/service/RenewableCacheService.java
   labs/shotoku/trunk/shotoku-cache/cache-test/src/java/org/jboss/shotoku/cache/test/TestServlet.java
Log:


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-22 20:24:49 UTC (rev 14453)
+++ labs/shotoku/trunk/shotoku-cache/cache-admin/src/java/org/jboss/shotoku/cache/admin/AdminBean.java	2007-08-22 21:00:58 UTC (rev 14454)
@@ -1,11 +1,12 @@
 package org.jboss.shotoku.cache.admin;
 
-import java.text.DateFormat;
 import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.Date;
 import java.util.List;
 
-import javax.faces.application.FacesMessage;
+import javax.faces.component.UIData;
 import javax.faces.context.FacesContext;
 import javax.management.MalformedObjectNameException;
 import javax.servlet.http.HttpServletRequest;
@@ -23,6 +24,8 @@
 	private long newServiceInterval;
 	private int newUpdateThreadCount;
 	
+	private List<String> currentAlerts;
+	
 	public AdminBean() {
 		// For development only.
 		((HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest()).getSession().invalidate();
@@ -45,12 +48,40 @@
 		return service;
 	}
 	
+	
+	private final static Comparator<CacheItemBean> cacheItemBeanComparator = new Comparator<CacheItemBean>() {
+		public int compare(CacheItemBean arg0, CacheItemBean arg1) {
+			int id1 = arg0.getId();
+			int id2 = arg1.getId();
+			
+			if (id1 < id2) {
+				return -1;
+			}
+			
+			if (id1 == id2) {
+				return 0;
+			}
+			
+			return 1;
+		}
+		
+	};
+	
 	public List<CacheItemBean> getCacheItems() {
 		if (cacheItems == null) {
+			currentAlerts = new ArrayList<String>();
 			cacheItems = new ArrayList<CacheItemBean>();
+			
 			for (RenewableCacheItemData<?> cacheItemData : getService().getCacheItemsData()) {
-				cacheItems.add(new CacheItemBean(cacheItemData, getService()));
+				CacheItemBean cacheItemBean = new CacheItemBean(cacheItemData, getService(), this);
+				cacheItems.add(cacheItemBean);
+				
+				if (cacheItemBean.isAlerted()) {
+					currentAlerts.add(cacheItemBean.getName());
+				}
 			}
+			
+			Collections.sort(cacheItems, cacheItemBeanComparator);
 		}
 		
 		return cacheItems;
@@ -80,6 +111,14 @@
     	return getService().getStatistics();
     }
     
+    public int getBusyThreadCount() {
+    	return getService().getBusyThreadCount();
+    }
+    
+    public int getIdleThreadCount() {
+    	return getService().getIdleThreadCount();
+    }
+    
     public int getUpdateThreadCount() {
     	return getService().getUpdateThreadCount();
     }
@@ -103,11 +142,31 @@
     	Date date = new Date();
     	date.toString();
     	
-    	FacesContext.getCurrentInstance().addMessage(null, 
-    			new FacesMessage("(" + DateFormat.getTimeInstance(DateFormat.SHORT).format(new Date()) + "): " +
-    			"Service interval and update " +
-    			"thread count changed successfully."));
+    	CacheFacesTools.addTimedFacesMessage("Service interval and update " +
+    			"thread count changed successfully.");
     	
     	return null;
     }
+    
+    public List<String> getCurrentAlerts() {
+    	getCacheItems();
+    	return currentAlerts;
+    }
+    
+    public int getCurrentAlertsSize() {
+    	return getCurrentAlerts().size();
+    }
+    
+    /**
+     * Data table of a cache item. Used to retrieve a key, which has been selected.
+     */
+	private UIData keysInUpdateData;
+	
+	public UIData getKeysInUpdateData() {
+		return keysInUpdateData;
+	}
+
+	public void setKeysInUpdateData(UIData keysInUpdateData) {
+		this.keysInUpdateData = keysInUpdateData;
+	}
 }

Added: labs/shotoku/trunk/shotoku-cache/cache-admin/src/java/org/jboss/shotoku/cache/admin/CacheFacesTools.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/cache-admin/src/java/org/jboss/shotoku/cache/admin/CacheFacesTools.java	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/cache-admin/src/java/org/jboss/shotoku/cache/admin/CacheFacesTools.java	2007-08-22 21:00:58 UTC (rev 14454)
@@ -0,0 +1,18 @@
+package org.jboss.shotoku.cache.admin;
+
+import java.text.DateFormat;
+import java.util.Date;
+
+import javax.faces.application.FacesMessage;
+import javax.faces.context.FacesContext;
+
+public class CacheFacesTools {
+	/**
+	 * Adds a global faces message, prepending the current time.
+	 * @param msg Message to add.
+	 */
+	public static void addTimedFacesMessage(String msg) {
+		FacesContext.getCurrentInstance().addMessage(null,
+    			new FacesMessage("(" + DateFormat.getTimeInstance(DateFormat.SHORT).format(new Date()) + "): " + msg, ""));
+	}
+}

Modified: 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	2007-08-22 20:24:49 UTC (rev 14453)
+++ labs/shotoku/trunk/shotoku-cache/cache-admin/src/java/org/jboss/shotoku/cache/admin/CacheItemBean.java	2007-08-22 21:00:58 UTC (rev 14454)
@@ -22,10 +22,17 @@
 	 */
 	private boolean alerted;
 	
-	public CacheItemBean(RenewableCacheItemData<?> cacheItem, RenewableCacheServiceMBean service) {
+	private int newId;
+	private long newInterval;
+	
+	private AdminBean adminBean;
+	
+	public CacheItemBean(RenewableCacheItemData<?> cacheItem, RenewableCacheServiceMBean service, AdminBean adminBean) {
 		this.cacheItem = cacheItem;
 		this.service = service;
 		
+		this.adminBean = adminBean;
+		
 		keysDuringUpdate = new ArrayList<Object>(cacheItem.getKeysDuringUpdate());
 		
 		//
@@ -90,16 +97,56 @@
 		return alerted;
 	}
 	
+	public int getId() {
+		return cacheItem.getId();
+	}
+	
+	public void setId(int id) {
+		newId = id;
+	}
+	
 	public long getInterval() {
 		return cacheItem.getInterval();
 	}
 	
 	public void setInterval(long interval) {
+		newInterval = interval;
 		System.out.println("Setting interval to: " + interval);
 	}
 	
+	private boolean checkId() {
+		if (newId != getId()) {
+			CacheFacesTools.addTimedFacesMessage("New or removed cache items. Please " +
+					"refresh the page and try again.");
+			return false;
+		}
+		
+		return true;
+	}
+	
 	public String updateConfig() {
-		System.out.println("CACHE ITEM: " + getName());
+		if (!checkId()) {
+			return null;
+		}
+		
+		cacheItem.setInterval(newInterval);
+		
+		CacheFacesTools.addTimedFacesMessage("Cache item " + getName() + " interval changed successfully.");
+		
 		return null;
 	}
+
+	public String reset() {
+		if (!checkId()) {
+			return null;
+		}
+		
+		Object key = adminBean.getKeysInUpdateData().getRowData();
+		
+		cacheItem.resetKey(key);
+		
+		CacheFacesTools.addTimedFacesMessage("Key " + key + " has been reset.");
+		
+		return null;
+	}
 }

Modified: labs/shotoku/trunk/shotoku-cache/cache-admin/src/web/pages/admin.css
===================================================================
--- labs/shotoku/trunk/shotoku-cache/cache-admin/src/web/pages/admin.css	2007-08-22 20:24:49 UTC (rev 14453)
+++ labs/shotoku/trunk/shotoku-cache/cache-admin/src/web/pages/admin.css	2007-08-22 21:00:58 UTC (rev 14454)
@@ -9,6 +9,11 @@
 	margin-top: 10px;
 }
 
+.header_messages {
+	font-size: x-small;
+	text-align: left;
+}
+
 .info_table {
 	width: 100%;
 }
@@ -66,13 +71,10 @@
 
 .note_panel {
 	text-align: left;
+    margin-bottom: 10px;
+	margin-top: 10px;
 }
 
-.note_panel h1 {
-	font-weight: bold;
-	font-size: small;
-}
-
 .note_panel ul {
 	font-size: x-small;
 }
@@ -80,4 +82,8 @@
 .alert {
 	color: red;
 	font-weight: bold;
+}
+
+.alert_panel {
+	margin-top: 5px;
 }
\ 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-22 20:24:49 UTC (rev 14453)
+++ labs/shotoku/trunk/shotoku-cache/cache-admin/src/web/pages/admin.jsp	2007-08-22 21:00:58 UTC (rev 14454)
@@ -15,12 +15,9 @@
 				<h:outputText styleClass="header" value="Shotoku Cache Administration" />
 			</rich:panel>
 			
-			<rich:panel id="messages" styleClass="note_panel">
-				<h:messages globalOnly="true" />
-			</rich:panel>
-			
 			<h:form>
-				<a4j:poll interval="5000" reRender="information,statistics,cacheitems" />
+				<a4j:poll interval="5000" 
+					reRender="information,statistics,cacheitem_information,keysInUpdate,keysNotInUpdate,alerts" />
 			</h:form>
 			
 			<h:panelGrid columns="3" styleClass="info_table">
@@ -34,6 +31,12 @@
 							
 							<h:outputText value="Current data packet queue size: "/>
 							<h:outputText value="#{admin.currentQueueSize}" />
+							
+							<h:outputText value="Number of idle threads: "/>
+							<h:outputText value="#{admin.idleThreadCount}" />
+							
+							<h:outputText value="Number of busy threads: "/>
+							<h:outputText value="#{admin.busyThreadCount}" />
 						</h:panelGrid>
 					</rich:simpleTogglePanel>
 					
@@ -55,6 +58,7 @@
 				
 					<rich:simpleTogglePanel switchType="client" label="Configuration">
 					<h:form>
+					<a4j:region id="AdminServiceSubmit">
 						<h:panelGrid columns="2" columnClasses="left_text,right_text">
 							<h:outputText value="Interval: "/>
 							<h:inputText value="#{admin.serviceInterval}" id="Interval" required="true">
@@ -68,43 +72,53 @@
 							
 							<h:outputText value="" />
 							<a4j:commandButton value="Submit" action="#{admin.updateServiceConfig}" 
-								reRender="serviceMessages,messages" />
+								reRender="serviceMessages" />
 						</h:panelGrid>
 						
 						<h:panelGroup id="serviceMessages">
-							<h:panelGrid columns="1">
-								<h:message for="Interval"/>
-								<h:message for="UpdateThreadCount"/>
-							</h:panelGrid>
+							<a4j:status startText="Sending ..." stopText="" for="AdminServiceSubmit" />
+							<h:messages showDetail="true" />
 						</h:panelGroup>
+					</a4j:region>
 					</h:form>
 					</rich:simpleTogglePanel>
 			</h:panelGrid>
 			
-			<rich:panel styleClass="header_panel">
+			<rich:panel styleClass="header_panel" id="cacheitem_messages">
 				<h:outputText styleClass="header" value="Cache Items" />
+				<h:panelGroup styleClass="header_messages">
+					<h:messages showDetail="true" />
+				</h:panelGroup>
+				<h:panelGroup id="alerts" styleClass="header_messages">
+					<h:panelGroup rendered="#{admin.currentAlertsSize > 0}">
+						<rich:panel styleClass="alert_panel">
+							<h:outputText value="Current alerts:" styleClass="alert" />
+							<rich:dataList var="alert" value="#{admin.currentAlerts}">
+								<h:outputText value="#{alert}" />
+							</rich:dataList>
+						</rich:panel>
+					</h:panelGroup>
+				</h:panelGroup>
 			</rich:panel>
 			
-			<rich:panel styleClass="note_panel">
+			<rich:simpleTogglePanel switchType="client" opened="true" label="Please note" styleClass="note_panel">
 				<f:verbatim>
-					<h1>Please note:</h1>
-					
 					<ul>
 						<li>only cache items which contain keys that should be updated/ are in update for
 							a time that is at least 2*interval are expanded</li>
 						<li>all changes in the settings will be lost on AS restart; remember to modify
 							the configuration files</li>
+						<li>checking if there are any new cache items requires a page refresh</li>
 					</ul>
 				</f:verbatim>
-			</rich:panel>
+			</rich:simpleTogglePanel>
 			
-			<h:dataTable var="cacheItem" value="#{admin.cacheItems}" styleClass="cacheitem_table" id="cacheitems">
-				<h:column>
+			<rich:dataGrid columns="1" var="cacheItem" value="#{admin.cacheItems}" styleClass="cacheitem_table" id="cacheitems">
 					<rich:simpleTogglePanel switchType="client" label="#{cacheItem.name}"
-						opened="true">
+						opened="#{cacheItem.alerted}">
 						<h:panelGrid columns="2">
 							<rich:simpleTogglePanel switchType="client" label="Information">
-								<h:panelGrid columns="2" columnClasses="left_text,right_text">
+								<h:panelGrid columns="2" columnClasses="left_text,right_text" id="cacheitem_information">
 									<h:outputText value="Name: "/>
 									<h:outputText value="#{cacheItem.name}" />
 								
@@ -123,6 +137,8 @@
 							
 							<rich:simpleTogglePanel switchType="client" label="Configuration">
 							<h:form>
+								<h:inputHidden value="#{cacheItem.id}" />
+								
 								<h:panelGrid columns="2" columnClasses="left_text,right_text">
 									<h:outputText value="Interval: "/>
 									<h:inputText value="#{cacheItem.interval}" id="Interval" required="true">
@@ -131,15 +147,8 @@
 							
 									<h:outputText value="" />
 									<a4j:commandButton value="Submit" action="#{cacheItem.updateConfig}" 
-										reRender="cacheItemMessages,messages" />
+										reRender="cacheitem_messages" />
 								</h:panelGrid>
-						
-								<h:panelGroup id="cacheItemMessages">
-									<h:panelGrid columns="1">
-										<h:message for="Interval"/>
-										<h:message for="UpdateThreadCount"/>
-									</h:panelGrid>
-								</h:panelGroup>
 							</h:form>
 							</rich:simpleTogglePanel>
 							
@@ -157,7 +166,12 @@
 							</rich:simpleTogglePanel>
 							
 							<rich:simpleTogglePanel switchType="client" label="Keys during update">
-								<h:dataTable var="key" value="#{cacheItem.keysDuringUpdate}">
+								<h:panelGroup id="keysInUpdate">
+								<h:form>
+								<h:inputHidden value="#{cacheItem.id}" />
+								
+								<h:dataTable var="key" value="#{cacheItem.keysDuringUpdate}"
+									binding="#{admin.keysInUpdateData}">
 									<h:column>
 										<f:facet name="header"><h:outputText value="Key"/></f:facet>
 										<h:outputText value="#{key}" />
@@ -166,12 +180,17 @@
 										<f:facet name="header"><h:outputText value="In update since"/></f:facet>
 										<h:outputText value="#{cacheItem.lastUpdatesAgo[key]} second(s)" />
 									</h:column>
+									<h:column>
+										<a4j:commandLink value="Reset" action="#{cacheItem.reset}" 
+											reRender="cacheitem_messages,keysInUpdate,keysNotInUpdate" />
+									</h:column>
 								</h:dataTable>
+								</h:form>
+								</h:panelGroup>
 							</rich:simpleTogglePanel>
 						</h:panelGrid>
 					</rich:simpleTogglePanel>
-				</h:column>
-			</h:dataTable>
+			</rich:dataGrid>
 		</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-22 20:24:49 UTC (rev 14453)
+++ labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/RenewableCacheItem.java	2007-08-22 21:00:58 UTC (rev 14454)
@@ -65,6 +65,7 @@
     private long interval;
     private long timeout;
     private String mbeanName;
+    private int id;
     
     private ConcurrentMap<K, Long> keysUpdates;
     /**
@@ -114,6 +115,8 @@
         keysDuringUpdate = new ConcurrentHashSet<K>();
         keysInUpdate = new ConcurrentHashSet<K>();
     	
+        id = CacheTools.getNextId();
+        
     	register();
         
     	if (fqn == null) {
@@ -236,6 +239,10 @@
 	public ConcurrentMap<K, Long> getKeysUpdates() {
 		return keysUpdates;
 	}
+	
+	public int getId() {
+		return id;
+	}
 
 	/**
      * Binds the given key with the given object in the associated TreeCache
@@ -322,6 +329,15 @@
             }
         }
     }
+    
+    /*
+     * (non-Javadoc)
+     * @see org.jboss.shotoku.cache.RenewableCacheItemData#resetKey(java.lang.Object)
+     */
+    public void resetKey(Object key) {
+    	keysInUpdate.remove(key);
+    	keysDuringUpdate.remove(key);
+    }
 
     /**
      * Called by the service periodically to update the object held in the

Modified: 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	2007-08-22 20:24:49 UTC (rev 14453)
+++ labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/RenewableCacheItemData.java	2007-08-22 21:00:58 UTC (rev 14454)
@@ -94,4 +94,17 @@
 	 * @return A set of keys, which are currently being updated.
 	 */
 	public Set<K> getKeysDuringUpdate();
+	
+	/**
+	 * 
+	 * @return A unique id of this instance of cache items.
+	 */
+	public int getId();
+	
+	/**
+	 * Resets the given key, that is, it's update status. Hence, if a thread updating a key
+	 * locks for some reason, it is possible to resume updates of this thread. Use with caution.
+	 * @param key Key, which update status should be reset.
+	 */
+	public void resetKey(Object key);
 }

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-22 20:24:49 UTC (rev 14453)
+++ labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/UpdateThread.java	2007-08-22 21:00:58 UTC (rev 14454)
@@ -45,11 +45,14 @@
     }
 
     public void run() {
+    	service.reportThreadNew();
+    	
         while (true) {
             UpdateThreadData data;
             try {
                 data = queue.take();
-
+                service.reportThreadBusy();
+                
                 long start = System.currentTimeMillis();
                 service.getStatistics().addPacketWaitingTime(start - data.getCreateTime());
                 
@@ -64,6 +67,8 @@
                     log.error("Exception while executing an update thread data.", t);
                     service.getStatistics().addPacketProcessingTime(System.currentTimeMillis() - start, true);
                 }
+                
+                service.reportThreadIdle();
             } catch (InterruptedException e) {
                 log.error("Update thread interrupted.", e);
             }

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-22 20:24:49 UTC (rev 14453)
+++ labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/service/DummyRenewableCacheService.java	2007-08-22 21:00:58 UTC (rev 14454)
@@ -99,4 +99,24 @@
 	public RenewableCacheStatistics getStatistics() {
 		return null;
 	}
+
+	public int getBusyThreadCount() {
+		return 0;
+	}
+
+	public int getIdleThreadCount() {
+		return 0;
+	}
+
+	public void reportThreadBusy() {
+		
+	}
+
+	public void reportThreadIdle() {
+		
+	}
+
+	public void reportThreadNew() {
+		
+	}
 }

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-22 20:24:49 UTC (rev 14453)
+++ labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/service/RenewableCacheServiceMBean.java	2007-08-22 21:00:58 UTC (rev 14454)
@@ -62,6 +62,13 @@
 	public int getUpdateThreadCount();
     public void setUpdateThreadCount(int n);
     
+    public void reportThreadIdle();
+    public void reportThreadBusy();
+    public void reportThreadNew();
+    
+    public int getIdleThreadCount();
+    public int getBusyThreadCount();
+    
     public Set<? extends RenewableCacheItemData<?>> getCacheItemsData();
     
     public void update();

Modified: labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/tools/CacheTools.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/tools/CacheTools.java	2007-08-22 20:24:49 UTC (rev 14453)
+++ labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/tools/CacheTools.java	2007-08-22 21:00:58 UTC (rev 14454)
@@ -105,4 +105,17 @@
         return (obj1 == null && obj2 == null) ||
                 ((obj1 != null) &&  (obj1.equals(obj2)));
     }
+    
+    /**
+     * Next unique id.
+     */
+    private static int ID_COUNTER = 1;
+    
+    /**
+     * 
+     * @return Gets a unique integer id.
+     */
+    public static synchronized int getNextId() {
+    	return ID_COUNTER++;
+    }
 }

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-22 20:24:49 UTC (rev 14453)
+++ labs/shotoku/trunk/shotoku-cache/cache-service/src/java/org/jboss/shotoku/cache/service/RenewableCacheService.java	2007-08-22 21:00:58 UTC (rev 14454)
@@ -199,6 +199,10 @@
         new LinkedBlockingQueue<UpdateThreadData>();
     
     private int updateThreadCount;
+    private int busyThreads;
+    private int idleThreads;
+    
+    private final Object threadCounterSynchronizer = new Object();
 
     public void addUpdateThreadData(UpdateThreadData data) {
     	updateThreadDataQueue.offer(data);
@@ -227,7 +231,37 @@
     public int getCurrentQueueSize() {
     	return updateThreadDataQueue.size();
     }
+    
+	public int getBusyThreadCount() {
+		return busyThreads;
+	}
 
+	public int getIdleThreadCount() {
+		return idleThreads;
+	}
+
+	public void reportThreadBusy() {
+		synchronized (threadCounterSynchronizer) {
+			busyThreads++;
+			idleThreads--;
+		}
+	}
+
+	public void reportThreadIdle() {
+		synchronized (threadCounterSynchronizer) {
+			busyThreads--;
+			idleThreads++;
+		}
+		
+	}
+
+	public void reportThreadNew() {
+		synchronized (threadCounterSynchronizer) {
+			idleThreads++;
+		}
+		
+	}
+
     /*
 	 * Update function.
 	 */

Modified: labs/shotoku/trunk/shotoku-cache/cache-test/src/java/org/jboss/shotoku/cache/test/TestServlet.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/cache-test/src/java/org/jboss/shotoku/cache/test/TestServlet.java	2007-08-22 20:24:49 UTC (rev 14453)
+++ labs/shotoku/trunk/shotoku-cache/cache-test/src/java/org/jboss/shotoku/cache/test/TestServlet.java	2007-08-22 21:00:58 UTC (rev 14454)
@@ -11,18 +11,27 @@
 public class TestServlet extends HttpServlet {
 	private TestCacheItem tci;
 	private TestCacheItem2 tci2;
+	private TestCacheItem tci3;
+	private TestCacheItem2 tci4;
 	
 	@Override
 	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 		System.out.println(tci.get("A"));
 		System.out.println(tci.get("B"));
 		System.out.println(tci2.get("C"));
+		System.out.println(tci2.get("D"));
+		System.out.println(tci3.get("E"));
+		System.out.println(tci3.get("F"));
+		System.out.println(tci4.get("G"));
+		System.out.println(tci4.get("H"));
 	}
 
 	@Override
 	public void init(ServletConfig config) throws ServletException {
 		tci = new TestCacheItem();
 		tci2 = new TestCacheItem2();
+		tci3 = new TestCacheItem();
+		tci4 = new TestCacheItem2();
 		
 		super.init(config);
 	}




More information about the jboss-svn-commits mailing list