[jboss-svn-commits] JBL Code SVN: r14426 - in labs/shotoku/trunk/shotoku-cache: cache-admin/src/web/pages and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Aug 21 16:50:59 EDT 2007
Author: adamw
Date: 2007-08-21 16:50:59 -0400 (Tue, 21 Aug 2007)
New Revision: 14426
Added:
labs/shotoku/trunk/shotoku-cache/cache-test/src/java/org/jboss/shotoku/cache/test/TestCacheItem2.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-test/src/java/org/jboss/shotoku/cache/test/TestServlet.java
Log:
Admin panel
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-21 19:08:13 UTC (rev 14425)
+++ labs/shotoku/trunk/shotoku-cache/cache-admin/src/java/org/jboss/shotoku/cache/admin/AdminBean.java 2007-08-21 20:50:59 UTC (rev 14426)
@@ -1,9 +1,11 @@
package org.jboss.shotoku.cache.admin;
+import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
+import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import javax.management.MalformedObjectNameException;
import javax.servlet.http.HttpServletRequest;
@@ -19,6 +21,7 @@
private RenewableCacheServiceMBean service;
private List<CacheItemBean> cacheItems;
private long newServiceInterval;
+ private int newUpdateThreadCount;
public AdminBean() {
// For development only.
@@ -77,6 +80,14 @@
return getService().getStatistics();
}
+ public int getUpdateThreadCount() {
+ return getService().getUpdateThreadCount();
+ }
+
+ public void setUpdateThreadCount(int newUpdateThreadCount) {
+ this.newUpdateThreadCount = newUpdateThreadCount;
+ }
+
public long getServiceInterval() {
return getService().getInterval();
}
@@ -85,9 +96,18 @@
this.newServiceInterval = newServiceInterval;
}
- public String changeServiceInterval() {
- System.out.println("Changing interval to: " + newServiceInterval);
+ public String updateServiceConfig() {
+ getService().setInterval(newServiceInterval);
+ getService().setUpdateThreadCount(newUpdateThreadCount);
+ 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."));
+
return null;
}
}
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-21 19:08:13 UTC (rev 14425)
+++ labs/shotoku/trunk/shotoku-cache/cache-admin/src/java/org/jboss/shotoku/cache/admin/CacheItemBean.java 2007-08-21 20:50:59 UTC (rev 14426)
@@ -16,19 +16,44 @@
private Map<Object, Long> keysUpdatesAgo;
private RenewableCacheServiceMBean service;
+ /**
+ * If any of the keys where updated/ are in update for a time that is longer
+ * than twice the interval of this cache item.
+ */
+ private boolean alerted;
+
public CacheItemBean(RenewableCacheItemData<?> cacheItem, RenewableCacheServiceMBean service) {
this.cacheItem = cacheItem;
this.service = service;
-
+
keysDuringUpdate = new ArrayList<Object>(cacheItem.getKeysDuringUpdate());
+ //
+
Map<?, Long> keysUpdates = cacheItem.getKeysUpdates();
long now = System.currentTimeMillis();
+ long maxKeyUpdateAgo = 0;
keysUpdatesAgo = new HashMap<Object, Long>();
for (Object key : keysUpdates.keySet()) {
- keysUpdatesAgo.put(key, (long)((now-keysUpdates.get(key))/1000));
+ long lastKeyUpdate = (now-keysUpdates.get(key));
+ keysUpdatesAgo.put(key, lastKeyUpdate/1000);
+
+ if (lastKeyUpdate > maxKeyUpdateAgo) {
+ maxKeyUpdateAgo = lastKeyUpdate;
+ }
}
+ //
+
+ long interval = cacheItem.getInterval();
+ if (interval == 0) {
+ interval = service.getInterval();
+ }
+
+ alerted = maxKeyUpdateAgo > (2*interval);
+
+ //
+
keysNotDuringUpdate = new ArrayList<Object>(keysUpdates.keySet());
keysNotDuringUpdate.removeAll(keysDuringUpdate);
}
@@ -37,10 +62,6 @@
return cacheItem.getClass().getName();
}
- public long getInterval() {
- return cacheItem.getInterval();
- }
-
public List<? extends Object> getKeysDuringUpdate() {
return keysDuringUpdate;
}
@@ -64,4 +85,21 @@
throw new RuntimeException(e);
}
}
+
+ public boolean isAlerted() {
+ return alerted;
+ }
+
+ public long getInterval() {
+ return cacheItem.getInterval();
+ }
+
+ public void setInterval(long interval) {
+ System.out.println("Setting interval to: " + interval);
+ }
+
+ public String updateConfig() {
+ System.out.println("CACHE ITEM: " + getName());
+ 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-21 19:08:13 UTC (rev 14425)
+++ labs/shotoku/trunk/shotoku-cache/cache-admin/src/web/pages/admin.css 2007-08-21 20:50:59 UTC (rev 14426)
@@ -33,9 +33,6 @@
width: 50%;
}
-.messages {
-}
-
.info_table .left_text {
width: 70%;
text-align: right;
@@ -65,4 +62,22 @@
.cacheitem_table .right_text {
vertical-align: bottom;
+}
+
+.note_panel {
+ text-align: left;
+}
+
+.note_panel h1 {
+ font-weight: bold;
+ font-size: small;
+}
+
+.note_panel ul {
+ font-size: x-small;
+}
+
+.alert {
+ color: red;
+ font-weight: bold;
}
\ 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-21 19:08:13 UTC (rev 14425)
+++ labs/shotoku/trunk/shotoku-cache/cache-admin/src/web/pages/admin.jsp 2007-08-21 20:50:59 UTC (rev 14426)
@@ -15,12 +15,12 @@
<h:outputText styleClass="header" value="Shotoku Cache Administration" />
</rich:panel>
- <rich:panel id="messages" styleClass="messages">
- <h:messages />
+ <rich:panel id="messages" styleClass="note_panel">
+ <h:messages globalOnly="true" />
</rich:panel>
<h:form>
- <a4j:poll interval="10000" reRender="information,statistics" />
+ <a4j:poll interval="5000" reRender="information,statistics,cacheitems" />
</h:form>
<h:panelGrid columns="3" styleClass="info_table">
@@ -61,13 +61,21 @@
<f:validateLongRange minimum="1000" />
</h:inputText>
+ <h:outputText value="Update thread count: "/>
+ <h:inputText value="#{admin.updateThreadCount}" id="UpdateThreadCount" required="true">
+ <f:validateLongRange maximum="100" />
+ </h:inputText>
+
<h:outputText value="" />
- <a4j:commandButton value="Submit" action="#{admin.changeServiceInterval}"
- reRender="serviceIntervalError,messages" />
+ <a4j:commandButton value="Submit" action="#{admin.updateServiceConfig}"
+ reRender="serviceMessages,messages" />
</h:panelGrid>
- <h:panelGroup id="serviceIntervalError">
- <h:message for="Interval"/>
+ <h:panelGroup id="serviceMessages">
+ <h:panelGrid columns="1">
+ <h:message for="Interval"/>
+ <h:message for="UpdateThreadCount"/>
+ </h:panelGrid>
</h:panelGroup>
</h:form>
</rich:simpleTogglePanel>
@@ -77,9 +85,23 @@
<h:outputText styleClass="header" value="Cache Items" />
</rich:panel>
- <h:dataTable var="cacheItem" value="#{admin.cacheItems}" styleClass="cacheitem_table">
+ <rich:panel 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>
+ </ul>
+ </f:verbatim>
+ </rich:panel>
+
+ <h:dataTable var="cacheItem" value="#{admin.cacheItems}" styleClass="cacheitem_table" id="cacheitems">
<h:column>
- <rich:simpleTogglePanel switchType="client" label="#{cacheItem.name}">
+ <rich:simpleTogglePanel switchType="client" label="#{cacheItem.name}"
+ opened="true">
<h:panelGrid columns="2">
<rich:simpleTogglePanel switchType="client" label="Information">
<h:panelGrid columns="2" columnClasses="left_text,right_text">
@@ -90,11 +112,35 @@
<h:outputText value="#{cacheItem.fqn}" />
<h:outputText value="FQN keys count: "/>
- <h:outputText value="#{cacheItem.fqnKeysCount}" />
+ <h:outputText value="#{cacheItem.fqnKeysCount}" />
+
+ <h:outputText rendered="#{cacheItem.alerted}" styleClass="alert"
+ value="Alert: "/>
+ <h:outputText rendered="#{cacheItem.alerted}" styleClass="alert"
+ value="Some keys are not updated/ are in update for a too long time" />
</h:panelGrid>
</rich:simpleTogglePanel>
<rich:simpleTogglePanel switchType="client" label="Configuration">
+ <h:form>
+ <h:panelGrid columns="2" columnClasses="left_text,right_text">
+ <h:outputText value="Interval: "/>
+ <h:inputText value="#{cacheItem.interval}" id="Interval" required="true">
+ <f:validateLongRange />
+ </h:inputText>
+
+ <h:outputText value="" />
+ <a4j:commandButton value="Submit" action="#{cacheItem.updateConfig}"
+ reRender="cacheItemMessages,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>
<rich:simpleTogglePanel switchType="client" label="Last updates of keys">
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-21 19:08:13 UTC (rev 14425)
+++ labs/shotoku/trunk/shotoku-cache/cache-base/src/java/org/jboss/shotoku/cache/RenewableCacheItem.java 2007-08-21 20:50:59 UTC (rev 14426)
@@ -67,6 +67,15 @@
private String mbeanName;
private ConcurrentMap<K, Long> keysUpdates;
+ /**
+ * Double-update-start prevention: if a key is already in that set, it won't be updated.
+ */
+ private ConcurrentSet<K> keysInUpdate;
+ /**
+ * Information: update methods of which keys are currently executed. Doesn't have to
+ * coincide with <code>keysInUpdate</code>, as the execution of the update methods for
+ * some keys may be waiting in a queue.
+ */
private ConcurrentSet<K> keysDuringUpdate;
private RenewableCacheServiceMBean service;
@@ -103,6 +112,7 @@
keysUpdates = new ConcurrentHashMap<K, Long>();
keysDuringUpdate = new ConcurrentHashSet<K>();
+ keysInUpdate = new ConcurrentHashSet<K>();
register();
@@ -294,15 +304,17 @@
for (final K key : keysUpdates.keySet()) {
if (now - keysUpdates.get(key) >= interval) {
- if (keysDuringUpdate.add(key)) {
+ if (keysInUpdate.add(key)) {
service.addUpdateThreadData(new UpdateThreadData() {
public void execute() {
keysUpdates.put(key, System.currentTimeMillis());
+ keysDuringUpdate.add(key);
try {
update(key, get(key));
} finally {
- keysDuringUpdate.remove(key);
+ keysInUpdate.remove(key);
+ keysDuringUpdate.remove(key);
}
}
});
Added: labs/shotoku/trunk/shotoku-cache/cache-test/src/java/org/jboss/shotoku/cache/test/TestCacheItem2.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/cache-test/src/java/org/jboss/shotoku/cache/test/TestCacheItem2.java (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/cache-test/src/java/org/jboss/shotoku/cache/test/TestCacheItem2.java 2007-08-21 20:50:59 UTC (rev 14426)
@@ -0,0 +1,21 @@
+package org.jboss.shotoku.cache.test;
+
+import org.jboss.shotoku.cache.RenewableCacheItem;
+
+public class TestCacheItem2 extends RenewableCacheItem<String, Integer> {
+ @Override
+ public Integer init(String key) {
+ return 0;
+ }
+
+ @Override
+ public void update(String key, Integer currentObject) {
+ try {
+ Thread.sleep(30000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ put(key, currentObject + 1);
+ }
+}
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-21 19:08:13 UTC (rev 14425)
+++ labs/shotoku/trunk/shotoku-cache/cache-test/src/java/org/jboss/shotoku/cache/test/TestServlet.java 2007-08-21 20:50:59 UTC (rev 14426)
@@ -10,15 +10,19 @@
public class TestServlet extends HttpServlet {
private TestCacheItem tci;
+ private TestCacheItem2 tci2;
@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"));
}
@Override
public void init(ServletConfig config) throws ServletException {
tci = new TestCacheItem();
+ tci2 = new TestCacheItem2();
super.init(config);
}
More information about the jboss-svn-commits
mailing list