jsalvata 2004/02/09 10:25:07 Modified: src/functions/org/apache/jmeter/functions RegexFunction.java Log: * Making thread-safe by using READ_ONLY_MASK when compiling regexps. * Using a pattern cache for better performance. Revision Changes Path 1.19 +7 -27 jakarta-jmeter/src/functions/org/apache/jmeter/functions/RegexFunction.java Index: RegexFunction.java =================================================================== RCS file: /home/cvs/jakarta-jmeter/src/functions/org/apache/jmeter/functions/RegexFunction.java,v retrieving revision 1.18 retrieving revision 1.19 diff -u -r1.18 -r1.19 --- RegexFunction.java 23 Jan 2004 00:10:05 -0000 1.18 +++ RegexFunction.java 9 Feb 2004 18:25:07 -0000 1.19 @@ -15,10 +15,9 @@ import org.apache.jmeter.util.JMeterUtils; import org.apache.jorphan.logging.LoggingManager; import org.apache.log.Logger; -import org.apache.oro.text.regex.MalformedPatternException; +import org.apache.oro.text.PatternCacheLRU; import org.apache.oro.text.regex.MatchResult; import org.apache.oro.text.regex.Pattern; -import org.apache.oro.text.regex.PatternCompiler; import org.apache.oro.text.regex.PatternMatcher; import org.apache.oro.text.regex.PatternMatcherInput; import org.apache.oro.text.regex.Perl5Compiler; @@ -41,7 +40,8 @@ Pattern searchPattern; Object[] template; String valueIndex, defaultValue, between; - transient PatternCompiler compiler = new Perl5Compiler(); + private static PatternCacheLRU patternCache = + new PatternCacheLRU(1000, new Perl5Compiler()); Pattern templatePattern; private String name; @@ -65,14 +65,7 @@ public RegexFunction() { valueIndex = between = name = ""; - try - { - templatePattern = compiler.compile("\\$(\\d+)\\$", Perl5Compiler.READ_ONLY_MASK); - } - catch (MalformedPatternException e) - { - log.error("", e); - } + templatePattern = patternCache.getPattern("\\$(\\d+)\\$", Perl5Compiler.READ_ONLY_MASK); } public String execute(SampleResult previousResult, Sampler currentSampler) @@ -81,7 +74,7 @@ try { searchPattern = - compiler.compile(((CompoundVariable) values[0]).execute()); + patternCache.getPattern(((CompoundVariable) values[0]).execute(), Perl5Compiler.READ_ONLY_MASK); generateTemplate(((CompoundVariable) values[1]).execute()); if (values.length > 2) @@ -112,11 +105,6 @@ name = ((CompoundVariable) values[values.length - 1]).execute(); } } - catch (MalformedPatternException e) - { - log.error("", e); - throw new InvalidVariableException("Bad regex pattern"); - } catch (Exception e) { throw new InvalidVariableException(e.getMessage()); @@ -298,16 +286,8 @@ private boolean isFirstElementGroup(String rawData) { - try - { - Pattern pattern = compiler.compile("^\\$\\d+\\$"); - return new Perl5Matcher().contains(rawData, pattern); - } - catch (MalformedPatternException e) - { - log.error("", e); - return false; - } + Pattern pattern = patternCache.getPattern("^\\$\\d+\\$", Perl5Compiler.READ_ONLY_MASK); + return new Perl5Matcher().contains(rawData, pattern); } /*
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]