You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by hl...@apache.org on 2011/09/08 23:20:56 UTC
svn commit: r1166911 - in /tapestry/tapestry5/trunk/tapestry-ioc/src:
main/java/org/apache/tapestry5/ioc/util/AbstractMessages.java
test/java/org/apache/tapestry5/ioc/internal/util/MessagesImplTest.java
Author: hlship
Date: Thu Sep 8 21:20:56 2011
New Revision: 1166911
URL: http://svn.apache.org/viewvc?rev=1166911&view=rev
Log:
TAP5-1638: Remove use of ConcurrentBarrier inside AbstractMessages, replace with ConcurrentHashMap
Modified:
tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/util/AbstractMessages.java
tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/MessagesImplTest.java
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/util/AbstractMessages.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/util/AbstractMessages.java?rev=1166911&r1=1166910&r2=1166911&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/util/AbstractMessages.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/main/java/org/apache/tapestry5/ioc/util/AbstractMessages.java Thu Sep 8 21:20:56 2011
@@ -1,4 +1,4 @@
-// Copyright 2006, 2009 The Apache Software Foundation
+// Copyright 2006, 2009, 2011 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -14,11 +14,9 @@
package org.apache.tapestry5.ioc.util;
-import org.apache.tapestry5.ioc.Invokable;
import org.apache.tapestry5.ioc.MessageFormatter;
import org.apache.tapestry5.ioc.Messages;
-import static org.apache.tapestry5.ioc.internal.util.CollectionFactory.newCaseInsensitiveMap;
-import org.apache.tapestry5.ioc.internal.util.ConcurrentBarrier;
+import org.apache.tapestry5.ioc.internal.util.CollectionFactory;
import org.apache.tapestry5.ioc.internal.util.MessageFormatterImpl;
import java.util.Locale;
@@ -30,12 +28,10 @@ import java.util.Map;
*/
public abstract class AbstractMessages implements Messages
{
- private final ConcurrentBarrier barrier = new ConcurrentBarrier();
-
/**
* String key to MF instance.
*/
- private final Map<String, MessageFormatter> cache = newCaseInsensitiveMap();
+ private final Map<String, MessageFormatter> cache = CollectionFactory.newConcurrentMap();
private final Locale locale;
@@ -66,29 +62,17 @@ public abstract class AbstractMessages i
return String.format("[[missing key: %s]]", key);
}
- public MessageFormatter getFormatter(final String key)
+ public MessageFormatter getFormatter(String key)
{
- MessageFormatter result = barrier.withRead(new Invokable<MessageFormatter>()
- {
- public MessageFormatter invoke()
- {
- return cache.get(key);
- }
- });
-
- if (result != null) return result;
-
- final MessageFormatter newFormatter = buildMessageFormatter(key);
+ MessageFormatter result = cache.get(key);
- barrier.withWrite(new Runnable()
+ if (result == null)
{
- public void run()
- {
- cache.put(key, newFormatter);
- }
- });
+ result = buildMessageFormatter(key);
+ cache.put(key, result);
+ }
- return newFormatter;
+ return result;
}
private MessageFormatter buildMessageFormatter(String key)
Modified: tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/MessagesImplTest.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/MessagesImplTest.java?rev=1166911&r1=1166910&r2=1166911&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/MessagesImplTest.java (original)
+++ tapestry/tapestry5/trunk/tapestry-ioc/src/test/java/org/apache/tapestry5/ioc/internal/util/MessagesImplTest.java Thu Sep 8 21:20:56 2011
@@ -1,4 +1,4 @@
-// Copyright 2006 The Apache Software Foundation
+// Copyright 2006, 2011 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -81,8 +81,7 @@ public class MessagesImplTest extends IO
public void formatters_are_cached()
{
MessageFormatter mf1 = messages.getFormatter("result");
- // Throw in a case-insensitive check:
- MessageFormatter mf2 = messages.getFormatter("Result");
+ MessageFormatter mf2 = messages.getFormatter("result");
assertSame(mf2, mf1);
}