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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Aug 13 12:46:17 EDT 2007


Author: adamw
Date: 2007-08-13 12:46:16 -0400 (Mon, 13 Aug 2007)
New Revision: 14177

Added:
   labs/shotoku/trunk/shotoku-cache/
   labs/shotoku/trunk/shotoku-cache/JBossORG-EULA.txt
   labs/shotoku/trunk/shotoku-cache/build.xml
   labs/shotoku/trunk/shotoku-cache/lib/
   labs/shotoku/trunk/shotoku-cache/lib/jboss-cache.jar
   labs/shotoku/trunk/shotoku-cache/lib/jboss-j2ee.jar
   labs/shotoku/trunk/shotoku-cache/lib/jboss-jmx.jar
   labs/shotoku/trunk/shotoku-cache/lib/jboss-system.jar
   labs/shotoku/trunk/shotoku-cache/lib/jgroups.jar
   labs/shotoku/trunk/shotoku-cache/lib/log4j-1.2.9.jar
   labs/shotoku/trunk/shotoku-cache/src/
   labs/shotoku/trunk/shotoku-cache/src/etc/
   labs/shotoku/trunk/shotoku-cache/src/etc/META-INF/
   labs/shotoku/trunk/shotoku-cache/src/etc/META-INF/jboss-service.xml
   labs/shotoku/trunk/shotoku-cache/src/java/
   labs/shotoku/trunk/shotoku-cache/src/java/org/
   labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/
   labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/
   labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/
   labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/ChangeType.java
   labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/RenewableCacheItem.java
   labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/RenewableCacheItemConfiguration.java
   labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/SignalExitUpdateThreadData.java
   labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/UpdateThread.java
   labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/UpdateThreadData.java
   labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/service/
   labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/service/RenewableCacheService.java
   labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/service/RenewableCacheServiceImpl.java
   labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/exceptions/
   labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/exceptions/RenewableCacheException.java
   labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/
   labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/ConcurrentHashSet.java
   labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/ConcurrentSet.java
   labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/KeyValue.java
   labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/Pair.java
   labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/Tools.java
   labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/Triple.java
   labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/Tuples.java
Log:
Initial renewable cache checkin


Property changes on: labs/shotoku/trunk/shotoku-cache
___________________________________________________________________
Name: svn:ignore
   + target
dist
build
bin
.classpath
.project
.settings


