View Javadoc
1   package org.apache.commons.jcs3.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.jcs3.engine.control.event.behavior.ElementEventType;
23  import org.apache.commons.jcs3.engine.control.event.behavior.IElementEvent;
24  import org.apache.commons.jcs3.engine.control.event.behavior.IElementEventHandler;
25  import org.apache.commons.jcs3.log.Log;
26  import org.apache.commons.jcs3.log.LogManager;
27  
28  /**
29   */
30  public class ElementEventHandlerMockImpl
31      implements IElementEventHandler
32  {
33      /** Times called. */
34      private int callCount;
35  
36      /** The logger */
37      private static final Log log = LogManager.getLog( ElementEventHandlerMockImpl.class );
38  
39      /** ELEMENT_EVENT_SPOOLED_DISK_AVAILABLE */
40      private int spoolCount;
41  
42      /** ELEMENT_EVENT_SPOOLED_NOT_ALLOWED */
43      private int spoolNotAllowedCount;
44  
45      /** ELEMENT_EVENT_SPOOLED_DISK_NOT_AVAILABLE */
46      private int spoolNoDiskCount;
47  
48      /** ELEMENT_EVENT_EXCEEDED_MAXLIFE_BACKGROUND */
49      private int exceededMaxLifeBackgroundCount;
50  
51      /** ELEMENT_EVENT_EXCEEDED_IDLETIME_BACKGROUND */
52      private int exceededIdleTimeBackgroundCount;
53  
54      /**
55       * @param event
56       */
57      @Override
58      public synchronized <T> void handleElementEvent( final IElementEvent<T> event )
59      {
60          setCallCount( getCallCount() + 1 );
61  
62          if ( log.isDebugEnabled() )
63          {
64              log.debug( "HANDLER -- HANDLER -- HANDLER -- ---EVENT CODE = " + event.getElementEvent() );
65              log.debug( "/n/n EVENT CODE = " + event.getElementEvent() + " ***************************" );
66          }
67  
68          if ( event.getElementEvent() == ElementEventType.SPOOLED_DISK_AVAILABLE )
69          {
70              setSpoolCount( getSpoolCount() + 1 );
71          }
72          else if ( event.getElementEvent() == ElementEventType.SPOOLED_NOT_ALLOWED )
73          {
74              setSpoolNotAllowedCount( getSpoolNotAllowedCount() + 1 );
75          }
76          else if ( event.getElementEvent() == ElementEventType.SPOOLED_DISK_NOT_AVAILABLE )
77          {
78              setSpoolNoDiskCount( getSpoolNoDiskCount() + 1 );
79          }
80          else if ( event.getElementEvent() == ElementEventType.EXCEEDED_MAXLIFE_BACKGROUND )
81          {
82              setExceededMaxLifeBackgroundCount( getExceededMaxLifeBackgroundCount() + 1 );
83          }
84          else if ( event.getElementEvent() == ElementEventType.EXCEEDED_IDLETIME_BACKGROUND )
85          {
86              setExceededIdleTimeBackgroundCount( getExceededIdleTimeBackgroundCount() + 1 );
87          }
88      }
89  
90      /**
91       * @param spoolCount The spoolCount to set.
92       */
93      public void setSpoolCount( final int spoolCount )
94      {
95          this.spoolCount = spoolCount;
96      }
97  
98      /**
99       * @return Returns the spoolCount.
100      */
101     public int getSpoolCount()
102     {
103         return spoolCount;
104     }
105 
106     /**
107      * @param spoolNotAllowedCount The spoolNotAllowedCount to set.
108      */
109     public void setSpoolNotAllowedCount( final int spoolNotAllowedCount )
110     {
111         this.spoolNotAllowedCount = spoolNotAllowedCount;
112     }
113 
114     /**
115      * @return Returns the spoolNotAllowedCount.
116      */
117     public int getSpoolNotAllowedCount()
118     {
119         return spoolNotAllowedCount;
120     }
121 
122     /**
123      * @param spoolNoDiskCount The spoolNoDiskCount to set.
124      */
125     public void setSpoolNoDiskCount( final int spoolNoDiskCount )
126     {
127         this.spoolNoDiskCount = spoolNoDiskCount;
128     }
129 
130     /**
131      * @return Returns the spoolNoDiskCount.
132      */
133     public int getSpoolNoDiskCount()
134     {
135         return spoolNoDiskCount;
136     }
137 
138     /**
139      * @param exceededMaxLifeBackground The exceededMaxLifeBackground to set.
140      */
141     public void setExceededMaxLifeBackgroundCount( final int exceededMaxLifeBackground )
142     {
143         this.exceededMaxLifeBackgroundCount = exceededMaxLifeBackground;
144     }
145 
146     /**
147      * @return Returns the exceededMaxLifeBackground.
148      */
149     public int getExceededMaxLifeBackgroundCount()
150     {
151         return exceededMaxLifeBackgroundCount;
152     }
153 
154     /**
155      * @param callCount The callCount to set.
156      */
157     public void setCallCount( final int callCount )
158     {
159         this.callCount = callCount;
160     }
161 
162     /**
163      * @return Returns the callCount.
164      */
165     public int getCallCount()
166     {
167         return callCount;
168     }
169 
170     /**
171      * @param exceededIdleTimeBackground The exceededIdleTimeBackground to set.
172      */
173     public void setExceededIdleTimeBackgroundCount( final int exceededIdleTimeBackground )
174     {
175         this.exceededIdleTimeBackgroundCount = exceededIdleTimeBackground;
176     }
177 
178     /**
179      * @return Returns the exceededIdleTimeBackground.
180      */
181     public int getExceededIdleTimeBackgroundCount()
182     {
183         return exceededIdleTimeBackgroundCount;
184     }
185 }