You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tapestry.apache.org by ms...@apache.org on 2008/01/23 21:36:12 UTC

svn commit: r614655 - in /tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator: Email.java Pattern.java

Author: mschulte
Date: Wed Jan 23 12:36:08 2008
New Revision: 614655

URL: http://svn.apache.org/viewvc?rev=614655&view=rev
Log:
fixes TAPESTRY-2071, don't use a pattern-pool for each validator instance.

Modified:
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Email.java
    tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Pattern.java

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Email.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Email.java?rev=614655&r1=614654&r2=614655&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Email.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Email.java Wed Jan 23 12:36:08 2008
@@ -21,7 +21,6 @@
 import org.apache.tapestry.form.ValidationMessages;
 import org.apache.tapestry.json.JSONLiteral;
 import org.apache.tapestry.json.JSONObject;
-import org.apache.tapestry.util.RegexpMatcher;
 import org.apache.tapestry.valid.ValidationConstants;
 import org.apache.tapestry.valid.ValidationConstraint;
 import org.apache.tapestry.valid.ValidationStrings;
@@ -49,13 +48,9 @@
     public static final String DOMAIN_PATTERN = "([0-9a-z]([-0-9a-z]{0,61}[0-9a-z])?\\.)+" + "(" + TLD_PATTERN + ")";
     public static final String USERNAME_PATTERN = "([-/!\\#$*?=_+&'\\da-z]+[.])*[-/!\\#$*?=_+&'\\da-z]+";
     public static final String PATTERN = "^(?i)"+ USERNAME_PATTERN + "@" + "(" + DOMAIN_PATTERN + ")$";
-                
-    // TODO: Possible thread safety issue if the validator
-    // is shared across threads, because the matcher
-    // will be too.
-    
-    private RegexpMatcher _matcher = new RegexpMatcher();
-    
+
+    private static final java.util.regex.Pattern PATTERN_COMPILED = java.util.regex.Pattern.compile(PATTERN);
+
     public Email()
     {
     }
@@ -70,7 +65,7 @@
     {
         String input = (String) object;
 
-        if (!_matcher.matches(PATTERN, input))
+        if ( !PATTERN_COMPILED.matcher(input).matches() )
             throw new ValidatorException(buildMessage(messages, field),
                     ValidationConstraint.EMAIL_FORMAT);
     }

Modified: tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Pattern.java
URL: http://svn.apache.org/viewvc/tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Pattern.java?rev=614655&r1=614654&r2=614655&view=diff
==============================================================================
--- tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Pattern.java (original)
+++ tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator/Pattern.java Wed Jan 23 12:36:08 2008
@@ -21,11 +21,11 @@
 import org.apache.tapestry.form.ValidationMessages;
 import org.apache.tapestry.json.JSONLiteral;
 import org.apache.tapestry.json.JSONObject;
-import org.apache.tapestry.util.RegexpMatcher;
 import org.apache.tapestry.valid.ValidationConstants;
 import org.apache.tapestry.valid.ValidationConstraint;
 import org.apache.tapestry.valid.ValidationStrings;
 import org.apache.tapestry.valid.ValidatorException;