Added: labs/shotoku/trunk/shotoku-cache/JBossORG-EULA.txt
===================================================================
--- labs/shotoku/trunk/shotoku-cache/JBossORG-EULA.txt	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/JBossORG-EULA.txt	2007-08-13 16:46:16 UTC (rev 14177)
@@ -0,0 +1,107 @@
+LICENSE AGREEMENT
+JBOSS(r)
+
+This License Agreement governs the use of the Software Packages and any updates to the Software 
+Packages, regardless of the delivery mechanism.  Each Software Package is a collective work 
+under U.S. Copyright Law.  Subject to the following terms, Red Hat, Inc. ("Red Hat") grants to 
+the user ("Client") a license to the applicable collective work(s) pursuant to the 
+GNU Lesser General Public License v. 2.1 except for the following Software Packages: 
+(a) JBoss Portal Forums and JBoss Transactions JTS, each of which is licensed pursuant to the 
+GNU General Public License v.2; 
+
+(b) JBoss Rules, which is licensed pursuant to the Apache  License v.2.0;
+
+(c) an optional download for JBoss Cache for the Berkeley DB for Java database, which is licensed under the 
+(open source) Sleepycat License (if Client does not wish to use the open source version of this database, 
+it may purchase a license from Sleepycat Software); 
+
+and (d) the BPEL extension for JBoss jBPM, which is licensed under the Common Public License v.1, 
+and, pursuant to the OASIS BPEL4WS standard, requires parties wishing to redistribute to enter various 
+royalty-free patent licenses.  
+
+Each of the foregoing licenses is available at http://www.opensource.org/licenses/index.php.
+
+1.  The Software.  "Software Packages" refer to the various software modules that are created and made available 
+for distribution by the JBoss.org open source community at http://www.jboss.org.   Each of the Software Packages 
+may be comprised of hundreds of software components.  The end user license agreement for each component is located in 
+the component's source code.  With the exception of certain image files identified in Section 2 below, 
+the license terms for the components permit Client to copy, modify, and redistribute the component, 
+in both source code and binary code forms.  This agreement does not limit Client's rights under, 
+or grant Client rights that supersede, the license terms of any particular component.
+
+2.  Intellectual Property Rights.  The Software Packages are owned by Red Hat and others and are protected under copyright 
+and other laws.  Title to the Software Packages and any component, or to any copy, modification, or merged portion shall 
+remain with the aforementioned, subject to the applicable license.  The "JBoss" trademark, "Red Hat" trademark, the 
+individual Software Package trademarks, and the "Shadowman" logo are registered trademarks of Red Hat and its affiliates 
+in the U.S. and other countries.  This agreement permits Client to distribute unmodified copies of the Software Packages 
+using the Red Hat trademarks that Red Hat has inserted in the Software Packages on the condition that Client follows Red Hat's 
+trademark guidelines for those trademarks located at http://www.redhat.com/about/corporate/trademark/.  Client must abide by 
+these trademark guidelines when distributing the Software Packages, regardless of whether the Software Packages have been modified. 
+If Client modifies the Software Packages, then Client must replace all Red Hat trademarks and logos identified at 
+http://www.jboss.com/company/logos, unless a separate agreement with Red Hat is executed or other permission granted.  
+Merely deleting the files containing the Red Hat trademarks may corrupt the Software Packages.  
+
+3.  Limited Warranty.  Except as specifically stated in this Paragraph 3 or a license for a particular 
+component, to the maximum extent permitted under applicable law, the Software Packages and the 
+components are provided and licensed "as is" without warranty of any kind, expressed or implied, 
+including the implied warranties of merchantability, non-infringement or fitness for a particular purpose.  
+Red Hat warrants that the media on which Software Packages may be furnished will be free from defects in 
+materials and manufacture under normal use for a period of 30 days from the date of delivery to Client.  
+Red Hat does not warrant that the functions contained in the Software Packages will meet Client's requirements 
+or that the operation of the Software Packages will be entirely error free or appear precisely as described 
+in the accompanying documentation. This warranty extends only to the party that purchases the Services 
+pertaining to the Software Packages from Red Hat or a Red Hat authorized distributor. 
+
+4.  Limitation of Remedies and Liability. To the maximum extent permitted by applicable law, the remedies 
+described below are accepted by Client as its only remedies.  Red Hat's entire liability, and Client's 
+exclusive remedies, shall be: If the Software media is defective, Client may return it within 30 days of 
+delivery along with a copy of Client's payment receipt and Red Hat, at its option, will replace it or 
+refund the money paid by Client for the Software.  To the maximum extent permitted by applicable law, 
+Red Hat or any Red Hat authorized dealer will not be liable to Client for any incidental or consequential 
+damages, including lost profits or lost savings arising out of the use or inability to use the Software, 
+even if Red Hat or such dealer has been advised of the possibility of such damages.  In no event shall 
+Red Hat's liability under this agreement exceed the amount that Client paid to Red Hat under this 
+Agreement during the twelve months preceding the action.
+
+5.  Export Control.  As required by U.S. law, Client represents and warrants that it: 
+(a) understands that the Software Packages are subject to export controls under the 
+U.S. Commerce Department's Export Administration Regulations ("EAR"); 
+
+(b) is not located in a prohibited destination country under the EAR or U.S. sanctions regulations 
+(currently Cuba, Iran, Iraq, Libya, North Korea, Sudan and Syria); 
+
+(c) will not export, re-export, or transfer the Software Packages to any prohibited destination, entity, 
+or individual without the necessary export license(s) or authorizations(s) from the U.S. Government; 
+
+(d) will not use or transfer the Software Packages for use in any sensitive nuclear, chemical or 
+biological weapons, or missile technology end-uses unless authorized by the U.S. Government by 
+regulation or specific license; 
+
+(e) understands and agrees that if it is in the United States and exports or transfers the Software 
+Packages to eligible end users, it will, as required by EAR Section 740.17(e), submit semi-annual 
+reports to the Commerce Department's Bureau of Industry & Security (BIS), which include the name and 
+address (including country) of each transferee; 
+
+and (f) understands that countries other than the United States may restrict the import, use, or 
+export of encryption products and that it shall be solely responsible for compliance with any such 
+import, use, or export restrictions.
+
+6.  Third Party Programs. Red Hat may distribute third party software programs with the Software Packages 
+that are not part of the Software Packages and which Client must install separately.  These third party 
+programs are subject to their own license terms.  The license terms either accompany the programs or 
+can be viewed at http://www.redhat.com/licenses/.  If Client does not agree to abide by the applicable 
+license terms for such programs, then Client may not install them.  If Client wishes to install the programs 
+on more than one system or transfer the programs to another party, then Client must contact the licensor 
+of the programs.
+
+7.  General.  If any provision of this agreement is held to be unenforceable, that shall not affect the 
+enforceability of the remaining provisions.  This License Agreement shall be governed by the laws of the 
+State of North Carolina and of the United States, without regard to any conflict of laws provisions, 
+except that the United Nations Convention on the International Sale of Goods shall not apply.
+
+Copyright 2006 Red Hat, Inc.  All rights reserved.  
+"JBoss" and the JBoss logo are registered trademarks of Red Hat, Inc.  
+All other trademarks are the property of their respective owners. 
+
+	Page 1 of 1	18 October 2006
+

