bring back re support for Args and Env
This commit is contained in:
		
							parent
							
								
									541fe6b395
								
							
						
					
					
						commit
						bdbcbf6e51
					
				| @ -28,7 +28,7 @@ alias tcfind ptql State.Name.eq=java,Args.*.eq=org.apache.catalina.startup.Boots | ||||
| #($1 is the return value of the first query in the string) | ||||
| #'Pne' => 'P' flags means parent of matched process | ||||
| #to filter out httpd child processes | ||||
| alias apfind ptql State.Name.re=^(https?d.*|[Aa]pache2?)$,State.Name.Pne=$1 | ||||
| alias apfind ptql State.Name.re=https?d.*|[Aa]pache2?$,State.Name.Pne=$1 | ||||
| 
 | ||||
| #find ant processes (ant hangs on me sometimes) | ||||
| #(* matches any value in the array) | ||||
|  | ||||
| @ -16,7 +16,7 @@ public class ProcessQueryHelper { | ||||
|         stringMatchers.put("ne", new StringNeMatcher()); | ||||
|         stringMatchers.put("sw", new StringSwMatcher()); | ||||
|         stringMatchers.put("ew", new StringEwMatcher()); | ||||
|         //stringMatchers.put("re", new StringReMatcher()); | ||||
|         stringMatchers.put("re", new StringReMatcher()); | ||||
|         stringMatchers.put("ct", new StringCtMatcher()); | ||||
|     } | ||||
| 
 | ||||
| @ -104,14 +104,12 @@ public class ProcessQueryHelper { | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     //XXX requires jdk 1.4+ to compile | ||||
|     /* | ||||
|     static class StringReMatcher implements StringMatcher { | ||||
|         public boolean match(String left, String right) { | ||||
|             return left.matches(right); | ||||
|             return StringPattern.matches(left, right); | ||||
|         } | ||||
|     } | ||||
|     */ | ||||
| 
 | ||||
|     public static boolean argsMatch(SigarProxy proxy, long pid, | ||||
|                                     String value, String op) | ||||
|         throws SigarException, SigarNotImplementedException { | ||||
|  | ||||
							
								
								
									
										54
									
								
								bindings/java/src/net/hyperic/sigar/ptql/StringPattern.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										54
									
								
								bindings/java/src/net/hyperic/sigar/ptql/StringPattern.java
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,54 @@ | ||||
| package net.hyperic.sigar.ptql; | ||||
| 
 | ||||
| import java.lang.reflect.Method; | ||||
| import java.util.Map; | ||||
| 
 | ||||
| import net.hyperic.sigar.util.ReferenceMap; | ||||
| 
 | ||||
| public class StringPattern { | ||||
|     static Class patternClass; | ||||
|     static Method compile, matcher, find; | ||||
|     private static Map patterns = null; | ||||
|      | ||||
|     //XXX avoiding 1.4 requirement | ||||
|     private static void init() throws Exception { | ||||
|         patterns = ReferenceMap.synchronizedMap(); | ||||
|         patternClass = Class.forName("java.util.regex.Pattern"); | ||||
|         Class matcherClass = Class.forName("java.util.regex.Matcher"); | ||||
|         Class[] arg = { String.class }; | ||||
|         compile = patternClass.getDeclaredMethod("compile", arg); | ||||
|         arg = new Class[] { Class.forName("java.lang.CharSequence") }; | ||||
|         matcher = patternClass.getDeclaredMethod("matcher", arg); | ||||
|         find = matcherClass.getDeclaredMethod("find", new Class[0]); | ||||
|     } | ||||
| 
 | ||||
|     /** | ||||
|      * Wrapper around Pattern.compile(regex).matcher(source).find() | ||||
|      */ | ||||
|     public static boolean matches(String source, String regex) { | ||||
|         try { | ||||
|             if (patterns == null) { | ||||
|                 init(); | ||||
|             } | ||||
| 
 | ||||
|             Object pattern = patterns.get(regex); | ||||
|             if (pattern == null) { | ||||
|                 //pattern = Pattern.compile(regex) | ||||
|                 pattern = compile.invoke(patternClass, new Object[] { regex }); | ||||
|                 patterns.put(regex, pattern); | ||||
|             } | ||||
|             //m = pattern.matcher(source) | ||||
|             Object m = matcher.invoke(pattern, new Object[] { source }); | ||||
|             //result = m.find() | ||||
|             Boolean result = (Boolean)find.invoke(m, new Object[0]); | ||||
|             return result.booleanValue(); | ||||
|         } catch (Exception e) { | ||||
|             System.err.println("Error matching '" + | ||||
|                                regex + "' against '" + | ||||
|                                source + "'"); | ||||
|             e.printStackTrace(); | ||||
|             return false; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Doug MacEachern
						Doug MacEachern