View Javadoc

1   /*
2    * Jour - java profiler and monitoring library
3    *
4    * Copyright (C) 2004 Jour team
5    *
6    * This library is free software; you can redistribute it and/or
7    * modify it under the terms of the GNU Library General Public
8    * License as published by the Free Software Foundation; either
9    * version 2 of the License, or (at your option) any later version.
10   *
11   * This library is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14   * Library General Public License for more details.
15   *
16   * You should have received a copy of the GNU Library General Public
17   * License along with this library; if not, write to the
18   * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19   * Boston, MA  02111-1307, USA.
20   */
21  package net.sf.jour.rt.view;
22  
23  import net.sf.jour.filter.TimeListFilter;
24  import net.sf.jour.rt.agent.EventTimed;
25  import net.sf.jour.rt.agent.ProfilerEvent;
26  import net.sf.jour.rt.view.config.FilterType;
27  
28  import org.apache.log4j.Logger;
29  
30  /***
31   * TODO Add docs
32   * Created on 04.12.2004
33   *
34   * Contributing Author(s):
35   *
36   *   Misha Lifschitz <mishalifschitz at users.sourceforge.net> (Inital implementation)
37   *   Vlad Skarzhevskyy <vlads at users.sourceforge.net> (Inital implementation)
38   *
39   * @author vlads
40   * @version $Revision: 1.1 $ ($Author: vlads $) $Date: 2004/12/15 20:50:32 $
41   */
42  
43  public class ViewFilterItem extends ClassMatchFilter {
44  	
45  	private boolean enabled;
46  	
47  	private String description;
48  	
49  	private TimeListFilter time;
50  	
51  	private long timeFrame;
52  	
53  	public ViewFilterItem() {
54  		time = new TimeListFilter();
55  	}
56  	
57      public void readConfig(FilterType definition) {
58          enabled = definition.isEnabled();
59          this.description = definition.getDescr();
60          if (definition.getAccumulation() != null) {
61              this.timeFrame = definition.getAccumulation().getTimeFrame();
62          }
63          super.readConfig(definition.getClasses());
64          
65  		time.readConfig(definition.getTime());
66      }
67      
68  	public int matchState(Object obj) {
69  		if (!isEnabled()) {
70  			return MATCH_NO;
71  		}
72  		if (obj instanceof ProfilerEvent) {
73  			ProfilerEvent event = (ProfilerEvent)obj;
74  			if (this.time.match(event.getTimestamp())) {
75  				if (super.isEmpty()) {
76  					return MATCH_YES;
77  				} else {
78  					return super.matchState(event);
79  				}
80  			} else {
81  				return MATCH_NO;
82  			}
83  		} else if (obj instanceof EventTimed) {	
84  		    EventTimed event = (EventTimed)obj;
85  			return b2Match(this.time.match(event.getTimestamp()));
86  		} else {
87  			return super.matchState(obj);
88  		}
89  	}
90  
91  	public void debug() {
92  		super.debug();
93  		this.time.debug();
94  	}
95      /***
96       * @return
97       */
98      public boolean isEnabled() {
99          return this.enabled;
100     }
101 
102     /***
103      * @param enabled
104      */
105     public void setEnabled(boolean enabled) {
106         this.enabled = enabled;
107     }
108 
109     /***
110      * @return Description
111      */
112     public String getDescription() {
113         return this. description;
114     }
115     
116     /***
117      * @return Returns the timeFrame.
118      */
119     public long getTimeFrame() {
120         return timeFrame;
121     }
122 }