Added: labs/shotoku/trunk/shotoku-cache/build.xml
===================================================================
--- labs/shotoku/trunk/shotoku-cache/build.xml	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/build.xml	2007-08-13 16:46:16 UTC (rev 14177)
@@ -0,0 +1,81 @@
+<?xml version='1.0' encoding='UTF-8'?>
+
+<project name="Shotoku Renewable Cache" default="build" basedir=".">
+    <!-- Configuration of deployment -->
+    <property name="jboss.home" value="/home/adamw/jboss/jboss-cache" />
+    <property name="jboss.conf" value="default" />
+
+    <!-- Name of the service archive which will contain the blog application -->
+	<property name="jar.lib.name" value="shotoku-cache.jar" />
+	<property name="jar.service.name" value="shotoku-cache-service.jar" />
+    <property name="sar.name" value="shotoku-cache-service.sar" />
+
+    <!-- Configuration of source/ target directories -->
+    <property name="src" value="src"/>
+    <property name="src.java" value="${src}/java"/>
+    <property name="src.meta" value="${src}/etc"/>
+    <property name="build" value="build"/>
+    <property name="dist" value="${basedir}/dist"/>
+
+    <!-- Helper properties: built using the above ones -->
+    <property name="dist.sar.dir" value="${dist}/${sar.name}" />
+    <property name="dist.sar.lib.dir" value="${dist.sar.dir}/lib" />
+	<property name="dist.lib.dir" value="${dist}" />
+	
+    <property name="deploy.dir" value="${jboss.home}/server/${jboss.conf}/deploy" />
+
+    <!-- Dependency jars filesets definitions -->
+    <fileset id="classpath" dir="lib"><include name="**/*.jar"/></fileset>
+	<path id="classpath.jars">
+	        <fileset refid="classpath" />
+	</path>
+
+    <!-- Main tasks -->
+    <target name="clean">
+        <delete dir="${dist}" />
+    	<delete dir="${build}" />
+    </target>
+
+    <target name="build" depends="clean">
+        <mkdir dir="${build}" />
+    	
+        <!-- Compiling the source -->
+        <javac srcdir="${src.java}" destdir="${build}" target="1.5" source="1.5">
+            <classpath refid="classpath.jars" />
+        </javac>
+    </target>
+
+    <target name="dist" depends="build">
+    	<mkdir dir="${dist.sar.dir}" />
+    	<mkdir dir="${dist.sar.lib.dir}" />
+    	<mkdir dir="${dist.lib.dir}" />
+    	
+    	<!-- Copying the meta information -->    	
+    	<copy todir="${dist.sar.dir}">
+			<fileset dir="${src.meta}"><include name="**/*" /></fileset>
+    	</copy>
+
+        <!-- Creating the jars with the classes -->
+        <jar destfile="${dist.sar.lib.dir}/${jar.service.name}" 
+        	basedir="${build}" 
+        	includes="**/*ServiceImpl*" />
+    	
+        <jar destfile="${dist.lib.dir}/${jar.lib.name}" 
+        	basedir="${build}" 
+        	excludes="**/*ServiceImpl*" />
+    </target>
+
+    <target name="deploy" depends="dist,undeploy">
+        <!-- Copying the sar directory to the jboss deploy dir -->
+        <copy todir="${deploy.dir}">
+            <fileset dir="${dist}">
+                <include name="${sar.name}/**" />
+            </fileset>
+        </copy>
+    </target>
+
+    <target name="undeploy">
+        <!-- Deleting old deployment -->
+        <delete dir="${deploy.dir}/${sar.name}" />
+    </target>
+</project>

Added: labs/shotoku/trunk/shotoku-cache/lib/jboss-cache.jar
===================================================================
(Binary files differ)


Property changes on: labs/shotoku/trunk/shotoku-cache/lib/jboss-cache.jar
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:mime-type
   + application/octet-stream

Added: labs/shotoku/trunk/shotoku-cache/lib/jboss-j2ee.jar
===================================================================
(Binary files differ)


Property changes on: labs/shotoku/trunk/shotoku-cache/lib/jboss-j2ee.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: labs/shotoku/trunk/shotoku-cache/lib/jboss-jmx.jar
===================================================================
(Binary files differ)


Property changes on: labs/shotoku/trunk/shotoku-cache/lib/jboss-jmx.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: labs/shotoku/trunk/shotoku-cache/lib/jboss-system.jar
===================================================================
(Binary files differ)


Property changes on: labs/shotoku/trunk/shotoku-cache/lib/jboss-system.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: labs/shotoku/trunk/shotoku-cache/lib/jgroups.jar
===================================================================
(Binary files differ)


Property changes on: labs/shotoku/trunk/shotoku-cache/lib/jgroups.jar
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:mime-type
   + application/octet-stream

Added: labs/shotoku/trunk/shotoku-cache/lib/log4j-1.2.9.jar
===================================================================
(Binary files differ)


Property changes on: labs/shotoku/trunk/shotoku-cache/lib/log4j-1.2.9.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: labs/shotoku/trunk/shotoku-cache/src/etc/META-INF/jboss-service.xml
===================================================================

Added: labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/ChangeType.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/ChangeType.java	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/ChangeType.java	2007-08-13 16:46:16 UTC (rev 14177)
@@ -0,0 +1,35 @@
+/******************************************************************************
+ * 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;
+
+/**
+ * Describes the possible type of changes which can be made on a
+ * resource.
+ * @author <a href="mailto:adam.warski at jboss.org">Adam Warski</a>
+ */
+public enum ChangeType {
+    MODIFIED,
+    ADDED,
+    DELETED,
+    NONE
+}

