View Javadoc
1   package org.apache.commons.jcs.engine.control.event;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.commons.jcs.engine.control.event.behavior.ElementEventType;
23  import org.apache.commons.jcs.engine.control.event.behavior.IElementEvent;
24  import org.apache.commons.jcs.engine.control.event.behavior.IElementEventHandler;
25  import org.apache.commons.logging.Log;
26  import org.apache.commons.logging.LogFactory;
27  
28  /**
29   * @author aaronsm
30   */
31  public class ElementEventHandlerMockImpl
32      implements IElementEventHandler
33  {
34      /** Times called. */
35      private int callCount = 0;
36  
37      /** The logger */
38      private static final Log log = LogFactory.getLog( ElementEventHandlerMockImpl.class );
39  
40      /** ELEMENT_EVENT_SPOOLED_DISK_AVAILABLE */
41      private int spoolCount = 0;
42  
43      /** ELEMENT_EVENT_SPOOLED_NOT_ALLOWED */
44      private int spoolNotAllowedCount = 0;
45  
46      /** ELEMENT_EVENT_SPOOLED_DISK_NOT_AVAILABLE */
47      private int spoolNoDiskCount = 0;
48  
49      /** ELEMENT_EVENT_EXCEEDED_MAXLIFE_BACKGROUND */
50      private int exceededMaxLifeBackgroundCount = 0;
51  
52      /** ELEMENT_EVENT_EXCEEDED_IDLETIME_BACKGROUND */
53      private int exceededIdleTimeBackgroundCount = 0;
54  
55      /**
56       * @param event
57       */
58      @Override
59      public synchronized <T> void handleElementEvent( IElementEvent<T> event )
60      {
61          setCallCount( getCallCount() + 1 );
62  
63          if ( log.isDebugEnabled() )
64          {
65              log.debug( "HANDLER -- HANDLER -- HANDLER -- ---EVENT CODE = " + event.getElementEvent() );
66              log.debug( "/n/n EVENT CODE = " + event.getElementEvent() + " ***************************" );
67          }
68  
69          if ( event.getElementEvent() == ElementEventType.SPOOLED_DISK_AVAILABLE )
70          {
71              setSpoolCount( getSpoolCount() + 1 );
72          }
73          else if ( event.getElementEvent() == ElementEventType.SPOOLED_NOT_ALLOWED )
74          {
75              setSpoolNotAllowedCount( getSpoolNotAllowedCount() + 1 );
76          }
77          else if ( event.getElementEvent() == ElementEventType.SPOOLED_DISK_NOT_AVAILABLE )
78          {
79              setSpoolNoDiskCount( getSpoolNoDiskCount() + 1 );
80          }
81          else if ( event.getElementEvent() == ElementEventType.EXCEEDED_MAXLIFE_BACKGROUND )
82          {
83              setExceededMaxLifeBackgroundCount( getExceededMaxLifeBackgroundCount() + 1 );
84          }
85          else if ( event.getElementEvent() == ElementEventType.EXCEEDED_IDLETIME_BACKGROUND )
86          {
87              setExceededIdleTimeBackgroundCount( getExceededIdleTimeBackgroundCount() + 1 );
88          }
89      }
90  
91      /**
92       * @param spoolCount The spoolCount to set.
93       */
94      public void setSpoolCount( int spoolCount )
95      {
96          this.spoolCount = spoolCount;
97      }
98  
99      /**
100      * @return Returns the spoolCount.
101      */
102     public int getSpoolCount()
103     {
104         return spoolCount;
105     }
106 
107     /**
108      * @param spoolNotAllowedCount The spoolNotAllowedCount to set.
109      */
110     public void setSpoolNotAllowedCount( int spoolNotAllowedCount )
111     {
112         this.spoolNotAllowedCount = spoolNotAllowedCount;
113     }
114 
115     /**
116      * @return Returns the spoolNotAllowedCount.
117      */
118     public int getSpoolNotAllowedCount()
119     {
120         return spoolNotAllowedCount;
121     }
122 
123     /**
124      * @param spoolNoDiskCount The spoolNoDiskCount to set.
125      */
126     public void setSpoolNoDiskCount( int spoolNoDiskCount )
127     {
128         this.spoolNoDiskCount = spoolNoDiskCount;
129     }
130 
131     /**
132      * @return Returns the spoolNoDiskCount.
133      */
134     public int getSpoolNoDiskCount()
135     {
136         return spoolNoDiskCount;
137     }
138 
139     /**
140      * @param exceededMaxLifeBackground The exceededMaxLifeBackground to set.
141      */
142     public void setExceededMaxLifeBackgroundCount( int exceededMaxLifeBackground )
143     {
144         this.exceededMaxLifeBackgroundCount = exceededMaxLifeBackground;
145     }
146 
147     /**
148      * @return Returns the exceededMaxLifeBackground.
149      */
150     public int getExceededMaxLifeBackgroundCount()
151     {
152         return exceededMaxLifeBackgroundCount;
153     }
154 
155     /**
156      * @param callCount The callCount to set.
157      */
158     public void setCallCount( int callCount )
159     {
160         this.callCount = callCount;
161     }
162 
163     /**
164      * @return Returns the callCount.
165      */
166     public int getCallCount()
167     {
168         return callCount;
169     }
170 
171     /**
172      * @param exceededIdleTimeBackground The exceededIdleTimeBackground to set.
173      */
174     public void setExceededIdleTimeBackgroundCount( int exceededIdleTimeBackground )
175     {
176         this.exceededIdleTimeBackgroundCount = exceededIdleTimeBackground;
177     }
178 
179     /**
180      * @return Returns the exceededIdleTimeBackground.
181      */
182     public int getExceededIdleTimeBackgroundCount()
183     {
184         return exceededIdleTimeBackgroundCount;
185     }
186 }