+import org.apache.oro.text.regex.Perl5Compiler;
 
 /**
  * Validates a user input string against a regular expression pattern.
@@ -38,10 +38,10 @@
 {
     // It is expectd that each Pattern instance will be used by a single component instance,
     // and therefore be restricted to a single thread.
-    
-    private RegexpMatcher _matcher = new RegexpMatcher();
 
     private String _pattern;
+    private String _quotedPattern;
+    private java.util.regex.Pattern _compiledPattern;
 
     public Pattern()
     {
@@ -57,7 +57,7 @@
     {
         String input = (String) object;
 
-        if (!_matcher.matches(_pattern, input))
+        if (! _compiledPattern.matcher(input).matches() )
             throw new ValidatorException(buildMessage(messages, field),
                     ValidationConstraint.PATTERN_MISMATCH);
     }
@@ -74,9 +74,7 @@
     public void renderContribution(IMarkupWriter writer, IRequestCycle cycle,
             FormComponentContributorContext context, IFormComponent field)
     {
-        String pattern = _matcher.getEscapedPatternString(_pattern);
-        
-        JSONObject profile = context.getProfile();
+       JSONObject profile = context.getProfile();
         
         if (!profile.has(ValidationConstants.CONSTRAINTS)) {
             profile.put(ValidationConstants.CONSTRAINTS, new JSONObject());
@@ -85,7 +83,7 @@
         
         accumulateProperty(cons, field.getClientId(), 
                 new JSONLiteral("[tapestry.form.validation.isValidPattern,\""
-                        + pattern + "\"]"));
+                        + _quotedPattern + "\"]"));
         
         accumulateProfileProperty(field, profile, 
                 ValidationConstants.CONSTRAINTS, buildMessage(context, field));
@@ -94,6 +92,8 @@
     public void setPattern(String pattern)
     {
         _pattern = pattern;
+        _compiledPattern = java.util.regex.Pattern.compile(pattern);
+        _quotedPattern =  Perl5Compiler.quotemeta(_pattern);
     }
 
     public String getPattern()



Re: svn commit: r614655 - in /tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator: Email.java Pattern.java

Posted by Marcus Schulte <et...@googlemail.com>.
I've filed an issue for commons-pool:
https://issues.apache.org/jira/browse/POOL-122

2008/1/24, Marcus Schulte <et...@googlemail.com>:
>
> Once, after a few days of running, pages with pattern-based validators
> would cease to work.
>
>
> The reason, from the stacktrace, was, that commons-pool does not
> health-check its one Timer (static instance in base-class), used to schedule
> eviction jobs, before scheduling a new Eviction-task with it. So, if, for
> some reason, the eviction thread dies, each subsequent pool-creation (and
> thus validator-creation) fails with an IllegalStateException. Which happened
> to us.
>
> I know they changed *something* with the eviction-mechanism in the latest
> version. When I have any time I'll check out the latest code and file an
> issue.
>
> 2008/1/23, Jesse Kuhnert <jk...@gmail.com>:
> >
> > Out of curiosity (and fear) - what is the commons-pool issue that you
> > ran in to?   Do you think it will effect the other areas of Tapestry
> > that uses it?  Do they know about it?
> >
> > On Jan 23, 2008 3:36 PM,  < mschulte@apache.org> wrote:
> > > Author: mschulte
> > > Date: Wed Jan 23 12:36:08 2008
> > > New Revision: 614655
> > >
> > > URL: http://svn.apache.org/viewvc?rev=614655&view=rev
> > > Log:
> > > fixes TAPESTRY-2071, don't use a pattern-pool for each validator
> > instance.
> > >
> > <snipped>
> >
> >
> >
> > --
> > Jesse Kuhnert
> > Tapestry / OGNL / Dojo team member/developer
> >
> > Open source based consulting work centered around
> > dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: dev-help@tapestry.apache.org
> >
> >
>
>
> --
> Marcus Schulte
> http://marcus-schulte.blogspot.com
>



-- 
Marcus Schulte
http://marcus-schulte.blogspot.com

Re: svn commit: r614655 - in /tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator: Email.java Pattern.java

Posted by Marcus Schulte <et...@googlemail.com>.
Once, after a few days of running, pages with pattern-based validators would
cease to work.

The reason, from the stacktrace, was, that commons-pool does not
health-check its one Timer (static instance in base-class), used to schedule
eviction jobs, before scheduling a new Eviction-task with it. So, if, for
some reason, the eviction thread dies, each subsequent pool-creation (and
thus validator-creation) fails with an IllegalStateException. Which happened
to us.
I know they changed *something* with the eviction-mechanism in the latest
version. When I have any time I'll check out the latest code and file an
issue.

2008/1/23, Jesse Kuhnert <jk...@gmail.com>:
>
> Out of curiosity (and fear) - what is the commons-pool issue that you
> ran in to?   Do you think it will effect the other areas of Tapestry
> that uses it?  Do they know about it?
>
> On Jan 23, 2008 3:36 PM,  <ms...@apache.org> wrote:
> > Author: mschulte
> > Date: Wed Jan 23 12:36:08 2008
> > New Revision: 614655
> >
> > URL: http://svn.apache.org/viewvc?rev=614655&view=rev
> > Log:
> > fixes TAPESTRY-2071, don't use a pattern-pool for each validator
> instance.
> >
> <snipped>
>
>
>
> --
> Jesse Kuhnert
> Tapestry / OGNL / Dojo team member/developer
>
> Open source based consulting work centered around
> dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: dev-help@tapestry.apache.org
>
>


-- 
Marcus Schulte
http://marcus-schulte.blogspot.com

Re: svn commit: r614655 - in /tapestry/tapestry4/trunk/tapestry-framework/src/java/org/apache/tapestry/form/validator: Email.java Pattern.java

Posted by Jesse Kuhnert <jk...@gmail.com>.
Out of curiosity (and fear) - what is the commons-pool issue that you
ran in to?   Do you think it will effect the other areas of Tapestry
that uses it?  Do they know about it?

On Jan 23, 2008 3:36 PM,  <ms...@apache.org> wrote:
> Author: mschulte
> Date: Wed Jan 23 12:36:08 2008
> New Revision: 614655
>
> URL: http://svn.apache.org/viewvc?rev=614655&view=rev
> Log:
> fixes TAPESTRY-2071, don't use a pattern-pool for each validator instance.
>
<snipped>



-- 
Jesse Kuhnert
Tapestry / OGNL / Dojo team member/developer

Open source based consulting work centered around
dojo/tapestry/tacos/hivemind. http://blog.opencomponentry.com

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org