Added: labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/RenewableCacheItem.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/RenewableCacheItem.java	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/RenewableCacheItem.java	2007-08-13 16:46:16 UTC (rev 14177)
@@ -0,0 +1,241 @@
+/******************************************************************************
+ * 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 org.apache.log4j.Logger;
+import org.jboss.cache.CacheException;
+import org.jboss.cache.Fqn;
+import org.jboss.shotoku.tools.Tools;
+import org.jboss.shotoku.tools.ConcurrentSet;
+import org.jboss.shotoku.tools.ConcurrentHashSet;
+import org.jboss.shotoku.cache.service.RenewableCacheService;
+import org.jboss.shotoku.exceptions.RenewableCacheException;
+
+import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+import javax.management.MalformedObjectNameException;
+
+/**
+ * Extend this class if you want to store objects in the cache that
+ * will be updated on every Shotoku service timer timeout. The cache
+ * item will be auto-registered in the service upon construction - so
+ * take care when constructing objects of this class.
+ * @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).
+ * @param <T> Type of the object that will be stored in the cache.
+ * @author <a href="mailto:adam.warski at jboss.org">Adam Warski</a>
+ */
+public abstract class RenewableCacheItem<K, T> implements RenewableCacheItemConfiguration<K> {
+	private final Logger log = Logger.getLogger(RenewableCacheItem.class);
+	
+    private Fqn fqn;
+    private long interval;
+    private long timeout;
+    private String mbeanName;
+    
+    private ConcurrentMap<K, Long> keysUpdates;
+    private ConcurrentSet<K> keysDuringUpdate;
+    
+    private RenewableCacheService service;
+
+    /**
+     *
+     * @param interval Interval at which the update operation will be executed.
+     * Effectively, the interval will be rounded to the nearest multiplicity of
+     * the service timer interval. The interval should be given in milliseconds.
+     */
+    public RenewableCacheItem(Fqn fqn, String mbeanName, long interval, long timeout) {
+    	if (mbeanName == null) {
+    		mbeanName = Tools.DEFAULT_RENEWABLE_CACHE_MBEAN;
+    	}
+    	
+    	this.mbeanName = mbeanName;
+    	
+    	try {
+			service = Tools.getService(mbeanName);
+		} catch (MalformedObjectNameException e) {
+			log.error("No RenewableCacheService bound to " + mbeanName + " in cache item " + this.getClass() + "!");
+			return;
+		}
+    	
+    	if (fqn == null) {
+    		this.fqn = service.getNextFqn();
+    	} else {
+    		this.fqn = fqn;
+    	}
+    	
+        this.interval = interval;
+        this.timeout = timeout;
+    	
+        keysUpdates = new ConcurrentHashMap<K, Long>();
+        keysDuringUpdate = new ConcurrentHashSet<K>();
+
+        service.register(this);
+    }
+
+    public RenewableCacheItem() {
+        this(null, null, 0, 0);
+    }
+    
+    public Fqn getFqn() {
+		return fqn;
+	}
+
+	public void setFqn(Fqn fqn) {
+		this.fqn = fqn;
+	}
+
+	public long getInterval() {
+		return interval;
+	}
+
+	public void setInterval(long interval) {
+		this.interval = interval;
+	}
+
+	public String getMbeanName() {
+		return mbeanName;
+	}
+
+	/**
+     * Binds the given key with the given object in the cache. The real key to
+     * which the object will be bound is: keyBase/key.
+     * @param key Key of the object.
+     * @param object Object that should be bound.
+     * @throws RenewableCacheException
+     */
+    public final void put(K key, T object) throws RenewableCacheException {
+        if (!keysUpdates.containsKey(key)) {
+            throw new RenewableCacheException("Key " + key + " is not handled by this " +
+                    "ShotokuCacheItem.");
+        }
+
+        try {
+			service.put(fqn, key, object);
+		} catch (CacheException e) {
+			log.error("Error while putting a value for key \"" + key + "\" in cache item " + this.getClass() + ".", e);
+		}
+    }
+
+    /**
+     * Gets an object that is bound to the given key in the cache.
+     * If this object is not in the cache, it will be initialized.
+     * @param key Key of the object to get.
+     * @return Value of the object.
+     */
+    @SuppressWarnings("unchecked")
+	public final T get(K key) {
+        synchronized(this) {
+            if (!keysUpdates.containsKey(key)) {
+                T ret = init(key);
+                try {
+					service.put(fqn, key, ret);
+				} catch (CacheException e) {
+					log.error("Error while putting a value for key \"" + key + "\" in cache item " + this.getClass() + ".", e);
+					return null;
+				}
+
+                // We have to initialize a new object.
+                keysUpdates.put(key, System.currentTimeMillis());
+
+                return ret;
+            }
+        }
+
+        try {
+			return (T) service.get(fqn, key);
+		} catch (CacheException e) {
+			log.error("Error while getting a value for key \"" + key + "\" in cache item " + this.getClass() + ".", e);
+			return null;
+		}
+    }
+
+    /**
+     * Removes all keys handled by this ShotokuCacheItem from the cache.
+     */
+    public final void unregister() {
+        try {
+			service.unregister(this);
+		} catch (CacheException e) {
+			log.error("Error while unregistering a cache item " + this.getClass() + ".", e);
+		}
+    }
+
+    /**
+     * Called by the Shotoku service. You shouldn't call it from inside your
+     * program.
+     */
+    public final void update() {
+        long now = Calendar.getInstance().getTimeInMillis();
+        
+        for (final K key : keysUpdates.keySet()) {
+            if (now - keysUpdates.get(key) >= interval) {
+                if (keysDuringUpdate.add(key)) {
+                    service.addUpdateThreadData(new UpdateThreadData() {
+                        public void execute() {
+                        	keysUpdates.put(key, System.currentTimeMillis());
+                        	
+                            try {
+                                update(key, get(key));
+                            } finally {
+                                keysDuringUpdate.remove(key);
+                            }
+                        }
+                    });
+                }
+            }
+        }
+    }
+
+    /**
+     * Notifies the cache item that it should reset its set of keys that
+     * are during update, most probably beacuse the managing service has
+     * been restarted (so updates of all keys that have been updated got
+     * interrupted).
+     */
+    public void resetKeysDuringUpdate() {
+        keysDuringUpdate.clear();
+    }
+
+    /**
+     * Called by the service periodically to update the object held.
+     * If the object in the cache should be changed, the implementing
+     * method must call put(key, newObject).
+     * @param key Key of the object to update.
+     * @param currentObject Current value held in the cache.
+     */
+    public abstract void update(K key, T currentObject);
+
+    /**
+     * Called when the user demanded an object which hasn't been accessed
+     * before, and thus, which hasn't been yet initialized. Here,
+     * put(key, initialObject) should not be called, as the returned object
+     * is automatically placed in the cache.
+     * @param key Key of the object to initialize.
+     * @return Initial value of an object with the given key.
+     */
+    public abstract T init(K key);
+}

