KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > web > loadbalancer > monitor > ECVMonitorService


1 /*
2  * JBoss, the OpenSource WebOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.web.loadbalancer.monitor;
8
9 import org.apache.commons.httpclient.HttpMethod;
10 import gnu.regexp.RE;
11 import gnu.regexp.REException;
12
13 /**
14  * A Monitor implementation that does a RegExp-check of the content.
15  *
16  * @author Thomas Peuss <jboss@peuss.de>
17  * @version $Revision: 1.3 $
18  * @jmx:mbean name="jboss.web.loadbalancer: service=ECVMonitor"
19  * extends="org.jboss.web.loadbalancer.monitor.AbstractMonitorMBean"
20  */

21 public class ECVMonitorService
22     extends AbstractMonitor
23     implements ECVMonitorServiceMBean
24 {
25   protected RE regExp;
26
27   protected boolean checkHostStatus(HttpMethod method)
28   {
29     return matchRegExp(method.getResponseBodyAsString());
30   }
31
32   protected boolean matchRegExp(String JavaDoc string)
33   {
34     // try to match regexp
35
if (regExp.getMatch(string) == null)
36     {
37       log.error("RegExp \"" + regExp + "\" does not match server output");
38       return false;
39     }
40     return true;
41   }
42
43   /**
44    * @jmx:managed-attribute
45    */

46   public void setRegExp(String JavaDoc regExp) throws REException
47   {
48     this.regExp = new RE(regExp);
49   }
50
51   /**
52    * @jmx:managed-attribute
53    */

54   public String JavaDoc getRegExp()
55   {
56     return regExp.toString();
57   }
58 }
Popular Tags