From do-not-reply at jboss.org Wed Apr 7 02:54:07 2010 Content-Type: multipart/mixed; boundary="===============7435367418380526409==" MIME-Version: 1.0 From: do-not-reply at jboss.org To: gatein-commits at lists.jboss.org Subject: [gatein-commits] gatein SVN: r2514 - in portal/trunk/component: common/src/test/java/org/exoplatform/commons/cache/future and 1 other directories. Date: Wed, 07 Apr 2010 02:54:07 -0400 Message-ID: <201004070654.o376s70R029899@svn01.web.mwc.hst.phx2.redhat.com> --===============7435367418380526409== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Author: julien_viet Date: 2010-04-07 02:54:06 -0400 (Wed, 07 Apr 2010) New Revision: 2514 Removed: portal/trunk/component/common/src/main/java/org/exoplatform/commons/cach= e/future/Entry.java Modified: portal/trunk/component/common/src/main/java/org/exoplatform/commons/cach= e/future/FutureCache.java portal/trunk/component/common/src/main/java/org/exoplatform/commons/cach= e/future/FutureExoCache.java portal/trunk/component/common/src/main/java/org/exoplatform/commons/cach= e/future/Loader.java portal/trunk/component/common/src/test/java/org/exoplatform/commons/cach= e/future/ConcurrentGetWhenPutTestCase.java portal/trunk/component/common/src/test/java/org/exoplatform/commons/cach= e/future/FutureMap.java portal/trunk/component/common/src/test/java/org/exoplatform/commons/cach= e/future/GetTestCase.java portal/trunk/component/scripting/src/main/java/org/exoplatform/groovyscr= ipt/text/TemplateService.java Log: GTNPORTAL-945 : simplification + javadoc Deleted: portal/trunk/component/common/src/main/java/org/exoplatform/common= s/cache/future/Entry.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- portal/trunk/component/common/src/main/java/org/exoplatform/commons/cac= he/future/Entry.java 2010-04-07 04:20:55 UTC (rev 2513) +++ portal/trunk/component/common/src/main/java/org/exoplatform/commons/cac= he/future/Entry.java 2010-04-07 06:54:06 UTC (rev 2514) @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2009 eXo Platform SAS. - * - * 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.exoplatform.commons.cache.future; - -import java.io.Serializable; - -/** - * @author Julien Viet - * @version $Revision$ - */ -public class Entry implements Serializable -{ - - public static Entry create(V v) - { - return new Entry(v); - } - - /** . */ - private final V value; - - private Entry(V value) - { - if (value =3D=3D null) - { - throw new NullPointerException(); - } - this.value =3D value; - } - - public V getValue() - { - return value; - } - - @Override - public String toString() - { - return "Entry[" + value + "]"; - } -} Modified: portal/trunk/component/common/src/main/java/org/exoplatform/commo= ns/cache/future/FutureCache.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- portal/trunk/component/common/src/main/java/org/exoplatform/commons/cac= he/future/FutureCache.java 2010-04-07 04:20:55 UTC (rev 2513) +++ portal/trunk/component/common/src/main/java/org/exoplatform/commons/cac= he/future/FutureCache.java 2010-04-07 06:54:06 UTC (rev 2514) @@ -30,6 +30,9 @@ * * @author Julien Viet * @version $Revision$ + * @param the key type parameter + * @param the value type parameter + * @param the context type parameter */ public abstract class FutureCache { @@ -38,7 +41,7 @@ private final Loader loader; = /** . */ - private final ConcurrentMap>> local; + private final ConcurrentMap> futureEntries; = /** . */ private final Logger log =3D LoggerFactory.getLogger(FutureCache.class); @@ -46,26 +49,35 @@ public FutureCache(Loader loader) { this.loader =3D loader; - this.local =3D new ConcurrentHashMap>>(); + this.futureEntries =3D new ConcurrentHashMap>(); } = - protected abstract Entry get(K key); + protected abstract V get(K key); = - protected abstract void put(K key, Entry entry); + protected abstract void put(K key, V value); = - public V get(final C context, final K key) + /** + * Perform a cache lookup for the specified key within the specified co= ntext. + * When the value cannot be loaded (because it does not exist or it fai= led or anything else that + * does not come to my mind), the value null is returned. + * + * @param context the context in which the resource is accessed + * @param key the key identifying the resource + * @return the value + */ + public final V get(final C context, final K key) { // First we try a simple cache get - Entry entry =3D get(key); + V value =3D get(key); = // If it does not succeed then we go through a process that will avo= id to load // the same resource concurrently - if (entry =3D=3D null) + if (value =3D=3D null) { // Create our future - FutureTask> future =3D new FutureTask>(new Call= able>() + FutureTask future =3D new FutureTask(new Callable() { - public Entry call() throws Exception + public V call() throws Exception { // Retrieve the value from the loader V value =3D loader.retrieve(context, key); @@ -73,14 +85,11 @@ // if (value !=3D null) { - // Create the entry - Entry entry =3D Entry.create(value); - // Cache it, it is made available to other threads (unle= ss someone removes it) - put(key, entry); + put(key, value); = - // Return entry - return entry; + // Return value + return value; } else { @@ -89,15 +98,15 @@ } }); = - // Was our means that we inserted in the local + // This boolean means we inserted in the local boolean inserted =3D true; = // try { - FutureTask> phantom =3D local.putIfAbsent(key, future= ); + FutureTask phantom =3D futureEntries.putIfAbsent(key, futur= e); = - // Use the entry that could have been inserted by another thre= ad + // Use the value that could have been inserted by another thre= ad if (phantom !=3D null) { future =3D phantom; @@ -108,8 +117,8 @@ future.run(); } = - // Returns the entry - entry =3D future.get(); + // Returns the value + value =3D future.get(); } catch (ExecutionException e) { @@ -124,12 +133,12 @@ // Clean up the per key map but only if our insertion succeede= d and with our future if (inserted) { - local.remove(key, future); + futureEntries.remove(key, future); } } } = // - return entry !=3D null ? entry.getValue() : null; + return value; } } Modified: portal/trunk/component/common/src/main/java/org/exoplatform/commo= ns/cache/future/FutureExoCache.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- portal/trunk/component/common/src/main/java/org/exoplatform/commons/cac= he/future/FutureExoCache.java 2010-04-07 04:20:55 UTC (rev 2513) +++ portal/trunk/component/common/src/main/java/org/exoplatform/commons/cac= he/future/FutureExoCache.java 2010-04-07 06:54:06 UTC (rev 2514) @@ -31,9 +31,9 @@ { = /** . */ - private final ExoCache> cache; + private final ExoCache cache; = - public FutureExoCache(Loader loader, ExoCache> cac= he) + public FutureExoCache(Loader loader, ExoCache cache) { super(loader); = @@ -42,13 +42,13 @@ } = @Override - protected Entry get(K key) + protected V get(K key) { return cache.get(key); } = @Override - protected void put(K key, Entry entry) + protected void put(K key, V entry) { cache.put(key, entry); } Modified: portal/trunk/component/common/src/main/java/org/exoplatform/commo= ns/cache/future/Loader.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- portal/trunk/component/common/src/main/java/org/exoplatform/commons/cac= he/future/Loader.java 2010-04-07 04:20:55 UTC (rev 2513) +++ portal/trunk/component/common/src/main/java/org/exoplatform/commons/cac= he/future/Loader.java 2010-04-07 06:54:06 UTC (rev 2514) @@ -19,15 +19,27 @@ = package org.exoplatform.commons.cache.future; = -import java.io.Serializable; - /** + * The loader interface is used by the future cache to retrieves the value= from the key when it does not exist. + * * @author Julien Viet * @version $Revision$ + * @param the key type parameter + * @param the value type parameter + * @param the context type parameter */ public interface Loader { = + /** + * Retrieves the value from the key within the specified context. If th= e resource is not found then the value + * null must be returned. + * + * @param context the context + * @param key the key + * @return the value + * @throws Exception any exception that would prevent the value to be l= oaded + */ V retrieve(C context, K key) throws Exception; = } Modified: portal/trunk/component/common/src/test/java/org/exoplatform/commo= ns/cache/future/ConcurrentGetWhenPutTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- portal/trunk/component/common/src/test/java/org/exoplatform/commons/cac= he/future/ConcurrentGetWhenPutTestCase.java 2010-04-07 04:20:55 UTC (rev 25= 13) +++ portal/trunk/component/common/src/test/java/org/exoplatform/commons/cac= he/future/ConcurrentGetWhenPutTestCase.java 2010-04-07 06:54:06 UTC (rev 25= 14) @@ -21,8 +21,6 @@ = import junit.framework.AssertionFailedError; import junit.framework.TestCase; -import org.exoplatform.commons.cache.future.Entry; -import org.exoplatform.commons.cache.future.FutureCache; import org.gatein.common.util.Tools; = import java.util.*; @@ -45,7 +43,7 @@ = = @Override - protected Entry get(String key) + protected String get(String key) { if (key =3D=3D key1) { @@ -71,13 +69,13 @@ } = @Override - protected void put(String key, Entry entry) + protected void put(String key, String value) { if (key =3D=3D key1) { if (Thread.currentThread() =3D=3D thread1) { - events.add("begin_put/key1/" + entry); + events.add("begin_put/key1/" + value); = // thread2.start(); @@ -161,7 +159,7 @@ List expectedEvents =3D Arrays.asList( "get/key1", "call/key1", - "begin_put/key1/Entry[foo_value_1]", + "begin_put/key1/foo_value_1", "get/key2", "end_put/key1" ); Modified: portal/trunk/component/common/src/test/java/org/exoplatform/commo= ns/cache/future/FutureMap.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- portal/trunk/component/common/src/test/java/org/exoplatform/commons/cac= he/future/FutureMap.java 2010-04-07 04:20:55 UTC (rev 2513) +++ portal/trunk/component/common/src/test/java/org/exoplatform/commons/cac= he/future/FutureMap.java 2010-04-07 06:54:06 UTC (rev 2514) @@ -19,10 +19,6 @@ = package org.exoplatform.commons.cache.future; = -import org.exoplatform.commons.cache.future.Entry; -import org.exoplatform.commons.cache.future.FutureCache; -import org.exoplatform.commons.cache.future.Loader; - import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -35,25 +31,25 @@ { = /** . */ - final Map> data; + final Map data; = public FutureMap(Loader loader) { super(loader); = // - this.data =3D Collections.synchronizedMap(new HashMap>()); + this.data =3D Collections.synchronizedMap(new HashMap()); } = @Override - protected Entry get(String key) + protected String get(String key) { return data.get(key); } = @Override - protected void put(String key, Entry entry) + protected void put(String key, String value) { - data.put(key, entry); + data.put(key, value); } } Modified: portal/trunk/component/common/src/test/java/org/exoplatform/commo= ns/cache/future/GetTestCase.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- portal/trunk/component/common/src/test/java/org/exoplatform/commons/cac= he/future/GetTestCase.java 2010-04-07 04:20:55 UTC (rev 2513) +++ portal/trunk/component/common/src/test/java/org/exoplatform/commons/cac= he/future/GetTestCase.java 2010-04-07 06:54:06 UTC (rev 2514) @@ -40,7 +40,7 @@ return "foo_value"; } }, "foo")); - Assert.assertEquals("foo_value", futureCache.data.get("foo").getValu= e()); + Assert.assertEquals("foo_value", futureCache.data.get("foo")); } = public void testNullValue() Modified: portal/trunk/component/scripting/src/main/java/org/exoplatform/gr= oovyscript/text/TemplateService.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- portal/trunk/component/scripting/src/main/java/org/exoplatform/groovysc= ript/text/TemplateService.java 2010-04-07 04:20:55 UTC (rev 2513) +++ portal/trunk/component/scripting/src/main/java/org/exoplatform/groovysc= ript/text/TemplateService.java 2010-04-07 06:54:06 UTC (rev 2514) @@ -22,7 +22,6 @@ import groovy.lang.Writable; import groovy.text.Template; = -import org.exoplatform.commons.cache.future.Entry; import org.exoplatform.commons.cache.future.FutureCache; import org.exoplatform.commons.cache.future.FutureExoCache; import org.exoplatform.commons.cache.future.Loader; @@ -59,7 +58,7 @@ = private GroovyTemplateEngine engine_; = - private ExoCache> templatesCache_; + private ExoCache templatesCache_; = private TemplateStatisticService statisticService; = @@ -169,7 +168,7 @@ getTemplatesCache().remove(resourceId); } = - public ExoCache> getTemplatesCache() + public ExoCache getTemplatesCache() { return templatesCache_; } @@ -219,13 +218,9 @@ try { ArrayList list =3D new ArrayList(); - for (Entry entry : templatesCache_.getCachedObjec= ts()) + for (GroovyTemplate template : templatesCache_.getCachedObjects()) { - GroovyTemplate template =3D entry.getValue(); - if (template !=3D null) - { - list.add(template.getId()); - } + list.add(template.getId()); } return list.toArray(new String[list.size()]); } --===============7435367418380526409==--