Added: labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/RenewableCacheItemConfiguration.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/RenewableCacheItemConfiguration.java	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/RenewableCacheItemConfiguration.java	2007-08-13 16:46:16 UTC (rev 14177)
@@ -0,0 +1,49 @@
+/******************************************************************************
+ * 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;
+
+/**
+ * 
+ * @param <K>
+ * @author <a href="mailto:adam.warski at jboss.org">Adam Warski</a>
+ */
+public interface RenewableCacheItemConfiguration<K> {
+	public Fqn getFqn();
+	public void setFqn(Fqn fqn);
+	
+	public long getInterval();
+	public void setInterval(long interval);
+	
+	public long getTimeout();
+	public void setTimeout(long timeout);
+	
+	public String getMbeanName();
+	
+	public Map<K, Long> getKeysLastUpdates();
+	public Set<K> getKeysDuringUpdate();
+}

Added: labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/SignalExitUpdateThreadData.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/SignalExitUpdateThreadData.java	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/SignalExitUpdateThreadData.java	2007-08-13 16:46:16 UTC (rev 14177)
@@ -0,0 +1,34 @@
+/******************************************************************************
+ * 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;
+
+/**
+ * 
+ * 
+ * @author <a href="mailto:adam.warski at jboss.org">Adam Warski</a>
+ */
+public class SignalExitUpdateThreadData extends UpdateThreadData {
+	@Override
+	public void execute() {
+	}
+}

Added: labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/UpdateThread.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/UpdateThread.java	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/UpdateThread.java	2007-08-13 16:46:16 UTC (rev 14177)
@@ -0,0 +1,68 @@
+/******************************************************************************
+ * 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 org.jboss.shotoku.cache.service.RenewableCacheService;
+import org.apache.log4j.Logger;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * @author <a href="mailto:adam.warski at jboss.org">Adam Warski</a>
+ */
+public class UpdateThread extends Thread {
+    private static final Logger log = Logger.getLogger(UpdateThread.class);
+
+    private RenewableCacheService service;
+    private BlockingQueue<UpdateThreadData> queue;
+
+    public UpdateThread(RenewableCacheService service, LinkedBlockingQueue<UpdateThreadData> queue) {
+        this.service = service;
+        this.queue = queue;
+
+        setDaemon(true);
+    }
+
+    public void run() {
+        while (true) {
+            UpdateThreadData data;
+            try {
+                data = queue.take();
+
+                if (data instanceof SignalExitUpdateThreadData) {
+                	break;
+                }
+                
+                try {
+                    data.execute();
+                } catch (Throwable t) {
+                    log.error("Exception while executing an update thread data.", t);
+                }
+
+            } catch (InterruptedException e) {
+                log.error("Update thread interrupted.", e);
+            }
+        }
+    }
+}

Added: labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/UpdateThreadData.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/UpdateThreadData.java	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/UpdateThreadData.java	2007-08-13 16:46:16 UTC (rev 14177)
@@ -0,0 +1,31 @@
+/******************************************************************************
+ * 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;
+
+/**
+ * Function that should be executed by an update thread.
+ * @author <a href="mailto:adam.warski at jboss.org">Adam Warski</a>
+ */
+public abstract class UpdateThreadData {
+    public abstract void execute();
+}

Added: labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/service/RenewableCacheService.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/service/RenewableCacheService.java	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/service/RenewableCacheService.java	2007-08-13 16:46:16 UTC (rev 14177)
@@ -0,0 +1,58 @@
+/******************************************************************************
+ * 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.shotoku.cache.RenewableCacheItem;
+import org.jboss.shotoku.cache.UpdateThread;
+import org.jboss.shotoku.cache.UpdateThreadData;
+
+/**
+ * 
+ * @author <a href="mailto:adam.warski at jboss.org">Adam Warski</a>
+ */
+public interface RenewableCacheService {
+    /*
+     * CACHE
+     */
+
+    public Object get(Fqn fqn, Object key) throws CacheException;
+    public void put(Fqn fqn, Object key, Object o) throws CacheException;
+    public void remove(Fqn fqn, Object key) throws CacheException;
+    
+    /**
+     * Touch the last update time of a key, that is, notifies the
+     * service that the given key is up to date. 
+     * @param key
+     */
+    public void register(RenewableCacheItem cacheItem);
+    public void unregister(RenewableCacheItem cacheItem) throws CacheException;
+
+    /**
+     * Gets a next unique key base for a shotoku cache item.
+     */
+    public Fqn getNextFqn();
+
+    public void addUpdateThreadData(UpdateThreadData data);
+}

Added: labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/service/RenewableCacheServiceImpl.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/service/RenewableCacheServiceImpl.java	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/cache/service/RenewableCacheServiceImpl.java	2007-08-13 16:46:16 UTC (rev 14177)
@@ -0,0 +1,286 @@
+/******************************************************************************
+ * 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.TreeCache;
+import org.jboss.shotoku.cache.RenewableCacheItem;
+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.Tools;
+import org.jboss.system.ServiceMBeanSupport;
+import org.apache.log4j.Logger;
+
+import java.util.Calendar;
+import java.util.Date;
+import java.util.concurrent.LinkedBlockingQueue;
+
+/**
+ * 
+ * @author <a href="mailto:adam.warski at jboss.org">Adam Warski</a>
+ */
+public class RenewableCacheServiceImpl extends ServiceMBeanSupport implements RenewableCacheService {
+    private final static Logger log = Logger.getLogger(RenewableCacheService.class);
+    
+    private TreeCache treeCache;
+    private long interval;
+    private long lastUpdate;
+    private Thread updateThread;
+    
+    /*
+     * Service-handling functions.
+     */
+
+    public void create() throws Exception {
+    }
+
+    public void start() throws Exception {
+    	log.info("Starting main update thread...");
+    	startUpdateThread();
+
+        log.info("Starting update threads...");
+        setUpdateThreadCount(updateThreadCount);
+
+        //log.info("Reseting keys during update in cache items...");
+        // Reseting just in case - if any thread unexpectadly died.
+        //for (RenewableCacheItem sci : cacheItems) {
+        //    sci.resetKeysDuringUpdate();
+        //}
+    }
+
+    public void stop() {
+        signalExitAllUpdateThreads();
+        getUpdateThread().interrupt();
+        
+        log.info("All update threads stopped.");
+    }
+
+    public void destroy() {
+
+    }
+    
+	public TreeCache getTreeCache() {
+		return treeCache;
+	}
+
+	public void setTreeCache(TreeCache 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 getLastUpdateSecondsAgo() {
+    	return (System.currentTimeMillis() - getLastUpdate())/1000;
+    }
+	
+	public Date getLastUpdateDate() {
+        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.debug("Stopping update thread for " + getName() + " (interrupted).", e);
+                        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.getKeysLastUpdates().keySet()) {
+    		remove(cacheItem.getFqn(), key);
+    	}
+    }
+
+    private int counter = 0;
+    private final Object counterSync = new Object();
+
+    public Fqn getNextFqn() {
+        int c;
+        synchronized(counterSync) { c = counter++; }
+
+        return new Fqn(new Object[] {Tools.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 void setUpdateThreadCount(int n) {
+        synchronized (updateThreadDataQueue) {
+            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;
+    }
+
+    private void signalExitAllUpdateThreads() {
+    	synchronized (updateThreadDataQueue) {
+    		for (int i=0; i<updateThreadCount; i++) {
+    			updateThreadDataQueue.offer(new SignalExitUpdateThreadData());
+    		}
+    	}
+    }
+
+    /*
+     * Update function.
+     */
+
+    public void update() {
+        for (RenewableCacheItem sci : cacheItems) {
+            try {
+                sci.update();
+            } catch (Throwable t) {
+                log.error("Exception while updating a cache item.", t);
+            }
+        }
+    }
+
+    /*
+     * Description functions.
+     */
+
+    public String getServiceDescription() {
+        /*long now = System.currentTimeMillis();
+
+        StringBuffer sb = new StringBuffer("Cache service.<br />");
+        sb.append("Currently storing ").append(cache.size()).append(" items in the cache ");
+        sb.append("and ").append(cacheItems.size()).append(" ShotokuCacheItem objects.<br />");
+        sb.append("Objects in cache:<br />");
+        for (Object key : cache.keySet()) {
+            sb.append(key.toString()).append(" : ").append(
+                    cache.get(key).getClass().getName()).append(
+                    ", last updated ").append((now - lastUpdates.get(key)) / 1000).append(
+                    " seconds ago.<br />");
+        }
+
+        sb.append("Cache items:<br />");
+        for (RenewableCacheItem sci : cacheItems) {
+            sb.append(sci.getClass().getName()).append("<br />");
+        }
+
+        return sb.toString();*/
+    	
+    	return null;
+    }
+}

Added: labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/exceptions/RenewableCacheException.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/exceptions/RenewableCacheException.java	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/exceptions/RenewableCacheException.java	2007-08-13 16:46:16 UTC (rev 14177)
@@ -0,0 +1,40 @@
+/******************************************************************************
+ * 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.exceptions;
+
+/**
+ * @author <a href="mailto:adam.warski at jboss.org">Adam Warski</a>
+ */
+public class RenewableCacheException extends RuntimeException {
+    public RenewableCacheException(Exception e) {
+		super(e);
+	}
+
+	public RenewableCacheException(String msg) {
+		super(msg);
+	}
+
+	public RenewableCacheException() {
+
+	}
+}

Added: labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/ConcurrentHashSet.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/ConcurrentHashSet.java	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/ConcurrentHashSet.java	2007-08-13 16:46:16 UTC (rev 14177)
@@ -0,0 +1,108 @@
+/******************************************************************************
+ * 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.tools;
+
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.Iterator;
+import java.util.Collection;
+
+/**
+ * @author <a href="mailto:adam.warski at jboss.org">Adam Warski</a>
+ */
+public class ConcurrentHashSet<K> implements ConcurrentSet<K> {
+    private ConcurrentMap<K, Boolean> map;
+
+    public ConcurrentHashSet() {
+        map = new ConcurrentHashMap<K, Boolean>();
+    }
+
+    public int size() {
+        return map.size();
+    }
+
+    public boolean isEmpty() {
+        return map.isEmpty();
+    }
+
+    public boolean contains(Object o) {
+        return map.containsKey(o);
+    }
+
+    public Iterator<K> iterator() {
+        return map.keySet().iterator();
+    }
+
+    public Object[] toArray() {
+        return map.keySet().toArray();
+    }
+
+    public <T>T[] toArray(T[] a) {
+        return map.keySet().toArray(a);
+    }
+
+    public boolean add(K o) {
+        return map.putIfAbsent(o, Boolean.TRUE) == null;
+    }
+
+    public boolean remove(Object o) {
+        return map.keySet().remove(o);
+    }
+
+    public boolean containsAll(Collection<?> c) {
+        return map.keySet().containsAll(c);
+    }
+
+    public boolean addAll(Collection<? extends K> c) {
+        boolean ret = false;
+        for (K o : c) {
+            ret |= add(o);
+        }
+
+        return ret;
+    }
+
+    public boolean retainAll(Collection<?> c) {
+        boolean ret = false;
+        for (Object o : c) {
+            if (!map.containsKey(o)) {
+                map.remove(o);
+            }
+        }
+
+        return ret;
+    }
+
+    public boolean removeAll(Collection<?> c) {
+        boolean ret = false;
+        for (Object o : c) {
+            ret |= remove(o);
+        }
+
+        return ret;
+    }
+
+    public void clear() {
+        map.clear();
+    }
+}

Added: labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/ConcurrentSet.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/ConcurrentSet.java	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/ConcurrentSet.java	2007-08-13 16:46:16 UTC (rev 14177)
@@ -0,0 +1,32 @@
+/******************************************************************************
+ * 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.tools;
+
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:adam.warski at jboss.org">Adam Warski</a>
+ */
+public interface ConcurrentSet<K> extends Set<K> {
+    
+}

Added: labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/KeyValue.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/KeyValue.java	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/KeyValue.java	2007-08-13 16:46:16 UTC (rev 14177)
@@ -0,0 +1,61 @@
+/******************************************************************************
+ * 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.tools;
+
+/**
+ * A pair of objects, but only the first one is considered in the equals()
+ * and hashCode() methods.
+ * @param <T1>
+ * @param <T2>
+ * @author <a href="mailto:adam.warski at jboss.org">Adam Warski</a>
+ */
+public class KeyValue<T1, T2> {
+    private T1 obj1;
+    private T2 obj2;
+
+    public KeyValue(T1 obj1, T2 obj2) {
+        this.obj1 = obj1;
+        this.obj2 = obj2;
+    }
+
+    public T1 getFirst() {
+        return obj1;
+    }
+
+    public T2 getSecond() {
+        return obj2;
+    }
+
+    public boolean equals(Object o) {
+        if (o instanceof KeyValue) {
+            KeyValue p = (KeyValue) o;
+            return p.getFirst().equals(obj1);
+        }
+
+        return false;
+    }
+
+    public int hashCode() {
+        return obj1.hashCode();
+    }
+}

Added: labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/Pair.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/Pair.java	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/Pair.java	2007-08-13 16:46:16 UTC (rev 14177)
@@ -0,0 +1,64 @@
+/******************************************************************************
+ * 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.tools;
+
+/**
+ * A pair of objects.
+ * @param <T1>
+ * @param <T2>
+ * @author <a href="mailto:adam.warski at jboss.org">Adam Warski</a>
+ */
+public class Pair<T1, T2> {
+	private T1 obj1;
+	private T2 obj2;
+	
+	public Pair(T1 obj1, T2 obj2) {
+		this.obj1 = obj1;
+		this.obj2 = obj2;
+	}
+	
+	public T1 getFirst() {
+		return obj1;
+	}
+	
+	public T2 getSecond() {
+		return obj2;
+	}
+
+    public boolean equals(Object o) {
+        if (o instanceof Pair) {
+            Pair p = (Pair) o;
+            return p.getFirst().equals(obj1) && p.getSecond().equals(obj2);
+        }
+
+        return false;
+    }
+
+    public int hashCode() {
+        return obj1.hashCode() + obj2.hashCode();
+    }
+
+    public String toString() {
+        return "(" + obj1.toString() + ", " + obj2.toString() + ")";
+    }
+}

Added: labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/Tools.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/Tools.java	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/Tools.java	2007-08-13 16:46:16 UTC (rev 14177)
@@ -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.tools;
+
+import javax.management.MalformedObjectNameException;
+
+import org.jboss.mx.util.MBeanProxyExt;
+import org.jboss.mx.util.MBeanServerLocator;
+import org.jboss.shotoku.cache.service.RenewableCacheService;
+
+/**
+ * Utility, helper functions used internally.
+ *
+ * @author <a href="mailto:adam.warski at jboss.org">Adam Warski</a>
+ */
+public class Tools {
+	public static final String GENERATED_FQN_BASE = "ShotokuRenewableCache";
+	
+	public static final String DEFAULT_RENEWABLE_CACHE_MBEAN = "shotoku:service=RenewableCache";
+	
+    public static RenewableCacheService getService(String mbeanName) throws MalformedObjectNameException {
+		return (RenewableCacheService) MBeanProxyExt.create(
+				RenewableCacheService.class, mbeanName,
+				MBeanServerLocator.locate());
+	}
+
+    /**
+	 * Checks if the given string is empty (null or "").
+	 * 
+	 * @param s
+	 *            String to check.
+	 * @return True iff the given string is null or equal to "".
+	 */
+    public static boolean isEmpty(String s) {
+        return (s == null) || ("".equals(s));
+    }
+
+    /**
+     * Converts the given object to a String in a null-safe way.
+     * @param o Object to convert.
+     * @return Result of o.toString() or null if o is null.
+     */
+    public static String toString(Object o) {
+        if (o == null) {
+            return null;
+        }
+
+        return o.toString();
+    }
+
+    /**
+     * Converts the given object to a String in a null-safe way.
+     * Never returns a null.
+     * @param o Object to convert.
+     * @return Result of o.toString() or an emptys tring if o is null.
+     */
+    public static String toStringNotNull(Object o) {
+        if (o == null) {
+            return "";
+        }
+
+        return o.toString();
+    }
+
+    /**
+     * Checks if two objects are equal - either both null, or
+     * their equals method returns true.
+     * @param obj1 First object to compare.
+     * @param obj2 Second object to compare.
+     * @return True iff both objects are equal to null or if
+     * their equals method returns true.
+     */
+    public static boolean objectsEqual(Object obj1, Object obj2) {
+        return (obj1 == null && obj2 == null) ||
+                ((obj1 != null) &&  (obj1.equals(obj2)));
+    }
+}

Added: labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/Triple.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/Triple.java	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/Triple.java	2007-08-13 16:46:16 UTC (rev 14177)
@@ -0,0 +1,72 @@
+/******************************************************************************
+ * 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.tools;
+
+/**
+ * A triple of objects.
+ * @param <T1>
+ * @param <T2>
+ * @param <T3>
+ * @author <a href="mailto:adam.warski at jboss.org">Adam Warski</a>
+ */
+public class Triple<T1, T2, T3> {
+    private T1 obj1;
+    private T2 obj2;
+    private T3 obj3;
+
+    public Triple(T1 obj1, T2 obj2, T3 obj3) {
+        this.obj1 = obj1;
+        this.obj2 = obj2;
+        this.obj3 = obj3;
+    }
+
+    public T1 getFirst() {
+        return obj1;
+    }
+
+    public T2 getSecond() {
+        return obj2;
+    }
+
+    public T3 getThird() {
+        return obj3;
+    }
+
+    public boolean equals(Object o) {
+        if (o instanceof Triple) {
+            Triple t = (Triple) o;
+            return t.getFirst().equals(obj1) && t.getSecond().equals(obj2)
+                    && t.getThird().equals(obj3);
+        }
+
+        return false;
+    }
+
+    public int hashCode() {
+        return obj1.hashCode() + obj2.hashCode() + obj3.hashCode();
+    }
+
+    public String toString() {
+        return "(" + obj1.toString() + ", " + obj2.toString()+ ", " + obj3.toString() + ")";
+    }
+}

Added: labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/Tuples.java
===================================================================
--- labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/Tuples.java	                        (rev 0)
+++ labs/shotoku/trunk/shotoku-cache/src/java/org/jboss/shotoku/tools/Tuples.java	2007-08-13 16:46:16 UTC (rev 14177)
@@ -0,0 +1,36 @@
+/******************************************************************************
+ * 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.tools;
+
+/**
+ * @author <a href="mailto:adam.warski at jboss.org">Adam Warski</a>
+ */
+public class Tuples {
+    public static<A, B> Pair<A, B> tuple(A a, B b) {
+        return new Pair<A, B>(a, b);
+    }
+
+    public static<A, B, C> Triple<A, B, C> tuple(A a, B b, C c) {
+        return new Triple<A, B, C>(a, b, c);
+    }
+}




More information about the jboss-svn-commits mailing list